이 전략은 ATR 지표를 사용하여 동적 중지 지점을 설정하고, 가격 변동의 정도에 따라 중지 위치를 조정하여 위험 통제를 실현한다. 전략은 주로 5 일 EMA와 20 일 EMA를 형성하여 금叉을 통해 여러 입장을 하고, 그 다음 ATR 지표를 사용하여 중지 지점과 중지 지점을 설정한다. 중지 지점은 가격 변동에 따라 조정되어 더 많은 이익을 잠금한다.
이 전략은 먼저 5일 EMA에 20일 EMA를 통과하여 금포가 형성될 때 더 많은 입장을 결정한다. 입장을 마친 후, ATR 지표를 사용하여 입시 가격과 현재 가격의 ATR 배수를 계산하고, 입시 가격 아래 1.5 ATR의 중지 지점을 설정한다. 그리고는 가격이 상승함에 따라 서서히 중지 지점을 높이고, 가격이 상승하면 입시 가격 3 ATR을 초과하면 부분적으로 중지한다.
특히, 정책은 다음과 같은 변수를 정의합니다.
입점 후,atr_ref는 현재 ATR 값으로,atr_div는 입점 가격에서 현재 가격의 ATR 배수로 계산한다. 그리고는atr_div에 따라atr_down,atr_current 및atr_up의 위치를 설정한다.
가격 상승에 따라, 현재 가격의 avg와atr_up을 비교하여, avg에atr_up을 착용하면,atr_div와atr의 대응 위치를 재계산하여, 스톱 라인을 단계적으로 높이고, 포지션 수익률을 증가시킨다.
만약 가격이 입시 가격 3ATR을 초과하면, 수익을 잠금하기 위해 부분적으로 청산되며, 이 때 tookProfit 표기는 true로 설정된다. 이후 가격이 계속 상승하면, 중지 손실 위치를 계속 올린다.
ATR 지표의 동적으로 조정된 스톱로드 위치를 사용하여 시장의 변동 정도에 따라 합리적인 스톱로드 거리를 설정할 수 있다.
손실이 제한된 경우, 트렌드를 따라 운행하여 수익을 절감하십시오. 스톱 손실 라인은 점차적으로 상승하여 수익이 계속 축적됩니다.
부분적인 스톱 메커니즘은 수익의 일부를 잠금화하여 위험을 줄일 수 있다. 이후 스톱 포지션은 계속 상승하여 수익이 계속 실행될 수 있다.
ATR 지표는 비정상적인 돌파구에 민감하지 않으며, gaps로 인한 위험에 대처할 수 없습니다.
EMA 지표는 트렌드 반전을 판단할 수 없으며, 트렌드 반전이 있을 때 새로운 포지션에 들어갈 수도 있다.
일부 중단 후 손실을 되돌릴 확률이 높습니다.
변수 최적화가 부족하여, 1.5 ATR 정지 및 3 ATR 정지 가 각 품종에 따라 조정할 필요가 있다.
ATR 지표의 지연을 방지하기 위해 Donchian Channel와 같은 다른 중지 지표를 추가하는 것을 고려할 수 있습니다.
다른 평균선 지표를 테스트하거나 MACD와 같은 추세 역전을 판단할 수 있다.
부분 막힘의 비율과 수를 최적화할 수 있으며, 다른 품종에는 다른 설정이 가능하다.
매개 변수 최적화를 추가하고, 다른 ATR 배수의 스톱 로즈 효과를 테스트한다. 스텝 스톱 로즈 기능을 추가한다.
추세가 약할 때 수행을 테스트하고, 추세가 강할 때만 이 전략을 실행하는 것을 고려할 수 있다.
이 전략의 전체적인 아이디어는 명확하고 이해하기 쉽으며, ATR 지표의 동적 조정을 사용하여 거래 위험을 제어하는 것이 가장 큰 장점이다. 그러나 ATR 지표 자체는 낙후성이 있으며, 매개 변수 설정은 최적화가 필요합니다. 다른 중단 및 추세 판단 지표를 추가하는 것은 개선 방향이 될 것입니다. 또한, 일부 정지 메커니즘은 다양한 품종에 따라 최적화 테스트가 필요합니다.
/*backtest
start: 2022-10-03 00:00:00
end: 2023-10-09 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ekinbasarkomur
//@version=5
strategy("[EKIN] ATR Exit Strategy", overlay=true, initial_capital = 1000, default_qty_value = 100, default_qty_type = strategy.percent_of_equity, calc_on_every_tick = true)
// Simple EMA tracking
fastEMA = ta.ema(close, 5)
slowEMA = ta.ema (close, 20)
atr = ta.atr(14)
// We define entry price for future reference
var float entry_price = na
// We define stop and take profit for future calculations
var float stop_price = na
var float take_profit_price = na
// We define atr limtim its here
var float atr_down = na
var float atr_up = na
var float atr_current = na
var float atr_ref = na
avg = (low + high) / 2
// Conditions
enterCondition = ta.crossover(fastEMA, slowEMA)
var bool tookProfit = false
timePeriod = time >= timestamp(syminfo.timezone, 2021, 12, 15, 0, 0)
InTrade = strategy.position_size > 0
// Go long if conditions are met
if (enterCondition and timePeriod and not InTrade)
// Calculate and update variables
entry_price := avg
atr_ref := atr
atr_div = int((avg - entry_price) / atr_ref)
atr_down := entry_price + (atr_ref * (atr_div - 1.5))
atr_up := entry_price + (atr_ref * (atr_div + 1))
atr_current := entry_price + (atr_ref * atr_div)
stop_price := (entry_price - (atr_ref * 1.5))
take_profit_price := (entry_price + (atr_ref * 3))
strategy.order("buy", strategy.long, qty = 2)
// Enter here if in position
if InTrade or tookProfit
stopCondition = avg < stop_price
takeProfitCondition = avg > take_profit_price
if avg < atr_down
stopCondition := true
// Move stop price and exit price if price for each atr price increase
if avg > atr_up
if tookProfit
atr_ref := atr
atr_div = int((avg - entry_price) / atr_ref)
atr_down := entry_price + (atr_ref * (atr_div - 1))
atr_up := entry_price + (atr_ref * (atr_div + 1))
atr_current := entry_price + (atr_ref * atr_div)
// Take half of the investment if current price is 3 atr higher than entry price
if (takeProfitCondition and timePeriod and InTrade and not tookProfit)
strategy.order("take_half_profit", strategy.short, qty = 1)
tookProfit := true
// Exit position if conditions are met and reset the variables
if (stopCondition and timePeriod and InTrade)
if tookProfit
strategy.order("exit", strategy.short, qty = 1)
else
strategy.order("stop_loss", strategy.short, qty = 2)
tookProfit := false
// Plot EMA's
plot(fastEMA, color = color.blue)
plot(slowEMA, color = color.yellow)
// Plot ATR Limit/Stop positions
profit_plot = plot(series = InTrade?atr_up:na, title = "profit", color = color.green, style=plot.style_linebr)
close_plot = plot(series = InTrade?atr_current:na, title = "close", color = color.white, style=plot.style_linebr)
stop_plot = plot(series = InTrade?atr_down:na, title = "stop_loss", color = color.red, style=plot.style_linebr)
fill(profit_plot, close_plot, color = color.new(color.green, 80))
fill(close_plot, stop_plot, color =color.new(color.red,80))