変動調整された移動平均取引戦略

作者: リン・ハーンチャオチャン,日付: 2023年11月7日17時18分05秒
タグ:

img

概要

この戦略は,T3移動平均値,ATR指標,ハイキン・アシの組み合わせを使用して,購入・売却シグナルを識別し,ATRを使用して,トレード後のトレンドのストップ・ロストと得益レベルを計算します.この戦略の利点は,取引リスクを制御しながら迅速な応答です.

原則分析

インディケーター計算

  • T3 移動平均: 傾向の方向性を決定するために,T3 移動平均 (デフォルト期間の100) を計算する.

  • ATR: ストップ・ロスト/テイク・プロフィートのサイズを決定するために使用される平均的な真の範囲を計算します.

  • ATR トレイリングストップ: 価格変動や変動に応じて調整するATRに基づくストップ損失を計算する.

貿易の論理

  • 購入シグナル: ATR トレイリングストップを横切ってT3移動平均を下回ると切符が切れる.

  • セール・シグナル: ATR トレイリング・ストップを下回り,T3 移動平均より上回りすると切符が切れる.

  • ストップ・ロース/テイク・プロフィート: ATRとユーザー定義リスク/リターン比に基づいて計算されたエントリー,ストップ・ロース,テイク・プロフィートの価格

入国と出国

  • ロングエントリー:ストップ・ロスはエントリー価格マイナスATR,テイク・プロフィートはエントリー価格プラスATR *リスク/リターン比

  • ストップ・ロスはエントリー価格+ATR,テイク・プロフィートはエントリー価格−ATR*リスク/リターン比

  • 価格がストップ・ロスのレベルに達すると退場

利点分析

迅速 な 対応

T3移動平均デフォルト期間は100で,価格変動に迅速に対応するために典型的な移動平均よりも敏感です.

リスク管理

ATRは,ストップアウトを避けるため,市場の変動に合わせてストップを引く. ATRに基づいてストップ損失/取利益は,取引ごとにリスク/報酬を制御する.

トレンド

ATR トレイリングストップは,短期の引き下げ時にさえも,早期離脱を避ける傾向を追っている.

パラメータ最適化

T3とATRの両方の期間を異なる市場に最適化して安定性を向上させる

リスク分析

ストップ・ロスト・ブレイク・イブン

激烈な価格動向はストップロスを突破し損失を引き起こす可能性があります ATR期間とストップ距離を拡大することができます

トレンドの逆転

トレンドが逆転し,価格がトレンドストップを横切ると損失が起こり得る.逆転を特定するために他の指標を組み込むことができます.

オプティマイゼーション オーバーフィット

パラメータ最適化は,限られた歴史的データに過剰に適合するリスクがあります.市場/タイムフレームにわたって強力な最適化が必要です.

改善 の 機会

  • 異なるT3移動平均期をテストして,感性と安定性の最適なバランスを探す.

  • ATR 期間を最適化して 最適なリスク制御とバランス後の傾向を見つけます

  • ターニングポイントで間違った取引を避けるために,RSI,MACDを組み込む

  • 最適な自動化パラメータのための機械学習,手動バイアスを減らす

  • リスクをより良く制御するために,ポジションサイズ化規則を追加する

概要

この戦略は,T3とATRの利点を組み合わせて,リスク制御とともに迅速な対応を可能にします.パラメータ最適化と追加のフィルターを通じて安定性と効率性をさらに向上させることができます.しかし,トレーダーは依然として逆転とブレイクイーンのリスクを注意し,バックテスト結果に過度に依存しないべきです.


