Checklist Edge 2.0

ChecklistTrader3951 · strategy · 132 行 · 点赞 24 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Checklist Capital LLC
 
//@version=6
strategy("Checklist Edge 2.0", overlay=true, initial_capital=100000, pyramiding=0, commission_type=strategy.commission.percent, commission_value=0.0, calc_on_every_tick=false, calc_on_order_fills=true, process_orders_on_close=true, max_bars_back=1000, margin_long=0, margin_short=0, default_qty_type=strategy.fixed, default_qty_value=1)
 
// ====== Inputs for Ticks (Gold futures: 1 tick = 0.1 points)
stopTicks    = input.int(20, minval=1, title="Stop Loss Ticks", group="RISK MANAGEMENT")
trailTicks   = input.int(10, minval=1, title="Trailing Stop Ticks (after breakeven)", group="RISK MANAGEMENT")
useTrail     = input.bool(true, "Use Trailing Stop", group="RISK MANAGEMENT")
useVolFilter = input.bool(true, "Use ATR Volatility Filter", group="SETTINGS")
minVolMult   = input.float(1.0, "Min ATR vs SMA (1.0 = avg vol)", step=0.1, group="SETTINGS")
tickSize     = syminfo.mintick
 
// ====== ATR for Vol Filter
float atr    = ta.atr(14)
float atrSma = ta.sma(atr, 20)
bool volOK   = not useVolFilter or (atr > atrSma * minVolMult)
 
// ====== MAs
float ema50  = ta.ema(close, 50)
float ema200 = ta.ema(close, 200)
float ema8   = ta.ema(close, 8)
float ema14  = ta.ema(close, 14)
 
// ====== TDI
rsiPeriod     = input.int(21, minval=1, title="RSI Period", group="SETTINGS")
bandLength    = input.int(34, minval=1, title="Band Length", group="SETTINGS")
lengthrsipl   = input.int(2,  minval=0, title="Fast MA on RSI", group="SETTINGS")
lengthtradesl = input.int(7,  minval=1, title="Slow MA on RSI", group="SETTINGS")
 
float src    = close
float rsi    = ta.rsi(src, rsiPeriod)
float mid    = ta.sma(rsi, bandLength)
float fastMA = ta.sma(rsi, lengthrsipl)
float slowMA = ta.sma(rsi, lengthtradesl)
 
// ====== HTF helper (no lookahead to avoid repaint)
security_f(bool x) =>
    request.security(syminfo.tickerid, "15", x, barmerge.gaps_off, barmerge.lookahead_off)
 
// ====== Checklist booleans
bool short1  = close < ema50 and ema50 < ema200
bool short2  = close < ema50
bool short3  = ema8  < ema14
bool short4  = close < ema8 and close < ema14
bool short5  = fastMA < slowMA
bool short6  = slowMA < 50 and fastMA < 50
bool short7  = mid < 50
bool short8  = fastMA < mid
bool short9  = security_f(close < ema50)
bool short10 = security_f(ema8 < ema14)
bool short11 = security_f(mid < 50)
bool short12 = security_f(slowMA < 50 and fastMA < 50)
bool short13 = security_f(fastMA < mid)
 
bool long1   = close > ema50 and ema50 > ema200
bool long2   = close > ema50
bool long3   = ema8  > ema14
bool long4   = close > ema8 and close > ema14
bool long5   = fastMA > slowMA
bool long6   = slowMA > 50 and fastMA > 50
bool long7   = mid > 50
bool long8   = fastMA > mid
bool long9   = security_f(close > ema50)
bool long10  = security_f(ema8 > ema14)
bool long11  = security_f(mid > 50)
bool long12  = security_f(slowMA > 50 and fastMA > 50)
bool long13  = security_f(fastMA > mid)
 
// ====== Scores
int long_score  = (long1?1:0)+(long2?1:0)+(long3?1:0)+(long4?1:0)+(long5?1:0)+(long6?1:0)+(long7?1:0)+(long8?1:0)+(long9?1:0)+(long10?1:0)+(long11?1:0)+(long12?1:0)+(long13?1:0)
int short_score = (short1?1:0)+(short2?1:0)+(short3?1:0)+(short4?1:0)+(short5?1:0)+(short6?1:0)+(short7?1:0)+(short8?1:0)+(short9?1:0)+(short10?1:0)+(short11?1:0)+(short12?1:0)+(short13?1:0)
 
minAlert     = input.float(55.0, step=0.1, title="Minimum % for Entry")
bool longOK  = (long_score  / 13.0) * 100.0 >= minAlert
bool shortOK = (short_score / 13.0) * 100.0 >= minAlert
 
// Signals on confirmed bar close + vol filter
bool longSig  = barstate.isconfirmed and longOK  and not longOK[1]  and volOK
bool shortSig = barstate.isconfirmed and shortOK and not shortOK[1] and volOK
 
// ====== Fixed Tick Stops
float longStop  = close - (stopTicks * tickSize)
float shortStop = close + (stopTicks * tickSize)
 
// ====== Trailing Stop Logic (basic: activate after X ticks profit)
float longTrailStop  = useTrail ? (strategy.position_size > 0 ? math.max(longStop, close - (trailTicks * tickSize)) : na) : longStop
float shortTrailStop = useTrail ? (strategy.position_size < 0 ? math.min(shortStop, close + (trailTicks * tickSize)) : na) : shortStop
 
// ====== Simple trade counter for debugging
var int tradeCount = 0
if longSig or shortSig
    tradeCount += 1
 
// ====== Orders (one position, reverse on opposite)
if longSig
    if strategy.position_size < 0
        strategy.close("Short")
    strategy.entry("Long", strategy.long)
    strategy.exit("LX", from_entry="Long", stop=longTrailStop, trail_price=useTrail ? close + (10 * tickSize) : na, trail_offset=useTrail ? trailTicks * tickSize : na)
 
if shortSig
    if strategy.position_size > 0
        strategy.close("Long")
    strategy.entry("Short", strategy.short)
    strategy.exit("SX", from_entry="Short", stop=shortTrailStop, trail_price=useTrail ? close - (10 * tickSize) : na, trail_offset=useTrail ? trailTicks * tickSize : na)
 
// ====== Safety closes
if shortOK and strategy.position_size > 0
    strategy.close("Long")
if longOK and strategy.position_size < 0
    strategy.close("Short")
 
// ====== Plots
plotshape(longSig,  title="Buy",  text="Buy",  style=shape.triangleup,   location=location.belowbar, color=color.green)
plotshape(shortSig, title="Sell", text="Sell", style=shape.triangledown, location=location.abovebar, color=color.red)
plot(useVolFilter ? atr : na, title="ATR (Vol Filter)", color=color.blue, display=display.pane)
 
// Optional: show scores in a pane
showScores = input.bool(true, "Show % Scores (pane)")
plot(showScores ? (long_score / 13.0) * 100.0 : na, title="Long %",  linewidth=2)
plot(showScores ? (short_score / 13.0) * 100.0 : na, title="Short %", linewidth=2)
hline(minAlert, "Min %", linestyle=hline.style_dotted)
 
// Trade count label (shows on last bar)
if barstate.islast
    label.new(bar_index, high, "Total Trades: " + str.tostring(tradeCount), style=label.style_label_down)
 
// Alerts
alertcondition(longSig,  title="Strategy Long",  message="LONG")
alertcondition(shortSig, title="Strategy Short", message="SHORT")

← 返回列表