
双EMA金叉死叉トレンド追跡戦略は,双EMA指標を使用して価格トレンドの方向を判断する量化取引戦略である.この戦略は,金叉と死叉の信号を組み合わせた2つの異なるパラメータのEMA指標を計算することによって価格トレンドを判断する.より短いEMAの上部に長いEMAを通過すると買取信号が生じ,より短いEMAの下部に長いEMAを通過すると売り信号が生じます.
この戦略の核心指標は,長い周期のEMA1と短い周期のEMA2の2つのグループである.EMA1のパラメータは21で,EMA2のパラメータは10である.戦略は,4時間の線で基準周期としてこの2つのグループを計算する.
短い周期EMA2で長い周期EMA1を突破すると,買入シグナルが生じます. これは,価格の短期トレンドが強くなって,上昇状態に入ることを意味します. 短い周期EMA2の下の長い周期EMA1を突破すると,販売シグナルが生じます. これは,価格の短期上昇傾向が中断され,下降状態に入ることを意味します.
誤差信号をフィルタリングするために,戦略は2つの金叉死叉指標を設定している.二つの指標が同時に信号を発信した場合のみ,対応する買入販売操作を誘発する.これは,価格の揺れによって引き起こされる誤った取引を効果的に減らすことができる.
これらのリスクは以下の方法で制御できます.
この戦略はさらに改善できる余地があります.
モデルポートフォリオを増やす. より多くの異なるパラメータの指標の組み合わせを構築し,戦略の安定性を高める.
止損メカニズムを増やす. 合理的な止損点を設定し,単一の損失を効果的に制御する.
ダイナミックパラメータ最適化 異なる市場環境に応じてEMAのパラメータを自動的に最適化できます
機械学習技術と組み合わせて.Tensorflowなどのフレームワークを使用して,価格動向をリアルタイムで予測するモデルを訓練します.
双EMA金叉死叉トレンド追跡戦略は,シンプルで実用的なトレンド取引戦略である.双EMA指数を使用して,価格の中での短期トレンドを判断し,方向的な動きの機会を捉える.同時に,二つの金叉死叉フィルター指数と組み合わせて,誤差取引を減らすことができる.この戦略の構造はシンプルで,容易に実装され,量化取引アプリケーションに適している.継続的な最適化と改善により,戦略の優位性をさらに拡大し,安定した収益性を高める見通しがある.
/*backtest
start: 2023-02-22 00:00:00
end: 2024-02-28 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=3
/// Component Code Startt
testStartYear = input(2017, "Backtest Start Year")
testStartMonth = input(01, "Backtest Start Month")
testStartDay = input(1, "Backtest Start Day")
testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)
testStopYear = input(2020, "Backtest Stop Year")
testStopMonth = input(1, "Backtest Stop Month")
testStopDay = input(1, "Backtest Stop Day")
testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)
// A switch to control background coloring of the test period
testPeriodBackground = input(title="Color Background?", type=bool, defval=false)
testPeriodBackgroundColor = testPeriodBackground and (time >= testPeriodStart) and (time <= testPeriodStop) ? #00FF00 : na
bgcolor(testPeriodBackgroundColor, transp=97)
testPeriod() => true
// Component Code Stop
strategy(title="Ema cross strat", overlay=true)
margin = input(true, title="Margin?")
Margin = margin ? margin : false
resCustom = input(title="EMA Timeframe", defval="240" )
source = close,
len2 = input(21, minval=1, title="EMA1")
len3 = input(10, minval=1, title="EMA2")
ema2 = request.security(syminfo.tickerid,resCustom,ema(source,len2), lookahead=barmerge.lookahead_off)
ema3 = request.security(syminfo.tickerid,resCustom,ema(source,len3), lookahead=barmerge.lookahead_off)
mylong = crossover(ema3, ema2)
myshort = crossunder(ema3,ema2)
last_long = na
last_short = na
last_long := mylong ? time : nz(last_long[1])
last_short := myshort ? time : nz(last_short[1])
in_long = last_long > last_short ? 2 : 0
in_short = last_short > last_long ? 2 : 0
mylong2 = crossover(ema3, ema2)
myshort2 = crossunder(ema3, ema2)
last_long2 = na
last_short2 = na
last_long2 := mylong2 ? time : nz(last_long2[1])
last_short2 := myshort2 ? time : nz(last_short2[1])
in_long2 = last_long2 > last_short2 ? 0 : 0
in_short2 = last_short2 > last_long2 ? 0 : 0
condlongx = in_long + in_long2
condlong = crossover(condlongx, 1.9)
condlongclose = crossunder(condlongx, 1.9)
condshortx = in_short + in_short2
condshort = crossover(condshortx, 1.9)
condshortclose = crossover(condshortx, 1.9)
if crossover(condlongx, 1.9) and testPeriod() and strategy.position_size <= 0
strategy.entry("Long", strategy.long, comment="Long")
if crossover(condshortx, 1.9) and testPeriod() and strategy.position_size > 0
strategy.close("Long",when = not Margin)
if crossover(condshortx, 1.9) and testPeriod() and strategy.position_size >= 0
strategy.entry("Short", strategy.short, comment="Short", when = Margin)