/*backtest
start: 2022-10-31 00:00:00
end: 2023-11-06 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy(title='UT Bot Alerts (QuantNomad) Strategy w/ NinjaView', overlay=true)
T3 = input(100)//600
// Input for Long Settings
// Input for Long Settings


xPrice3 = close
xe1 = ta.ema(xPrice3, T3)
xe2 = ta.ema(xe1, T3)
xe3 = ta.ema(xe2, T3)
xe4 = ta.ema(xe3, T3)
xe5 = ta.ema(xe4, T3)
xe6 = ta.ema(xe5, T3)

b3 = 0.7
c1 = -b3*b3*b3
c2 = 3*b3*b3+3*b3*b3*b3
c3 = -6*b3*b3-3*b3-3*b3*b3*b3
c4 = 1+3*b3+b3*b3*b3+3*b3*b3
nT3Average = c1 * xe6 + c2 * xe5 + c3 * xe4 + c4 * xe3

//plot(nT3Average, color=color.white, title="T3")

// Buy Signal - Price is below T3 Average
buySignal3 = xPrice3 < nT3Average
sellSignal3 = xPrice3 > nT3Average
// Inputs
a = input(1, title='Key Value. "This changes the sensitivity"')
c = input(50, title='ATR Period')
h = input(true, title='Signals from Heikin Ashi Candles')
riskRewardRatio = input(1, title='Risk Reward Ratio')

xATR = ta.atr(c)
nLoss = a * xATR

src = h ? request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, close, lookahead=barmerge.lookahead_off) : close

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

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

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

ema = ta.ema(src, 1)
above = ta.crossover(ema, xATRTrailingStop)
below = ta.crossunder(ema, xATRTrailingStop)

buy = src > xATRTrailingStop and above
sell = src < xATRTrailingStop and below

barbuy = src > xATRTrailingStop
barsell = src < xATRTrailingStop

plotshape(buy, 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(sell, title='Sell', text='Sell', style=shape.labeldown, location=location.abovebar, color=color.new(color.red, 0), textcolor=color.new(color.white, 0), size=size.tiny)

barcolor(barbuy ? color.new(color.green, 90) : na)
barcolor(barsell ? color.new(color.red, 90) : na)

var float entryPrice = na
var float takeProfitLong = na
var float stopLossLong = na
var float takeProfitShort = na
var float stopLossShort = na

if buy and buySignal3
    entryPrice := src
    takeProfitLong := entryPrice + nLoss * riskRewardRatio
    stopLossLong := entryPrice - nLoss
    takeProfitShort := na
    stopLossShort := na

if sell and sellSignal3
    entryPrice := src
    takeProfitShort := entryPrice - nLoss * riskRewardRatio
    stopLossShort := entryPrice + nLoss
    takeProfitLong := na
    stopLossLong := na

// Strategy order conditions
acct = "Sim101"
ticker = "ES 12-23"
qty = 1

OCOMarketLong = '{ "alert": "OCO Market Long", "account": "' + str.tostring(acct) + '", "ticker": "' + str.tostring(ticker) + '", "qty": "' + str.tostring(qty) + '", "take_profit_price": "' + str.tostring(takeProfitLong) + '", "stop_price": "' + str.tostring(stopLossLong) + '", "tif": "DAY" }'
OCOMarketShort = '{ "alert": "OCO Market Short", "account": "' + str.tostring(acct) + '", "ticker": "' + str.tostring(ticker) + '", "qty": "' + str.tostring(qty) + '", "take_profit_price": "' + str.tostring(takeProfitShort) + '", "stop_price": "' + str.tostring(stopLossShort) + '", "tif": "DAY" }'
CloseAll = '{ "alert": "Close All", "account": "' + str.tostring(acct) + '", "ticker": "' + str.tostring(ticker) + '" }'

strategy.entry("Long", strategy.long, when=buy ,alert_message=OCOMarketLong)
strategy.entry("Short", strategy.short, when=sell , alert_message=OCOMarketShort)

// Setting the take profit and stop loss for long trades
strategy.exit("Take Profit/Stop Loss", "Long", stop=stopLossLong, limit=takeProfitLong,alert_message=CloseAll)

// Setting the take profit and stop loss for short trades
strategy.exit("Take Profit/Stop Loss", "Short", stop=stopLossShort, limit=takeProfitShort,alert_message=CloseAll)

// Plot trade setup boxes
bgcolor(buy ? color.new(color.green, 90) : na, transp=0, offset=-1)
bgcolor(sell ? color.new(color.red, 90) : na, transp=0, offset=-1)

longCondition = buy and not na(entryPrice)
shortCondition = sell and not na(entryPrice)

var line longTakeProfitLine = na
var line longStopLossLine = na
var line shortTakeProfitLine = na
var line shortStopLossLine = na

if longCondition
    longTakeProfitLine := line.new(bar_index, takeProfitLong, bar_index + 1, takeProfitLong, color=color.green, width=2)
    longStopLossLine := line.new(bar_index, stopLossLong, bar_index + 1, stopLossLong, color=color.red, width=2)
    label.new(bar_index + 1, takeProfitLong, str.tostring(takeProfitLong, "#.#####"), color=color.green, style=label.style_none, textcolor=color.green, size=size.tiny)
    label.new(bar_index + 1, stopLossLong, str.tostring(stopLossLong, "#.#####"), color=color.red, style=label.style_none, textcolor=color.red, size=size.tiny)

if shortCondition
    shortTakeProfitLine := line.new(bar_index, takeProfitShort, bar_index + 1, takeProfitShort, color=color.green, width=2)
    shortStopLossLine := line.new(bar_index, stopLossShort, bar_index + 1, stopLossShort, color=color.red, width=2)
    label.new(bar_index + 1, takeProfitShort, str.tostring(takeProfitShort, "#.#####"), color=color.green, style=label.style_none, textcolor=color.green, size=size.tiny)
    label.new(bar_index + 1, stopLossShort, str.tostring(stopLossShort, "#.#####"), color=color.red, style=label.style_none, textcolor=color.red, size=size.tiny)

alertcondition(buy, 'UT Long', 'UT Long')
alertcondition(sell, 'UT Short', 'UT Short')


もっと