多期移動平均クロスオーバー戦略

作者: リン・ハーンチャオチャン,日付: 2024-02-19 15:41:29
タグ:

img

概要

マルチタイムフレーム移動平均クロスオーバー戦略は,異なるタイムフレーム間の移動平均クロスオーバー信号を使用してトレンド方向を決定するアルゴリズム的な取引戦略である.この戦略は,より信頼性の高いトレード信号を生成するためにトレンド,モメンタム,変動指標を組み合わせます.

戦略の論理

この戦略では,CCI指標を異なる期間にわたって計算し,市場傾向の方向性を決定し,GOLDEN CROSSとDEATH CROSSを特定するためのMACD信号と組み合わせ,最後にATR指標を使用して,低価格で購入し,高価格で販売するためにストップ・ロスト/テイク・プロフィートレベルを設定します.

ATRは20期間のCCIを計算し,上昇傾向や下落傾向を判断する.その後,MACD線が交差しているかどうかを確認し,取引シグナルを識別する.次に,ATRは利益をロックするためにトレーリングストップを生成するために使用される.最後に,すべてのシグナルが統合され,エントリーと出口シグナルを生成する.

利点

  1. 複数のインジケーターの組み合わせにより信号の精度が向上します

    CCI,MACD,ATRの組み合わせにより,トレンド,モメンタム,波動性を集約して判断することで,取引信号の信頼性が向上します.

  2. 多期分析は市場リズムを把握する

    より長い期間のCCIは全体的な傾向を把握し,より高い周波数のMACDは地元のターニングポイントを特定し,戦略は大きな市場の変動を活用することができます.

  3. ATR の後部停止制御は,効果的にリスク

    ATRをベースにしたストップロスは市場の変動に適応できるが,トレーリング機能は市場の好調な動きにより利益をさらに固定する.

リスク

  1. 制限された最適化空間

    ほとんどのパラメータは細かな調整スペースが狭いので,性能ボトルネックに簡単に到達できます.

  2. 計算負荷増加

    複数の指標が同時に動いている場合 計算負荷が増加し 高周波取引に遅れが生じます

  3. 頻繁に信号を送る リスク管理が限られている

    信号は頻繁で,リスク制御は主にATRの後続停止に依存し,極端な動きに対して制限があります.

改良

  1. より効率的なパラメータ調整のために機械学習を適用する

    ベイジアン最適化や遺伝アルゴリズムなどにより知的で効率的なパラメータ調整が可能になります

  2. 適応性を向上させる機能指標を追加する

    戦略をより堅牢で柔軟にすることができます 戦略は,より堅牢で柔軟にできます

  3. 安定性を高めるリスク管理を強化する

    より科学的なストップ・ロスのルールが設計され ポジション・サイジングのようなさらなるモジュールが 極端な出来事から守るのに役立ちます

結論

マルチタイムフレーム移動平均クロスオーバー戦略は,信頼性の高いトレンドキャプチャと効率的なリスク制御を達成するためにCCI,MACD,ATRの力を活用する.正確な信号を生成し,市場のリズムを理解し,リスクを管理するためにトレンド,モメンタム,不安定性を考慮する.パラメータチューニング,コンピューティング負荷,リスク管理などのいくつかの側面がさらに改善され得るものの,それは堅牢なアルゴリズム取引システムである.機械学習,より多くの指標,より良いリスク管理を使用していくつかの強化により,そのパフォーマンスは新しいレベルに達することができます.


