
이 전략은 제가 이전에 발표한 간단한 추적 스톱 전략의 다중 시간 프레임 버전입니다. 이전 전략은 기본적인 추적 스톱만을 사용하여 포지션에 진입했습니다. 효과가 좋았기 때문에 몇 가지 개선을 시도했습니다.
이 전략에서는 ATR 스톱만 사용해서 다른 3개의 더 높은 시간 프레임과 현재 시간 프레임을 선택할 수 있습니다. 이 시간 프레임의 추적 스톱은 차트에 그려집니다. 4개의 시간 프레임 모두 다중 헤드 신호를 내면 더 많이 입장합니다. 적어도 2개의 시간 프레임이 다중 헤드 신호에 동의하지 않을 때 더 많은 헤드 포지션을 평행합니다.
이 전략의 핵심은 스톱을 추적하고 트렌드를 따라가는 것이다. 스톱을 추적하는 것은 스톱 지점을 설정하기 위해 사용되며, 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)