機械学習に基づくストカスティック最適化による価格EMA

作者: リン・ハーンチャオチャン開催日:2024年1月26日 14:57:08
タグ:

img

概要

この戦略は,トレンドにおけるより多くの機会を把握するためにスムーズムービング・アベアとストーカスティック・インジケーターを組み合わせます.主にトレンドにおけるより高い収益性を獲得するために,エントリータイム選択のためのストーカスティック・インジケーターにおけるK線とD線のクロスオーバーとともに,異なる期間を持つ2つの指数関数移動平均を使用して取引信号を生成します.

戦略原則

この戦略は12期と26期のスムーズ・ムービング・平均値を使用する. 速い線が下からスローラインを越えると,ロング. 速い線が上からスローラインを越えると,ショート. 偽信号をフィルタリングするには,速い線と遅い線が同じ方向で,速い線がスローラインの上から長い,速い線がスローライン下から短い必要があります.

ストキャスト指標のK線とD線のクロスオーバーは,エントリータイミング選択に使用されます.K線がオーバーボールドラインの下からD線を越えると,ロング.K線がオーバーボールドライン上からD線下を通ると,ショート.

スムーズ・ムービング・メアリーはトレンド方向を決定し,ストカスティック・インジケーターはノイズをフィルターし,エントリータイミングを選択する.その組み合わせはトレンドでより収益性の高い機会を得ることができる.

戦略 の 利点

  • スムーズ・ムービング・メアリーは,傾向を追跡し,傾向を追跡しやすいという特徴を持っています.
  • 雑音をフィルタリングし,収益性を向上させるためにストカスティックを使用します
  • 急速なMAと遅いMAの組み合わせにより,高速なMAが遅いMAに戻ると,より良いリスク報酬を得ることができます.
  • KラインとDラインのクロスオーバーは,さらにタイミングの最適化を提供します

したがって,この戦略は,より高い収益性を得るために,機会を捕獲するために選択的に傾向に従うことができる.

リスク分析

  • 短期間で早期離脱のリスクが高い.高速MAが遅いMAに引き戻されたときに信号が否定されるか閉じ込められる.
  • 劇的なトレンド逆転に 素早く適応できず 大幅な損失をもたらします

ストップ・ロスを設定したり より穏やかな MA パラメータを採用したりできます

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

この戦略は,次の側面からさらに最適化できる:

  1. 最適な値を見つけるために,MAパラメータの異なる組み合わせをテストする
  2. ストカスティックパラメータの異なる組み合わせをテストする
  3. ストップ損失戦略を追加
  4. 動的ストップ損失を波動性に基づいて追加する
  5. 試験パラメータの最適化
  6. パラメータを最適化するために機械学習アルゴリズムを使用する

異なるパラメータの組み合わせをテストすることで,よりよいパラメータを見つけることができる.また,ストップ・ロスの戦略は,リスクを効果的に削減し,安定性を向上させることができる.

結論

この戦略は,スムーズ・ムービング・平均値とストーカスティックの強みを統合し,よりよいエントリータイミングを選択する.操作が簡単で,制御可能なリスクと大きな実用的な価値があります.継続的なテストと最適化によりパフォーマンスをさらに向上させることができます.量子トレーダーに効率的で安定したトレンド追跡モデルを提供します.


/*backtest
start: 2024-01-18 00:00:00
end: 2024-01-25 00:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
// author SoftKill

strategy(title="Price EMA with stock", shorttitle="EMA STOCH", 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(5, 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 = 9)
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=plot.style_columns, color=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=plot.style_columns, color=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(0.1)
sl=input(0.1)

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

strategy.exit("X_long", "long", profit=close * tp / syminfo.mintick,  loss=close * sl / syminfo.mintick, when=touch  )
strategy.exit("x_short", "short",profit=close * tp / syminfo.mintick,loss=close * sl / syminfo.mintick,when = touch )

// //tp = input(0.0003, title="tp")
// tp = 0.0003
// //sl = input(1.0 , title="sl")
// sl = 1.0
// strategy.exit("closelong", "long" , profit = close * tp / syminfo.mintick, loss = close * sl / syminfo.mintick, alert_message = "closelong")
// strategy.exit("closeshort", "short" , profit = close * tp / syminfo.mintick, loss = close * sl / syminfo.mintick, alert_message = "closeshort")

もっと