
この戦略は,2つの移動平均線 (EMA) の交差を基に取引信号を生成する.短期EMA (20日) が下から上へと長いEMA (50日) を渡るときは,買入信号を生成する.短期EMAが上から下へと長いEMAを渡るときは,売り信号を生成する.同時に,この戦略は,200日間のEMAを長期トレンドの参考として描画する.この戦略の主な考え方は,異なる周期移動平均線の交差を利用して市場トレンドの転換を捕捉し,取引を行うことである.
EMA双均線交差策略は,簡単で分かりやすい,トレンド市場に適した取引策策である.短期および長期の移動平均の交差を活用して,市場動向の変化を捉え,長期のトレンド参照を導入する.この策略には,波動的な市場での不良なパフォーマンス,移動平均の遅れなどのいくつかの限界があるにもかかわらず,他の指標を導入し,パラメータを最適化し,リスク管理措置を加えるなどの方法で,戦略の安定性と収益性をさらに向上させることができる.
/*backtest
start: 2023-03-23 00:00:00
end: 2024-03-28 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("EMA Crossover Strategy by Peter Gangmei", overlay=true)
// Define the length for moving averages
short_ma_length = input.int(20, "Short MA Length")
long_ma_length = input.int(50, "Long MA Length")
long_ma_200_length = input.int(200, "Long MA 200 Length")
// Define start time for testing
start_time = timestamp(2024, 01, 01, 00, 00)
// Calculate current date and time
current_time = timenow
// Calculate moving averages
ema20 = ta.ema(close, short_ma_length)
ema50 = ta.ema(close, long_ma_length)
ema200 = ta.ema(close, long_ma_200_length)
// Crossing conditions
crossed_above = ta.crossover(ema20, ema50)
crossed_below = ta.crossunder(ema20, ema50)
// Entry and exit conditions within the specified time frame
if true
if (crossed_above)
strategy.entry("Buy", strategy.long)
alert("Buy Condition", alert.freq_once_per_bar_close)
if (crossed_below)
strategy.entry("Sell", strategy.short)
alert("Sell Condition", alert.freq_once_per_bar_close)
// Plotting moving averages for visualization
plot(ema20, color=color.green, title="EMA20")
plot(ema50, color=color.red, title="EMA50")
plot(ema200, color=color.blue, title="EMA200")
// Placing buy and sell markers
plotshape(series=crossed_above, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, title="Buy Signal")
plotshape(series=crossed_below, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, title="Sell Signal")