
マルチタイムフレーム移動平均クロスオーバー戦略 (Multi Timeframe Moving Average Crossover Strategy) は,異なる時間周期の移動平均の間の交差信号を利用してトレンド方向を判断するアルゴリズム取引戦略である.この戦略は,トレンド指標,運動指標,波動率指標の組み合わせを総合的に利用し,戦略信号をより信頼性のあるものにする.
この戦略は,異なる周期のCCI指標を計算して市場のトレンド方向を判断し,MACD指標と組み合わせて金叉死叉信号を探し,最後にATR指標を使用してストップ・ロスの位置を設定し,低買い高売りを実現する.
具体的には,まず20周期のCCI指標を計算し,その正負に基づいて市場動向を判断する.次に,MACD指標の急減平均線が交差するかどうかを計算し,買入シグナルが生成されるかどうかを判断する.次に,ATR指標を使用して,トラッキングストップ・ロスの仕組みを生成し,さらに利益をロックする.最後に,上記の複数の指標のシグナルを統合して,最終的な買出戦略シグナルを生成する.
この戦略は,CCI,MACD,ATRの3つの指標の組み合わせを使用し,市場の傾向,運動,変動率を総合的に判断し,戦略信号をより正確かつ信頼性のあるものにします.
異なる周期のCCIを使用して市場の全体的な動きを判断し,高周期MACDと連携して低買い高売りノードを探し,市場のより大きなトレンドリズムを把握することができる.
ATR指標によって生成されるストップ・ロスは,市場の変動率に応じて合理的なストップ・ロスを設定でき,ストップ・ロスを追跡する機能を持ち,戦略のリスクを十分に制御できます.
この策略のパラメータの調整スペースは,効果の限界に達しやすいので,策略効果のさらなる向上を制限する.
策略は複数の指標を用いて組み合わせ算算を行うため,策略の計算負荷を一定程度に増加させる.高周波取引ではカートン問題が発生する可能性がある.
策略信号はより頻繁に発生し,リスク管理は主にATR指標のストップ・トラッキングに依存し,極端な状況に対するリスク管理は不完全である.
機械学習による超パラメータ最適化アルゴリズム (ベイエス最適化,遺伝的アルゴリズムなど) を使って,パラメータ調整をより賢く効率的に行うことができます.
戦略の適応性や強性を高めるために,波動率指標,量能指標,感情指標などの他の機能的指標を追加することを検討することができます.
より科学的な止損原理を設計したり,特定のポジション制御や資金管理モジュールを追加したりすることで,極端な状況のリスクをよりよく防ぎ,戦略の安定性を保証することができる.
多時間枠跨均線戦略は,CCI,MACD,ATRの3大指標の組み合わせを用いることで,より信頼性の高いトレンド判断と高効率のリスク管理を実現する.この戦略は,トレンド,動量,波動率の3次元を総合的に考慮し,信号正確性が高く,市場のペースを把握し,リスクを効果的に制御する利点がある.もちろん,戦略には,一定のパラメータ最適化スペース,限られた計算負荷の大きさ,およびリスク管理を向上させる問題なども存在する.より多くの指標を導入し,より優れたパラメータ最適化手段を適用し,より強力なリスク管理モジュールを設計することにより,この戦略はさらに向上させ,最適化することができる.
/*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)