2つの移動平均値とMACDの組み合わせによる短期取引戦略

作者: リン・ハーンチャオチャン開催日:2023年10月9日 16時47分42秒
タグ:

概要

この戦略は,二重移動平均値,ストキャスト指標,MACDを組み合わせて,比較的古典的な短期取引戦略である短期取引機会を特定します.

原則

この戦略は主に以下の原則に基づいています.

  1. 傾向の方向を決定するために50期および100期 EMAを使用する.短い期間のEMAは価格変化に迅速に対応することができる.50期EMAを100期EMA以上に横切ることは,ロングポジションを確立することを表し,横切りはショートポジションを確立することを表す.

  2. MACD の差を入力点と出口点を決定するために使用します.差が0を超えると,牛勢力の強化を示し,ロングエントリーにつながります.0を下回ると,熊勢力の強化を示し,ショートエントリーにつながります.

  3. 過剰購入と過剰販売状況を判断するためにストーカスティックRSI指標を組み合わせます.この指標はKDJとRSIの利点を組み合わせ,過剰購入と過剰販売の条件をよく示することができます.20未満の場合,市場は過剰販売であり,長引入は他の指標を組み合わせると考えられます.80を超えると,市場は過剰購入であり,短引入は考慮することができます.

  4. 入力方向が決定された後,最も最近の5個のキャンドルスタイクのうち4つの閉じる価格が移動平均値に触れた場合,移動平均値の周りにサポート/レジスタンスがあり,ポジションが開けることが示されます.

  5. リスク管理のためにストップ・ロスを使って 利益を取ります

利点

この戦略の利点は以下の通りです.

  1. 複数の指標の組み合わせにより 移動平均値,過剰購入/過剰販売指標,インパルス指標を組み合わせて 勝率を向上させることができます

  2. 短期間移動平均値は,トレンドと逆転を迅速に把握することができます. MACDパラメータは,正確なエントリー信号を生成するために最適化されています.

  3. ストカスティックRSIパラメータは,過剰購入/過剰販売の条件を適切に識別するために最適化されています.

  4. 時計制御のために移動平均値のサポート/レジスタンスを使用することで 偽のブレイクに囚われないようにします

  5. 合理的なストップ・ロストと 利潤の引き上げは,それぞれの取引のリスクを効果的に制御します.

リスク

この戦略にはいくつかのリスクもあります:

  1. 偽の脱出によって引き起こされる損失を完全に避けることができない.

  2. インディケーター間には差が起こり,取引信号が不一致する可能性があります.

  3. 固定ストップ・ロードとテイク・プロフィートは,市場の変化に適応できない可能性があります.

  4. 多くのパラメータを持つ複雑なコードは最適化するのが難しいのです

解決策は次のとおりです

  1. パラメータを最適化して 信号の質を向上させ 偽の突破の可能性を低減させる

  2. 衝突を避けるために指標の間で優先順位を設定する.

  3. 動的ストップ・ロスを採用し,ATR範囲に基づいて利益を取ります.

  4. 論理を簡素化し テストと最適化のためのコアパラメータを抽出します

オプティマイゼーションの方向性

戦略は以下の側面で最適化できます.

  1. 移動平均期とMACDパラメータの最適な組み合わせをテストして探す.

  2. ストカスティックRSIを代用するために,異なる過剰購入/過剰販売指標をテストします.

  3. ダイナミックストップ・ロストを試して 利益を引き取り リスク管理をより賢くするために トレイリングストップを試してください

  4. 信号の質を改善するために 音量を増加させるようなフィルタリング条件を追加します

  5. 効果のないブレイクアウトを避けるためにエントリーロジックを最適化し,傾向を決定するためにより多くの指標を使用します.

  6. ストップ・ロスの制限を設定します 口座のサイズや 日々の取引数によって

概要

この戦略は,複数の指標の利点を統合し,短期取引には非常に実用的です.パラメータの継続的な最適化,厳格なエントリー論理,および改善されたリスク管理により,安定性と収益性がさらに向上することができます.それはいくつかの経験を持つ短期トレーダーに適していますが,大きな損失を避けるためにリスクを制御する必要があります.


