Quanta Docs

Tài liệu Quanta hoàn chỉnh cho Quant Studio

Bài họcrecipelesson/regime-mean-reversion

Bài 3 — Mean reversion với guard regime

RSI<30 + chạm BB dưới → enter long; chỉ khi ATR thấp (range). Guard regime trong detect.

quanta
strategy "BB Mean Reversion"
    @regime     "mean_reversion, calm"
    @style      "swing"
    @detail "RSI oversold tại BB dưới, chỉ khi ATR% thấp (thị trường range)."

params:
  rsi_n = 14 in [7..30]
  bb_n = 20 in [10..50]
  atr_pct_max = 4pct in [1pct..8pct]

detect:
  c = market.close
  bb = bbands(c, bb_n, 2.0)
  r = rsi(c, rsi_n)
  atr_pct = atr(market.high, market.low, c, 14) / c
  calm = atr_pct < atr_pct_max

act:
  when r < 30 and c < bb.lower and calm and not position.is_long:
    enter long with wnav 5pct tag "oversold + range"
  when r > 70 and c > bb.upper and position.is_long:
    close long tag "overbought exit"

render:
  panel main:
    line bb.mid as "BB Mid" in white
    band bb.upper to bb.lower as "BB Cloud" in cyan with opacity 8pct
  panel rsi:
    line r as "RSI" in amber
    level 30 as "OS" in lime dashed
    level 70 as "OB" in red dashed
  • Guard calm là Series bool trong detect: (atr_pct < atr_pct_max). fn hiện khôngreturn — xem syntax/fn; đừng viết return atr_pct < ….
  • 4pct = scalar 0.04; so sánh với Series → bool series; when lấy bar cuối.
#intermediate
Trợ lý Quanta"Học nhanh hơn, hiệu quả hơn cùng AI"

Xin chào! Tôi là trợ lý học ngôn ngữ Quanta. Hỏi tôi về cú pháp, hàm, hoặc cách viết một chiến lược cụ thể (ví dụ: "Làm sao để xác định đỉnh đáy để vẽ trendline?").