
この戦略は,二指数移動平均 ((EMA) の交差に基づくトレンド追跡システムで,取引収益を最適化するために段階的な退出の仕組みを組み合わせている.この戦略は,9周期および21周期のEMAを快線および慢線として使用し,それらの交差によって市場のトレンドの変化を認識し,リスクと収益をバランスさせるために2段階のポジション退出プログラムを使用する.
戦略の核心的な論理は,高速EMA ((9サイクル) と遅いEMA ((21サイクル) の交差信号に基づいています.快線でゆっくりと進むと,システムは0.02で多頭ポジションを開きます.高速線の下をゆっくりと進むと,システムは0.02で空頭ポジションを開きます.ポジションの保持中に,戦略は2段階の退出機構を採用します.第一段階は,利潤が200点に達したときに半分のポジションを平らにする ().0.01手);第二段階は,反向交差信号が発生したときに残りのポジションを平らにする.この段階の退出は,利潤の部分をロックしながら上スペースを保つために設計されています.
これは,クラシックな均線交差戦略と近代的なポジション管理を組み合わせた完全な取引システムである. 戦略は,段階的な退出機構によって,従来の均線交差戦略の収益性を向上させていますが,依然として,特定の市場環境と自身のリスク承受能力に応じてトレーダーが適切な調整を行う必要があります.
/*backtest
start: 2024-02-25 00:00:00
end: 2025-02-22 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Binance","currency":"SOL_USDT"}]
*/
//@version=5
strategy("EMA Crossover with Partial Exit", overlay=true, default_qty_type=strategy.cash, default_qty_value=50)
// Define lot sizes
lotSize = 0.02 // Initial trade size
partialLot = 0.01 // Half quantity to close at 20 pips profit
profitTarget = 200 // 20 pips = 200 points (for Forex, adjust accordingly)
// Define EMA lengths
fastLength = 9
slowLength = 21
// Compute EMAs
fastEMA = ta.ema(close, fastLength)
slowEMA = ta.ema(close, slowLength)
// Define crossover conditions
longEntry = ta.crossover(fastEMA, slowEMA) // Buy when 9 EMA crosses above 21 EMA
shortEntry = ta.crossunder(fastEMA, slowEMA) // Sell when 9 EMA crosses below 21 EMA
// Track trade state
var float entryPrice = na
var bool inTrade = false
var bool isLong = false
// Entry Logic (Enter with 0.02 lot size)
if (longEntry and not inTrade)
strategy.entry("Long", strategy.long, qty=lotSize)
entryPrice := close
inTrade := true
isLong := true
if (shortEntry and not inTrade)
strategy.entry("Short", strategy.short, qty=lotSize)
entryPrice := close
inTrade := true
isLong := false
// Partial Exit Logic (Close 0.01 lot after 20 pips profit)
if (isLong and inTrade and close >= entryPrice + profitTarget * syminfo.mintick)
strategy.close("Long", qty=partialLot)
if (not isLong and inTrade and close <= entryPrice - profitTarget * syminfo.mintick)
strategy.close("Short", qty=partialLot)
// Full Exit (Close remaining 0.01 lot at the next major crossover)
if (isLong and shortEntry)
strategy.close("Long") // Close remaining position
inTrade := false
if (not isLong and longEntry)
strategy.close("Short") // Close remaining position
inTrade := false
// Plot EMAs
plot(fastEMA, color=color.blue, title="9 EMA")
plot(slowEMA, color=color.red, title="21 EMA")
// Mark Buy/Sell Signals
plotshape(series=longEntry, location=location.belowbar, color=color.green, style=shape.labelup, title="BUY Signal")
plotshape(series=shortEntry, location=location.abovebar, color=color.red, style=shape.labeldown, title="SELL Signal")