/*backtest
start: 2023-01-01 00:00:00
end: 2023-10-08 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4

strategy(title="Forex scalper 2xEMA + SRSI + MACD", shorttitle="Forex scalper 5-15min", overlay=true)
src = input(title="Source", type=input.source, defval=close)

src_0 = src[0]
src_1 = src[1]
src_2 = src[2]
src_3 = src[3]
src_4 = src[4]

len50 = input(50, minval=1, title="Length")
src50 = input(close, title="Source")
out50 = ema(src50, len50)
len100 = input(100)
src100 = input(close, title="Source")
out100 = ema(src100, len100)

len1 = input(1, minval=1, title="Length")
src1 = input(close, title="Source")
out1 = sma(src1, len1)

length = input(4, minval=1)
OverBought = input(80)
OverSold = input(20)
smoothK = 3
smoothD = 3

k = sma(stoch(close, high, low, length), smoothK)
d = sma(k, smoothD)
cu = crossover(k,OverSold)
co = crossunder(k,OverBought)

sma_down = crossunder(out1, out50)
sma_up = crossover(out1,out50)

//if (not na(k) and not na(d))
  //  if (co and k < OverSold)
    //    strategy.entry("StochLE", strategy.long, comment="StochLE")
    //if (cu and k > OverBought)
     //   strategy.entry("StochSE", strategy.short, comment="StochSE")

crossCandle_4 = crossover(src[4],out50)
crossCandleUnder_4= cross(src[4],out50)
crossCandle_3 = crossover(src[3],out50)
crossCandleUnder_3= crossunder(src[3],out50)
crossCandle_2 = crossover(src[2],out50)
crossCandleUnder_2= crossunder(src[2],out50)
crossCandle_1 = crossover(src[1],out50)
crossCandleUnder_1= crossunder(src[1],out50)
crossCandle_0 = crossover(src[0],out50)
crossCandleUnder_0= crossunder(src[0],out50)

conditionOver = (crossCandle_4 or crossCandle_3 or crossCandle_2 or crossCandle_1 or crossCandle_0)
conditionUnder =(crossCandleUnder_4 or crossCandleUnder_3 or crossCandleUnder_2 or crossCandleUnder_1 or crossCandleUnder_0)

touch4 = (cross(low[4],out50) or cross(high[4],out50))
touch3 = (cross(low[3],out50) or cross(high[3],out50))
touch2 = (cross(low[2],out50) or cross(high[2],out50))
touch1 = (cross(low[1],out50) or cross(high[1],out50))

touch = touch1 or touch2 or touch3 or touch4

//and sma_up
//and sma_down

// Getting inputs
fast_length = input(title="Fast Length", type=input.integer, defval=12)
slow_length = input(title="Slow Length", type=input.integer, defval=26)
src_macd = input(title="Source", type=input.source, defval=close)
signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 10)
sma_source = input(title="Simple MA(Oscillator)", type=input.bool, defval=false)
sma_signal = input(title="Simple MA(Signal Line)", type=input.bool, defval=false)

// Plot colors
col_grow_above = #26A69A
col_grow_below = #FFCDD2
col_fall_above = #B2DFDB
col_fall_below = #EF5350
col_macd = #0094ff
col_signal = #ff6a00

// Calculating
fast_ma = sma_source ? sma(src_macd, fast_length) : ema(src_macd, fast_length)
slow_ma = sma_source ? sma(src_macd, slow_length) : ema(src_macd, slow_length)
macd = fast_ma - slow_ma
signal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length)
hist = macd - signal

//plot(hist, title="Histogram", style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below) ), transp=0 )
//plot(macd, title="MACD", color=col_macd, transp=0)
//plot(signal, title="Signal", color=col_signal, transp=0)


// plot((conditionOver or conditionUnder or touch)  and src[0] >= out50 and close >= out50 and  (cu) and out50 > out100 and hist>=0 , title="Buy", style=columns, color=lime)
// plot((conditionOver or conditionUnder or touch)  and src[0] <= out50 and close <= out50 and  (co) and out50< out100 and hist<=0 , title="sell", style=columns, color=red)


long_cond = ((conditionOver or conditionUnder or touch)  and src[0] >= out50 and close > out50 and  (cu) and out50 > out100 and hist>=0)
short_cond = ((conditionOver or conditionUnder or touch)  and src[0] <= out50 and close < out50 and  (co) and out50< out100 and hist<=0)

tp=input(200)
sl=input(200)

strategy.entry("long",strategy.long, when=long_cond)
strategy.entry("short",strategy.short, when=short_cond)

strategy.exit("X_long", "long", profit=tp,  loss=sl, when=touch  )
strategy.exit("x_short", "short",profit=tp, loss=sl,when = touch )

もっと