该策略是一个基于均线交叉和动态止损的趋势追踪系统。核心逻辑是通过快速均线(EMA5)与慢速均线(EMA200)的金叉来捕捉上涨趋势的起点,并结合ATR动态止损来保护盈利。策略还设置了固定百分比的止盈目标,以实现风险收益的平衡。
策略运作基于以下核心机制: 1. 入场信号由EMA5上穿EMA200触发,表明短期动能突破长期趋势 2. 动态止损基于ATR指标计算,止损价格设定为收盘价减去ATR值乘以倍数 3. 止盈目标设定为入场价格的固定百分比(默认5%) 4. 持仓期间,ATR止损价会随着价格上涨而上移,形成跟踪止损 5. 当价格触及止损线或达到止盈目标时,策略自动平仓
这是一个结合经典技术指标与现代风险管理的趋势追踪策略。通过均线交叉捕捉趋势,利用ATR动态止损保护盈利,在趋势市场中表现出色。虽然存在一定的假信号风险,但通过参数优化和增加过滤器可以显著提升策略的稳定性。策略的核心优势在于其系统化的操作逻辑和灵活的风险管理机制,适合作为中长期趋势交易的基础策略框架。
/*backtest
start: 2024-02-21 00:00:00
end: 2025-02-18 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Binance","currency":"ETH_USDT"}]
*/
// -----------------------------------------------------------
// Title: EMA5 Cross-Up EMA200 with ATR Trailing Stop & Take-Profit
// Author: ChatGPT
// Version: 1.1 (Pine Script v6)
// Notes: Enter Long when EMA(5) crosses above EMA(200).
// Exit on either ATR-based trailing stop or
// specified % Take-Profit.
// -----------------------------------------------------------
//@version=6
strategy(title="EMA5 Cross-Up EMA200 ATR Stop", shorttitle="EMA5x200_ATRStop_v6", overlay=true, initial_capital=100000, default_qty_type=strategy.percent_of_equity,default_qty_value=100)
// -- 1) Inputs
emaFastLength = input.int(5, "Fast EMA Length")
emaSlowLength = input.int(200, "Slow EMA Length")
atrPeriod = input.int(14, "ATR Period")
atrMult = input.float(2.0,"ATR Multiplier", step=0.1)
takeProfitPerc = input.float(5.0,"Take-Profit %", step=0.1)
// -- 2) Indicator Calculations
emaFast = ta.ema(close, emaFastLength)
emaSlow = ta.ema(close, emaSlowLength)
atrValue = ta.atr(atrPeriod)
// -- 3) Entry Condition: EMA5 crosses above EMA200
emaCrossUp = ta.crossover(emaFast, emaSlow)
// -- 4) Determine a dynamic ATR-based stop loss (for trailing)
longStopPrice = close - (atrValue * atrMult)
// -- 5) Take-Profit Price
// We store it in a variable so we can update it when in position.
var float takeProfitPrice = na
var float avgEntryPrice = na
if strategy.position_size > 0
// If there is an open long, get the average fill price:
avgEntryPrice := strategy.position_avg_price
takeProfitPrice := avgEntryPrice * (1 + takeProfitPerc / 100)
else
// If no open position, reset
takeProfitPrice := na
avgEntryPrice := na
// -- 6) Submit Entry Order
if emaCrossUp
strategy.entry(id="Long", direction=strategy.long)
// -- 7) Submit Exit Orders (Stop or Take-Profit)
strategy.exit(id = "Exit Long",stop = longStopPrice,limit = takeProfitPrice)
// -- 8) (Optional) Plotting for Visuals
plot(emaFast, color=color.new(color.yellow, 0), linewidth=2, title="EMA Fast")
plot(emaSlow, color=color.new(color.blue, 0), linewidth=2, title="EMA Slow")
plot(longStopPrice, color=color.red, linewidth=2, title="ATR Trailing Stop")