Chuyển đến nội dung chính
ATK Pine Script®

Profile và Candle Bridge

Visual tổng hợp ATK bridge — gói candlestick, profile horizontal_bar, và overlay dual_horizontal_bar_fixed trong một giai đoạn render-only duy nhất.

Profile và Candle Bridge: Visual Tổng Hợp Theo Cách An Toàn#

Một trong những ví dụ mới hơn trong source tree kết hợp ba renderer ATK bridge khác nhau trong một giai đoạn render-only duy nhất: gói candle gọn, profile ngang, và overlay profile kép. Đây là mẫu cần nghiên cứu khi một ý tưởng visual tự nhiên phân giải thành payload nhóm thay vì một plot hoặc một đối tượng đơn lẻ.

def build_visuals(frame, params=None, ctx=None):
    payload = dict(frame.attrs.get("visual_profile_payload") or {})
    tail = frame.tail(int(payload.get("tail_size") or 4)).reset_index(drop=True)
    if tail.empty:
        return []

    last_index = float(tail.iloc[-1]["index"])
    y_levels = [float(value) for value in tail["close"].tolist()]
    return [
        ctx.atk.candlestick(
            key="atk_sub_candles",
            x=[float(value) for value in tail["index"].tolist()],
            open=[float(value) for value in tail["open"].tolist()],
            high=[float(value) for value in tail["high"].tolist()],
            low=[float(value) for value in tail["low"].tolist()],
            close=[float(value) for value in tail["close"].tolist()],
        ),
        ctx.atk.horizontal_bar(
            key="atk_horizontal_profile",
            x=last_index + 4.0,
            y=y_levels,
            **dict(payload.get("horizontal_bar") or {}),
        ),
        ctx.atk.dual_horizontal_bar_fixed(
            key="atk_dual_profile",
            xData=last_index + 8.0,
            yData=y_levels,
            **dict(payload.get("dual_horizontal_bar_fixed") or {}),
        ),
    ]

Các mẫu chính trong ví dụ này#

  • frame.attrs mang cấu hình payload tĩnh (kích thước tail, tùy chọn profile) được đặt trong build_indicator_frame.

  • Tọa độ (last_index, y_levels) được lấy từ slice frame trực tiếp, không phải từ attrs.

  • Function trả về một list — nhiều bridge intent là hợp lệ từ một lần gọi build_visuals.

  • Cả ba renderer chia sẻ một lượt render duy nhất không có tính toán TA.

  • Tải ví dụ profile và candle bridge

  • Tải demo lifecycle

  • Mở bridge cookbook