이 전략은 평균 실제 파장 지표 ATR을 기반으로 트렌드 방향을 판단하고, 트렌드가 상승할 때 더 많이 하고, 트렌드가 하락할 때 더 많이 하락하며, 트렌드 추적 유형의 전략에 속한다.
이 전략은 우선 가격의 단순 이동 평균 sma와 지수 이동 평균 ema를 계산한다. 그리고 ATR 지표, 즉 지난 N 일 동안의 평균 변동 범위를 계산한다.
이 전략은 트렌드 방향성을 판단하기 위해 에마 평균, 상반기 ((ema + ATR * 인수) 및 하반기 ((ema - ATR * 인수) 를 사용합니다. 가격이 상반기에 들어올 때, 더 많이하고, 가격이 하반기에 들어올 때, 공백을 만듭니다.
코드의 주요 논리:
ATR을 통해 동적으로 포지션을 조정하여 동향을 효과적으로 추적 할 수 있습니다.
해결책:
이 ATR 트렌드 추적 전략은 전체적인 아이디어가 명확하고, ATR 지표를 통해 트렌드 방향을 판단하는 전형적인 트렌드 추적 전략에 속한다. 전략의 장점은 간단하고 쉽게 조작할 수 있으며, 효과적으로 트렌드를 추적할 수 있다. 그러나 특정 위험이 있지만, 전략의 최대 효과를 발휘하기 위해 서로 다른 시장 환경에 최적화된 조정이 필요합니다.
/*backtest
start: 2023-08-28 00:00:00
end: 2023-09-27 00:00:00
period: 1h
basePeriod: 15m
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/
// © Investoz
//@version=4
strategy("ATR Strategy FOREX", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
len = input(26, type=input.integer, minval=1, title="Length")
mul = input(2.618, type=input.float, minval=0, title="Length")
mullow = input(2.386, type=input.float, minval=0, title="Length")
price = sma(close, 1)
average = ema(close, len)
diff = atr(len) * mul
difflow = atr(len) * mullow
bull_level = average + diff
bear_level = average - difflow
bull_cross = crossunder(price, bear_level)
bear_cross = crossunder(bull_level, price)
FromMonth = input(defval = 8, title = "From Month", minval = 1, maxval = 12)
FromDay = input(defval = 18, title = "From Day", minval = 1, maxval = 31)
FromYear = input(defval = 2008, title = "From Year", minval = 2008)
ToMonth = input(defval = 1, title = "To Month", minval = 1, maxval = 12)
ToDay = input(defval = 1, title = "To Day", minval = 1, maxval = 31)
ToYear = input(defval = 2020, title = "To Year", minval = 2019)
start = timestamp(FromYear, FromMonth, FromDay, 00, 00)
finish = timestamp(ToYear, ToMonth, ToDay, 23, 59)
startTimeOk() => true
if (startTimeOk()) and ema(close,1) > ema(close,528)
strategy.entry("KOP", strategy.long, when=bull_cross)
strategy.close("KOP", when=bear_cross)
if (startTimeOk()) and ema(close,1) < ema(close,528)
strategy.entry("SALJ", strategy.short, when=bear_cross)
strategy.close("SALJ", when=bull_cross)
plot(price, title="price", color=color.black, transp=50, linewidth=2)
a0 = plot(average, title="average", color=color.red, transp=50, linewidth=1)
a1 = plot(bull_level, title="bull", color=color.green, transp=50, linewidth=1)
a2 = plot(bear_level, title="bear", color=color.red, transp=50, linewidth=1)
fill(a0, a1, color=color.green, transp=97)
fill(a0, a2, color=color.red, transp=97)