
この戦略は,私が以前公開した,シンプルなトラッキングストップ戦略のマルチタイムフレームバージョンです. 前回の戦略は,基本のトラッキングストップのみを使用して,ポジションに入りました. 効果が良かったので,私はそれを改善しようとしました.
この戦略では,ATRストップのみを使用し,他の3つのより高い時間枠と現在の時間枠を選択できます. これらの時間枠の追跡ストップは,グラフに描かれます. 4つの時間枠すべてが多頭信号を発信した場合,入場は多頭になります.
この戦略の核心は,ストップとトレンドフォローを追跡することである.ストップフォローは,ストップを設定するために使用され,ATR値の計算により,ストップが破られることを効果的に防ぐことができる.トレンドフォローは,異なる時間枠におけるトレンドの方向を観察して入場を決定する.
具体的には,戦略は,まず,異なる時間枠でATR値を計算し,止損距離を設定します. そして,価格が止損値を突破すると判断して多行または空行シグナルを発行します.
異なる周期のトレンド判断を組み合わせることで,偽ブレークを効果的にフィルターすることができる。同時に,ストップロスを追跡することで,利益をロックし,リスクを効果的に制御することができる。
解決策は
戦略は以下のように最適化できます.
この戦略は,多時間枠ATRのストップ追跡方法によって,トレンドフォローとリスクコントロールの有機的な組み合わせを実現している.単一のストップと比較して,トレンドの方向性をより明確に判断できる;単一の時間枠と比較して,多くのノイズをフィルターする.ストップパラメータと時間枠の合理的な配置は,最適な効果を達成するための鍵である.この戦略は,一定撤退を許容できる投資家に適用され,より安定した投資リターンを得ることができる.さらに最適化スペースと拡張性があり,非常に有望な戦略の考えである.
/*backtest
start: 2023-01-01 00:00:00
end: 2024-01-07 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy(title="MTF Trailing SL Strategy [QuantNomad]", shorttitle = "MTF TrailingSL [QN]", overlay = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100)
////////////
// Inputs //
atr_length = input(14, title = "ATR Length")
atr_mult = input(2, title = "ATR Mult", type = input.float)
tf2 = input('120', title = "TF2", type = input.string)
tf3 = input('180', title = "TF3", type = input.string)
tf4 = input('240', title = "TF4", type = input.string)
// BACKTESTING RANGE
// From Date Inputs
fromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)
fromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)
fromYear = input(defval = 2016, title = "From Year", minval = 1970)
// To Date Inputs
toDay = input(defval = 1, title = "To Day", minval = 1, maxval = 31)
toMonth = input(defval = 1, title = "To Month", minval = 1, maxval = 12)
toYear = input(defval = 2100, title = "To Year", minval = 1970)
// Calculate start/end date and time condition
startDate = timestamp(fromYear, fromMonth, fromDay, 00, 00)
finishDate = timestamp(toYear, toMonth, toDay, 00, 00)
time_cond = time >= startDate and time <= finishDate
//////////////////
// CALCULATIONS //
tsl() =>
// SL values
sl_val = atr_mult * atr(atr_length)
// Init Variables
pos = 0
trailing_sl = 0.0
// Signals
long_signal = nz(pos[1]) != 1 and high > nz(trailing_sl[1])
short_signal = nz(pos[1]) != -1 and low < nz(trailing_sl[1])
// Calculate SL
trailing_sl := short_signal ? high + sl_val :
long_signal ? low - sl_val :
nz(pos[1]) == 1 ? max(low - sl_val, nz(trailing_sl[1])) :
nz(pos[1]) == -1 ? min(high + sl_val, nz(trailing_sl[1])) :
nz(trailing_sl[1])
// Position var
pos := long_signal ? 1 : short_signal ? -1 : nz(pos[1])
trailing_sl
trailing_sl1 = tsl()
trailing_sl2 = security(syminfo.tickerid, tf2, tsl())
trailing_sl3 = security(syminfo.tickerid, tf3, tsl())
trailing_sl4 = security(syminfo.tickerid, tf4, tsl())
pos1 = 0
pos1 := low <= trailing_sl1 ? -1 : high >= trailing_sl1 ? 1 : nz(pos1[1])
pos2 = 0
pos2 := low <= trailing_sl2 ? -1 : high >= trailing_sl2 ? 1 : nz(pos2[1])
pos3 = 0
pos3 := low <= trailing_sl3 ? -1 : high >= trailing_sl3 ? 1 : nz(pos3[1])
pos4 = 0
pos4 := low <= trailing_sl4 ? -1 : high >= trailing_sl4 ? 1 : nz(pos4[1])
total_pos = pos1 + pos2 + pos3 + pos4
//////////////
// PLOTINGS //
plot(trailing_sl1, linewidth = 2 , color = pos1 == 1 ? color.green : color.red, title = "TSL TF1")
plot(trailing_sl2, linewidth = 2 , color = pos2 == 1 ? color.green : color.red, title = "TSL TF2", transp = 25)
plot(trailing_sl3, linewidth = 2 , color = pos3 == 1 ? color.green : color.red, title = "TSL TF3", transp = 50)
plot(trailing_sl4, linewidth = 2 , color = pos4 == 1 ? color.green : color.red, title = "TSL TF4", transp = 75)
//////////////
// STRATEGY //
//strategy.entry("long", true, stop = trailing_sl1)
//strategy.entry("short", false, stop = trailing_sl1)
strategy.entry("long", true, when = total_pos == 4)
strategy.entry("short", false, when = total_pos == -4)
strategy.close("long", when = total_pos <= 0)
strategy.close("short", when = total_pos >= 0)