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

Các Anti-Pattern

Ví dụ sai và đúng khi viết strategy — lạm dụng build_trade_frame, lỗi vị trí MTF, và các lộ trình khởi đầu tốt nhất.

Sai và Đúng khi viết Strategy#

Lạm dụng build_trade_frame#

# Wrong: build_trade_frame becomes a second compute stage.
def build_trade_frame(signal_df, params=None, styles=None):
    frame = signal_df.copy()
    frame["sl"] = frame["close"] - ta.atr(frame["high"], frame["low"], frame["close"], 14)
    return build_mapped_trade_frame(frame)


# Right: compute all strategy intent first, then map only.
def build_signal_frame(df, params=None):
    frame = df.copy().reset_index(drop=True)
    atr = ta.atr(frame["high"], frame["low"], frame["close"], 14)
    frame["sl"] = frame["close"] - atr
    return frame


def build_trade_frame(signal_df, params=None, styles=None):
    return build_mapped_trade_frame(signal_df)

Vị trí đặt bộ lọc MTF#

# Wrong: HTF confirmation is delayed into mapping.
# Right: request.security is part of signal logic and belongs with entries.

Kiểm tra thực tế: nếu bạn có thể giải thích strategy chỉ bằng cách đọc build_signal_frame, thiết kế là lành mạnh. Nếu hành vi bị chia tách giữa cả hai builder, hợp đồng đã bắt đầu lệch hướng.

Các lộ trình khởi đầu tốt nhất#

Theo tiến trình này để xây dựng sự tự tin với các mẫu chuẩn:

  1. Bắt đầu từ strategy khởi đầu
  2. Nghiên cứu strategy bracket
  3. Nghiên cứu strategy trailing
  4. Thêm strategy template alert
  5. Thêm thuộc tính thực tế
  6. Chuyển sang xác nhận MTF