T3移動平均とATRに基づく取引戦略


作成日: 2023-11-07 17:18:05 最終変更日: 2023-11-07 17:18:05
コピー: 1 クリック数: 809
1
フォロー
1617
フォロワー

T3移動平均とATRに基づく取引戦略

概要

この戦略は,T3移動平均,ATR指数,ハイクルの組み合わせを使用して,買入と売却のシグナルを識別し,ATRに基づいてストップ・ストップ・ポジションを計算し,トレンドを追跡する取引を実現します.戦略の優点は,迅速な応答であり,取引リスクを制御することです.

原則分析

指標計算

  • T3移動平均:トレンドの方向を判断するために,T3 ((デフォルト100) の滑らかなパラメータであるT3移動平均を計算する.

  • ATR: ストップダストストップの位置の大きさを決定するために使用されるATR ((平均実際の波動幅) を計算する.

  • ATR移動ストップ:ATRに基づいて移動ストップラインを計算し,価格の変化と変動率に応じて調整することができ,トレンド追跡が可能である.

トランザクションロジック

  • 買取シグナル:閉盤価格でATR移動ストップラインを穿越し,T3平均を下回ると買取シグナルが生じる.

  • 売り込みシグナル: 売り込みシグナルは,ATR移動ストップラインを閉店価格の下を通過し,T3平均より上にあるときに発生します.

  • ストップ・ストップ:入場後,ATR値とユーザが設定したリスク・リターン比率に基づいてストップ・ストップ価格を計算する.

入場と出場の戦略

  • 購入後,ストップ・ロスは入場価格からATRを減算し,ストップ・ストップは入場価格からATRを加算し,リスク・リターン・レート (RRR) を掛けます.

  • 販売後,ストップ・ロスト価格は入場価格に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')