移動平均クロスオーバーシグナル戦略


作成日: 2024-01-08 15:54:32 最終変更日: 2024-01-08 15:54:32
コピー: 0 クリック数: 673
1
フォロー
1617
フォロワー

移動平均クロスオーバーシグナル戦略

概要

この戦略は,異なる種類の移動平均を計算し,描画することで,移動平均の間の交差信号を実現し,購入と売却のシグナルを発信する.

戦略原則

  1. 戦略は,SMA,EMA,WMAなど,さまざまな種類の移動平均を選択することができます.
  2. 策略は主要な移動平均を計算し,第二の移動平均を選択することも許される.
  3. 主な移動平均と第2の移動平均の交差によって市場の空虚状態を判断する.
  4. メインの移動平均線上には,その自己指定周期の移動平均線が横断する時,買入シグナルが生成され,メインの移動平均線下には,その自己指定周期の移動平均線が横断する時,売出シグナルが生成される.
  5. このように,移動平均の交差によって,市場の空虚状態をより明確に判断することができます.

戦略的優位性

  1. 移動平均のタイプは,異なるニーズに対応します.
  2. 移動平均の2つ目の線が加えられれば,信号がより明確になります.
  3. 移動平均の周期は,異なる時間周期に適用できます.
  4. グラフィックをより鮮明にするために,色を平滑に染色します.
  5. 交差信号機構を用いて,多空状態の判断が正確である.

リスクと最適化

  1. 移動平均は遅滞性があり,偽信号が発生する可能性があります. 曲線を適切に選択して移動平均に適合させることができます.
  2. 移動平均周期の設定が正しくない場合,取引機会を逃す可能性があります.最適のパラメータを見つけるためにより多くの組み合わせをテストすることができます.
  3. 取引量エネルギー指数などの他の指標と組み合わせて検証することが推奨され,リスクを減らすことができます.
  4. 信号の移動平均をカール平均に変えることが考えられます.
  5. 戦略の最適化には,LSTMなどのディープラーニングモデルと連携できます.

要約する

この戦略の概観は明快で,移動平均の交差原理を用いて市場空虚状態を判断し,異なるニーズに応えるようにパラメータをカスタマイズすることができる.また,いくつかの問題もあるが,モデルとパラメータを最適化することで改善できる.全体的に見ると,この戦略は移動平均に基づく取引戦略の典型的代表である.

ストラテジーソースコード
/*backtest
start: 2023-01-01 00:00:00
end: 2024-01-07 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=3
strategy("Moving averages-Strategy", overlay=true)
//Created by user ChrisMoody 4-24-2014
//Plots The Majority of Moving Averages
//Defaults to Current Chart Time Frame --- But Can Be Changed to Higher Or Lower Time Frames
//2nd MA Capability with Show Crosses Feature

//inputs
src = close
useCurrentRes = input(true, title="Use Current Chart Resolution?")
resCustom = input(title="Use Different Timeframe? Uncheck Box Above",defval="D")
len = input(20, title="Moving Average Length - LookBack Period")
atype = input(1,minval=1,maxval=7,title="1=SMA, 2=EMA, 3=WMA, 4=HullMA, 5=VWMA, 6=RMA, 7=TEMA")
cc = input(true,title="Change Color Based On Direction?")
smoothe = input(2, minval=1, maxval=10, title="Color Smoothing - 1 = No Smoothing")
doma2 = input(false, title="Optional 2nd Moving Average")
len2 = input(50, title="Moving Average Length - Optional 2nd MA")
atype2 = input(1,minval=1,maxval=7,title="1=SMA, 2=EMA, 3=WMA, 4=HullMA, 5=VWMA, 6=RMA, 7=TEMA")
cc2 = input(true,title="Change Color Based On Direction 2nd MA?")
warn = input(false, title="***You Can Turn On The Show Dots Parameter Below Without Plotting 2nd MA to See Crosses***")
warn2 = input(false, title="***If Using Cross Feature W/O Plotting 2ndMA - Make Sure 2ndMA Parameters are Set Correctly***")
sd = input(false, title="Show Dots on Cross of Both MA's")


res = useCurrentRes ? timeframe.period : resCustom
//hull ma definition
hullma = wma(2*wma(src, len/2)-wma(src, len), round(sqrt(len)))
//TEMA definition
ema1 = ema(src, len)
ema2 = ema(ema1, len)
ema3 = ema(ema2, len)
tema = 3 * (ema1 - ema2) + ema3

avg = atype == 1 ? sma(src,len) : atype == 2 ? ema(src,len) : atype == 3 ? wma(src,len) : atype == 4 ? hullma : atype == 5 ? vwma(src, len) : atype == 6 ? rma(src,len) : tema
//2nd Ma - hull ma definition
hullma2 = wma(2*wma(src, len2/2)-wma(src, len2), round(sqrt(len2)))
//2nd MA TEMA definition
sema1 = ema(src, len2)
sema2 = ema(sema1, len2)
sema3 = ema(sema2, len2)
stema = 3 * (sema1 - sema2) + sema3

avg2 = atype2 == 1 ? sma(src,len2) : atype2 == 2 ? ema(src,len2) : atype2 == 3 ? wma(src,len2) : atype2 == 4 ? hullma2 : atype2 == 5 ? vwma(src, len2) : atype2 == 6 ? rma(src,len2) : tema

out = avg 
out_two = avg2

out1 = request.security(syminfo.tickerid, res, out)
out2 = request.security(syminfo.tickerid, res, out_two)

ma_up = out1 >= out1[smoothe]
ma_down = out1 < out1[smoothe]

col = cc ? ma_up ? lime : ma_down ? red : aqua : aqua
col2 = cc2 ? ma_up ? lime : ma_down ? red : aqua : aqua

circleYPosition = out2

plot(out1, title="Multi-Timeframe Moving Avg", style=line, linewidth=4, color = col)
plot(doma2 and out2 ? out2 : na, title="2nd Multi-TimeFrame Moving Average", style=circles, linewidth=4, color=col2)
plot(sd and cross(out1, out2) ? circleYPosition : na,style=cross, linewidth=5, color=yellow)


longCondition = crossover(out1, out1[smoothe])
if (longCondition)
    strategy.entry("My Long Entry Id", strategy.long)

shortCondition = crossunder(out1, out1[smoothe])
if (shortCondition)
    strategy.entry("My Short Entry Id", strategy.short)