
この戦略は,均線交差と動的ストップに基づいたトレンド追跡システムである.その核心論理は,急速な均線 ((EMA5) と遅い均線 ((EMA200)) の金叉を使って上昇トレンドの出発点を捕捉し,ATRの動的ストップと組み合わせて利益を保護することである.この戦略は,リスクと利益のバランスをとるための固定パーセントのストップ目標を設定している.
この戦略は、次のコアメカニズムに基づいて機能します。
これは,古典的な技術指標と近代的なリスク管理を組み合わせたトレンド追跡戦略である.均線交差捕捉によるトレンド,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")