Big Trend Catcher: Dual-Gate EMA & ATR Trailing Swing Trader

LegalxSeagull · strategy · 78 行 · 点赞 104 · 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/
// © LegalxSeagull
 
//@version=5
strategy("Big Trend Catcher: Dual-Gate EMA & ATR Trailing Swing Trader", 
     overlay=true, 
     initial_capital=100000, 
     default_qty_type=strategy.percent_of_equity, 
     default_qty_value=20,
     pyramiding=6,         
     process_orders_on_close=true)
 
// =============================
// INDICATORS
// =============================
ema20  = ta.ema(close, 20)
ema100 = ta.ema(close, 100)
atrVal = ta.atr(20)
volGate = volume > ta.sma(volume, 20) * 1.3
 
// =============================
// SIGNAL LOGIC
// =============================
basicEntry = (ta.crossover(close, ema20) or open > high[1]) and volGate
 
var bool signalPending = false
if basicEntry
    signalPending := true
 
// Reset signal if it takes too long or if momentum significantly fails
if ta.crossunder(close, ema20) or ta.barssince(basicEntry) > 10
    signalPending := false
 
// =============================
// THE DUAL-GATE ENTRY (FIXED)
// =============================
// Price MUST close above 100 EMA AND above 20 EMA to trigger.
// This excludes entries where price is "lagging" below short-term momentum.
confirmedEntry = signalPending and close > ema100 and close > ema20 and strategy.position_size == 0
 
if confirmedEntry
    strategy.entry("Wizard", strategy.long, comment="Entry")
    signalPending := false 
 
// =============================
// PROGRESSIVE PYRAMIDING
// =============================
avgPrice = strategy.position_avg_price
distFromEntry = (close - avgPrice) / avgPrice * 100
 
runawayScale  = strategy.position_size > 0 and distFromEntry > 10 and close > ema100 and close > ema20 and strategy.opentrades < 3
pullbackScale = ta.crossunder(low, ema20) and close > ema20 and close > ema100 and strategy.position_size > 0
 
if (runawayScale or pullbackScale)
    strategy.entry("Wizard", strategy.long, comment=runawayScale ? "Velocity" : "Pullback")
 
// =============================
// EXIT: THE IRON FLOOR
// =============================
var float TS = na
highestBase = ta.highest(high - 3.5 * atrVal, 20)
TS := (close > nz(TS[1])) ? math.max(nz(TS[1]), highestBase) : low - (atrVal * 3.5)
 
if (close < TS) or ta.crossunder(close, ema100)
    strategy.close_all(comment="Trend Death")
 
// =============================
// VISUALS
// =============================
plot(ema20, "20 EMA", color=color.yellow)
plot(ema100, "100 EMA", color=color.blue, linewidth=2)
plot(TS, "ATR Stop", color=color.red, style=plot.style_stepline)
 
 
 
// Visuals for Logic Tracking
plotshape(signalPending and (close <= ema100 or close <= ema20), "Signal Pending", shape.xcross, location.abovebar, color=color.gray, size=size.tiny)
plotshape(confirmedEntry, "Gate Entry", shape.triangleup, location.belowbar, color=color.lime, size=size.tiny)

← 返回列表