/*backtest
start: 2024-01-01 00:00:00
end: 2024-01-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy('smplondonclinic Strategy', shorttitle='SMPLC Strategy', overlay=true, pyramiding = 0, process_orders_on_close = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100)

direction   = input.string(title='Entry Direction', defval='Long', options=['Long', 'Short', 'Both'],group = "Strategy Entry Direction")

TPPerc = input.float(title='Take Profit (%)', minval=0.0, step=0.1, defval=0.5, group='Strategy TP & SL')
SLPerc = input.float(title='Stop Loss (%)', minval=0.0, step=0.1, defval=0.5, group='Strategy TP & SL')

period = input(20, 'CCI period',group = "TREND MAGIC")
coeff = input(1, 'ATR Multiplier',group = "TREND MAGIC")
AP = input(5, 'ATR Period',group = "TREND MAGIC")
ATR = ta.sma(ta.tr, AP)
srctm = close
upT = low - ATR * coeff
downT = high + ATR * coeff
MagicTrend = 0.0
MagicTrend := ta.cci(srctm, period) >= 0 ? upT < nz(MagicTrend[1]) ? nz(MagicTrend[1]) : upT : downT > nz(MagicTrend[1]) ? nz(MagicTrend[1]) : downT
color1 = ta.cci(srctm, period) >= 0 ? #0022FC : #FC0400
plot(MagicTrend, color=color1, linewidth=3)
tmb = ta.cci(srctm, period) >= 0 and close>MagicTrend
tms = ta.cci(srctm, period) <= 0 and close<MagicTrend

//MACD

res           = input.timeframe("",  "Indicator TimeFrame", group = "MACD")
fast_length   = input.int(title="Fast Length", defval=12, group = "MACD")
slow_length   = input.int(title="Slow Length", defval=26, group = "MACD")
src           = input.source(title="Source", defval=close, group = "MACD")
signal_length = input.int(title="Signal Smoothing", minval = 1, maxval = 999, defval = 9, group = "MACD")
sma_source    = input.string(title="Oscillator MA Type", defval="EMA", options=["SMA", "EMA"], group = "MACD")
sma_signal    = input.string(title="Signal Line MA Type", defval="EMA", options=["SMA", "EMA"], group = "MACD")

fast_ma = request.security(syminfo.tickerid, res, sma_source == "SMA" ? ta.sma(src, fast_length) : ta.ema(src, fast_length))
slow_ma = request.security(syminfo.tickerid, res, sma_source == "SMA" ? ta.sma(src, slow_length) : ta.ema(src, slow_length))
macd = fast_ma - slow_ma
signal = request.security(syminfo.tickerid, res, sma_signal == "SMA" ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length))
hist = macd - signal

trend_up   = macd > signal
trend_dn   = macd < signal
cross_UP   = signal[1] >= macd[1] and signal < macd
cross_DN   = signal[1] <= macd[1] and signal > macd
cross_UP_A = (signal[1] >= macd[1] and signal < macd) and macd > 0
cross_DN_B = (signal[1] <= macd[1] and signal > macd) and macd < 0


//UT Bot

srcut = close
showut = input.bool(false, 'Show UT Bot Labels', group = "UT BOT")
keyvalue = input.float(2, title='Key Vaule. \'This changes the sensitivity\'', step=.5, group = "UT BOT")
atrperiod = input(7, title='ATR Period', group = "UT BOT")
xATR = ta.atr(atrperiod)
nLoss = keyvalue * xATR

xATRTrailingStop = 0.0
iff_1 = srcut > nz(xATRTrailingStop[1], 0) ? srcut - nLoss : srcut + nLoss
iff_2 = srcut < nz(xATRTrailingStop[1], 0) and srcut[1] < nz(xATRTrailingStop[1], 0) ? math.min(nz(xATRTrailingStop[1]), srcut + nLoss) : iff_1
xATRTrailingStop := srcut > nz(xATRTrailingStop[1], 0) and srcut[1] > nz(xATRTrailingStop[1], 0) ? math.max(nz(xATRTrailingStop[1]), srcut - nLoss) : iff_2

pos = 0
iff_3 = srcut[1] > nz(xATRTrailingStop[1], 0) and srcut < nz(xATRTrailingStop[1], 0) ? -1 : nz(pos[1], 0)
pos := srcut[1] < nz(xATRTrailingStop[1], 0) and srcut > nz(xATRTrailingStop[1], 0) ? 1 : iff_3

xcolor = pos == -1 ? color.red : pos == 1 ? color.green : color.blue

//plot(xATR, color=xcolor, title='Trailing Stop')
buy = ta.crossover(srcut, xATRTrailingStop)
sell = ta.crossunder(srcut, xATRTrailingStop)
barcolor = srcut > xATRTrailingStop

plotshape(showut ? buy:na, title='Buy', text='Buy', style=shape.labelup, location=location.belowbar, color=color.new(color.green, 0), textcolor=color.new(color.white, 0), size=size.tiny)
plotshape(showut ? sell:na, title='Sell', text='Sell', style=shape.labeldown, color=color.new(color.red, 0), textcolor=color.new(color.white, 0), size=size.tiny)

//barcolor(barcolor ? color.green : color.red)

goLong = buy and tmb and cross_UP
goShort = sell and tms and cross_DN

plotshape(goLong, location=location.bottom, style=shape.triangleup, color=color.lime, size=size.small)
plotshape(goShort, location=location.top, style=shape.triangledown, color=color.red, size=size.small)

percentAsPoints(pcnt) =>
    strategy.position_size != 0 ? math.round(pcnt / 100.0 * strategy.position_avg_price / syminfo.mintick) : float(na)

percentAsPrice(pcnt) =>
    strategy.position_size != 0 ? (pcnt / 100.0 + 1.0) * strategy.position_avg_price : float(na)

current_position_size = math.abs(strategy.position_size)
initial_position_size = math.abs(ta.valuewhen(strategy.position_size[1] == 0.0, strategy.position_size, 0))

TP = strategy.position_avg_price + percentAsPoints(TPPerc) * syminfo.mintick * strategy.position_size / math.abs(strategy.position_size)
SL = strategy.position_avg_price - percentAsPoints(SLPerc) * syminfo.mintick * strategy.position_size / math.abs(strategy.position_size)

var long = false
var short = false

if direction == 'Long' 
    long := goLong
    short := false

if direction == 'Short'
    short := goShort
    long := false

if direction == 'Both' 
    long := goLong
    short := goShort

if long and strategy.opentrades == 0
    strategy.entry(id='Long', direction=strategy.long)

if short and strategy.opentrades == 0
    strategy.entry(id='Short', direction=strategy.short)

if strategy.position_size > 0

    strategy.exit('TPSL', from_entry='Long', qty=initial_position_size, limit=TP, stop=SL)

if strategy.position_size < 0

    strategy.exit('TPSL2', from_entry='Short', qty=initial_position_size, limit=TP, stop=SL)



もっと