
이 전략은 부린 띠와 ATR 지표에 기반을 두고 있으며, 부린 띠를 통해 가격의 변동 범위를 포착하고, 부린 띠를 뚫고 하향 궤도를 타는 것을 포지션 신호로 사용하며, ATR을 이동 스톱으로 사용하며, 마지막으로 간단한 이동 평균을 깨는 것을 포지션 신호로 사용한다. 이 전략은 트렌드 상황을 포착하고, 트렌드 방향에 따라 포지션을 구축하고, 트렌드가 역전될 때 평점 포지션을 취한다.
부린띠 ATR 트렌드 추적 전략은 부린띠와 ATR 지표를 통해 트렌드 시장을 포착하며, 트렌드 추적, 시간적 중단 및 간단한 사용의 장점이 있습니다. 그러나 동시에 파라미터 민감성, 변동 시장 및 트렌드 역전과 같은 위험이 있습니다. 파라미터 최적화, 필터 및 포지션 관리 등을 통해 전략 성능을 더욱 최적화 할 수 있습니다.
/*backtest
start: 2024-04-01 00:00:00
end: 2024-04-30 23:59:59
period: 4h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Bollinger Bands and ATR Strategy", overlay=true)
// Veri Çekme
symbol = "AAPL"
timeframe = "D"
src = close
// Bollinger Bantları Hesaplama
len = 20
mult = 2
sum1 = 0.0, sum2 = 0.0
for i = 0 to len - 1
sum1 += src[i]
basis = sum1 / len
for i = 0 to len - 1
diff = src[i] - basis
sum2 += diff * diff
dev = math.sqrt(sum2 / len)
upper_band = basis + dev * mult
lower_band = basis - dev * mult
// ATR Hesaplama
atr_period = input(10, title="ATR Period")
atr_value = 0.0
for i = 0 to atr_period - 1
atr_value += math.abs(src[i] - src[i + 1])
atr_value /= atr_period
loss = input(1, title="Key Value (Sensitivity)")
atr_trailing_stop = src[1]
if src > atr_trailing_stop[1]
atr_trailing_stop := math.max(atr_trailing_stop[1], src - loss * atr_value)
else if src < atr_trailing_stop[1]
atr_trailing_stop := math.min(atr_trailing_stop[1], src + loss * atr_value)
else
atr_trailing_stop := src - loss * atr_value
// Sinyal Üretme
long_condition = src < lower_band and src[1] >= lower_band[1]
short_condition = src > upper_band and src[1] <= upper_band[1]
close_long = src > basis
close_short = src < basis
buy_signal = src > atr_trailing_stop[1] and src[1] <= atr_trailing_stop[1]
sell_signal = src < atr_trailing_stop[1] and src[1] >= atr_trailing_stop[1]
if (long_condition)
strategy.entry("Long", strategy.long, comment="Long Signal")
if (short_condition)
strategy.entry("Short", strategy.short, comment="Short Signal")
if (close_long)
strategy.close("Long", comment="Close Long")
if (close_short)
strategy.close("Short", comment="Close Short")
if (buy_signal)
strategy.entry("Long", strategy.long, comment="Buy Signal")
if (sell_signal)
strategy.entry("Short", strategy.short, comment="Sell Signal")
// Çizim
plot(upper_band, color=#0000FF, linewidth=2, title="Upper Band")
plot(lower_band, color=#0000FF, linewidth=2, title="Lower Band")
plot(basis, color=#808080, linewidth=2, title="SMA")
plot(atr_trailing_stop, color=#FFA500, linewidth=2, title="ATR Trailing Stop")
plot(src, color=#FFA500, linewidth=2, title="Price")
// Sinyal İşaretleri
plotshape(long_condition, style=shape.arrowup, color=#00FF00, location=location.belowbar, size=size.small, title="Long Signal")
plotshape(short_condition, style=shape.arrowdown, color=#FF0000, location=location.abovebar, size=size.small, title="Short Signal")
plotshape(buy_signal, style=shape.diamond, color=#00FF00, location=location.belowbar, size=size.small, title="Buy Signal")
plotshape(sell_signal, style=shape.diamond, color=#FF0000, location=location.abovebar, size=size.small, title="Sell Signal")