Tham chiếu họ hàm plot
Tham chiếu cho plot, plotbar, plotchar, plotarrow, plotshape, barcolor, bgcolor, fill, linefill, và ctx.atk.fill_between trong ATK PyneScript V6.
Tổng quan họ plot#
| Hàm | Ý nghĩa argument đầu tiên | Sử dụng khi |
|---|---|---|
plot(source, ...) | Tên cột dataframe được tạo sau trong frame builder. | Bạn cần một đường hoặc hình ảnh series căn theo hàng. |
plotbar(open, high, low, close, ...) | Bốn cột dataframe đã tồn tại trong frame đã chuẩn bị. | Bạn muốn thanh OHLC mà không cần xuống cấp thấp định tuyến candle. |
plotchar(series, ...) | Một series boolean hoặc thưa quyết định nơi ký tự xuất hiện. | Bạn muốn đánh dấu văn bản nhẹ như B, S, hoặc dấu chấm. |
plotarrow(series, ...) | Một series số có dấu biểu thị cường độ. | Bạn muốn hướng mũi tên lên/xuống được mã hóa trong chính giá trị series. |
barcolor(series, ...) | Một cột color theo từng hàng. | Bạn muốn tô màu thanh theo tín hiệu hoặc trạng thái regime. |
bgcolor(series, ...) | Một series boolean hoặc thưa kích hoạt. | Bạn muốn dải nền session, state, hoặc regime. |
fill(ref1, ref2, ...) | Hai tham chiếu plot hoặc hline. | Bạn muốn khoảng trống giữa hai hình ảnh khai báo tĩnh hiện có. |
linefill.new(line1, line2, ...) | Hai định danh line, thường là plot key. | Bạn muốn quan hệ fill bền vững giữa hai hình ảnh line có tên. |
plotshape(series, ...) | Một series boolean hoặc thưa đánh dấu. | Bạn cần điểm đánh dấu phía trên, phía dưới, hoặc tại bar. |
ctx.atk.fill_between(...) | Hai key đường bridge ATK. | Bạn đang sử dụng ctx.atk.plot_line thay vì khai báo tĩnh. |
Quy tắc nhanh nhất: source thường có nghĩa là cột dataframe, key có nghĩa là định danh runtime, và title có nghĩa là nhãn hiển thị cho người dùng. Đây là ba thứ khác nhau — không nhầm lẫn chúng.
Bách khoa parameter plot()#
| Parameter | Cách chọn |
|---|---|
source | Dùng chính xác tên cột output mà frame builder sẽ ghi. Nếu builder ghi frame["ub"], thì plot("ub", ...) là source đúng. |
key | Dùng một định danh hình ảnh ổn định như bb_upper. Đây là tên mà các hình ảnh khác có thể tham chiếu sau, bao gồm fill. |
title | Dùng nhãn chú giải dễ đọc. Giữ nó đủ ngắn cho chú giải chart và bảng cài đặt. |
color | Dùng cho kiểu dáng mặc định. Không mã hóa logic ở đây mà nên nằm trong series hoặc cài đặt người dùng riêng. |
width | Dùng độ rộng đường để thể hiện tầm quan trọng trực quan. Đường basis có thể dày hơn các đường biên band xung quanh. |
Giải mã plot() từng dòng#
plot(
"ub", # source: dataframe column name written later by the frame builder
key="bb_upper", # key: stable runtime identity other visuals can reference
title="Upper Band", # title: user-facing legend or settings label
color="#00aa00", # color: default style, not the series logic itself
width=1, # width: visual importance and readability
)Sai vs Đúng: source vs key#
# Wrong: using bb_upper as source when the frame writes "ub"
# plot("bb_upper", key="bb_upper", ...)
# Right: source matches the dataframe column; key is the visual identity
plot("ub", key="bb_upper", title="Upper Band", color="#00aa00", width=1)Mẫu BBands: plot và linefill cùng nhau#
plot("lb", key="bb_lower", title="Lower", color="#ff0000", width=1)
plot("cb", key="bb_basis", title="Basis", color="#ffa500", width=1)
plot("ub", key="bb_upper", title="Upper", color="#00aa00", width=1)
# linefill.new links visual identities (plot keys), not dataframe column names.
linefill.new("bb_lower", "bb_upper", key="bb_band_fill", color="rgba(63,57,100,0.44)")
def build_indicator_frame(df, params=None):
frame = df.copy().reset_index(drop=True)
upper, basis, lower = ta.bbands(frame["close"], length=20, std=2.0, mamode="sma")
frame["lb"] = lower.reset_index(drop=True)
frame["cb"] = basis.reset_index(drop=True)
frame["ub"] = upper.reset_index(drop=True)
return frameSo sánh plotshape(), linefill.new(), và fill_between()#
plotshape — Sai vs Đúng#
# Wrong: trying to invent the trigger inside the declaration mindset.
# plotshape("close > ema", ...)
# Right: prepare the trigger column first.
frame["buy_marker"] = (frame["close"] > frame["ema_fast"]).fillna(False)
plotshape(
"buy_marker",
key="buy_marker",
location="belowbar",
style="arrow_up",
color="#00c853",
text="BUY",
)linefill.new — Sai vs Đúng#
# Wrong: passing dataframe columns instead of visual identities.
# linefill.new("ub", "lb", key="bb_fill", color="rgba(63,57,100,0.44)")
# Right: pass the plot keys created by the declarations.
plot("lb", key="bb_lower", title="Lower", color="#ff0000", width=1)
plot("ub", key="bb_upper", title="Upper", color="#00aa00", width=1)
linefill.new("bb_lower", "bb_upper", key="bb_fill", color="rgba(63,57,100,0.44)")ctx.atk.fill_between — Sai vs Đúng#
# Wrong: mixing static line identities with bridge line identities.
# ctx.atk.fill_between(line1="bb_upper", line2="bb_lower", ...)
# Right: fill between lines created through ctx.atk.plot_line.
ctx.atk.plot_line(key="atk_fast_line", source="fast", color="#00c853")
ctx.atk.plot_line(key="atk_slow_line", source="slow", color="#f23645")
ctx.atk.fill_between(
key="atk_fast_slow_fill",
line1="atk_fast_line",
line2="atk_slow_line",
color="rgba(41,98,255,0.12)",
fill_alpha=31,
)Gói di chuyển họ Plot#
plotbar("open", "high", "low", "close", key="ohlc_surface", color="#2962ff")
plotchar("breakout_signal", key="breakout_chars", char="B", location="abovebar", color="#00c853")
plotarrow("trend_strength", key="trend_arrows", colorup="#00c853", colordown="#f23645")
barcolor("bar_tint", key="bar_tint")
bgcolor("session_bg_signal", key="session_bg", color="rgba(41,98,255,0.10)")Cây quyết định API trực quan#
Cần vẽ gì đó?
|
+-- Mỗi bar có tự nhiên ánh xạ đến một giá trị series hoặc đánh dấu không?
| |
| +-- Có
| | +-- Cần đường hoặc series? -> dùng plot(...)
| | +-- Cần ngưỡng cố định? -> dùng hline(...)
| | +-- Cần đánh dấu? -> dùng plotshape(...), plotchar(...), hoặc plotarrow(...)
| | +-- Cần fill giữa đường tĩnh? -> dùng fill(...) hoặc linefill.new(...)
| |
| +-- Không
| +-- Đối tượng chart rõ ràng (line/label/box)? -> dùng ctx.line / ctx.label / ctx.box
| +-- Hỗn hợp gốc ATK (table/zone/profile)? -> dùng ctx.atk.*
|
+-- Đã dùng ctx.atk.plot_line cho các đường?
+-- Có -> dùng ctx.atk.fill_between(...)
+-- Không -> giữ khai báo tĩnh và dùng fill(...) hoặc linefill.new(...)Nếu điều đầu tiên bạn nghĩ là "Tôi chỉ cần thêm một cột dataframe", hãy ở lại họ khai báo tĩnh. Nếu điều đầu tiên bạn nghĩ là "Tôi cần một đối tượng" hoặc "Tôi cần một payload nhóm", hãy chuyển sang ctx.* hoặc ctx.atk.*.
Xem thêm: