
この戦略は,EMAとSMAの2つの移動平均をベースにした交差戦略である. 遅いEMAがより速いSMAを下から上へと渡るとき,買いのシグナルを生成し,遅いEMAがより速いSMAを上から下へと渡るとき,売りのシグナルを生成する. この戦略は,牛市における上昇傾向を捉えながら,ある程度のサポートを提供することを目的としている.
この戦略は,2つの移動平均線:20周期のSMAと21周期のEMAを使用する.EMAが上下からSMAを横切るときは,市場が上昇傾向を転向している可能性があることを示すため,買取シグナルを生成する.逆に,EMAが上下からSMAを横切るときは,市場が下下傾向を転向している可能性があることを示すため,売出シグナルを生成する.信号を確認するために,この戦略は,現在の閉盘価格が前回の閉盘価格より高く (買取シグナル) または前回の閉盘価格より低く (売出シグナル) を要求する.
均線交差牛市支柱帯戦略は,牛市情勢に特に適用されるシンプルでわかりやすいトレンド追跡戦略である.しかし,この戦略には,偽信号,遅れ,トレンド識別能力の制限など,一定の制限がある.他の指標,最適化パラメータ,およびストップストップなどの方法と組み合わせることで,この戦略のパフォーマンスをさらに向上させ,安定性を高めることができる.
/*backtest
start: 2023-05-17 00:00:00
end: 2024-05-22 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © rodrinverte
//@version=5
strategy("EMA-SMA Crossover Strategy", overlay=true, initial_capital = 1000)
// Definir la longitud de las medias móviles
fast = ta.sma(close, 20)
slow = ta.ema(close, 21)
// Definir condiciones de compra y venta
buySignal = ta.crossover(slow, fast)
sellSignal = ta.crossunder(slow, fast)
// Configurar colores de las líneas y relleno
emaColor = buySignal ? color.green : sellSignal ? color.red : color.blue
smaColor = color.gray
fillColor = slow < fast ? color.new(color.green, 90) : color.new(color.red, 90)
// Esperar un periodo para confirmar la señal de compra o venta
buyConfirmation = close > close[1] and buySignal
sellConfirmation = close < close[1] and sellSignal
// Dibujar las medias móviles
plot(slow, title="EMA", color=emaColor)
plot(fast, title="SMA", color=smaColor)
// Configurar las señales de compra y venta
plotshape(buyConfirmation, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small)
plotshape(sellConfirmation, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small)
// Estrategia de compra y venta
if (buyConfirmation)
strategy.entry("Buy", strategy.long)
if (sellConfirmation)
strategy.entry("Sell", strategy.short)
// Cerrar posición opuesta al cruce original
if (sellSignal)
strategy.close("Buy")
if (buySignal)
strategy.close("Sell")