Chandelier Exit + ATR Trailing Stop + ATR Bands

outbreeak · study · 29 行 · 点赞 380 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=4
study("Chandelier Exit + ATR Trailing Stop + ATR Bands", overlay = true)
length=input(30, minval=1,maxval = 100)
Mult=input(3, minval=1,maxval = 100)
 
RatioATR = Mult*atr(length)
 
LongStop=highest(length)-RatioATR
ShortStop=lowest(length)+RatioATR
 
LongStopBand=highest(length)-RatioATR
ShortStopBand=lowest(length)+RatioATR
ShortStopBand := close+RatioATR
LongStopBand := close-RatioATR
    
TrailStop = 0.0
TrailStop := iff(close > nz(TrailStop[1], 0) and close[1] > nz(TrailStop[1], 0), max(nz(TrailStop[1]), close - RatioATR), iff(close < nz(TrailStop[1], 0) and close[1] < nz(TrailStop[1], 0), min(nz(TrailStop[1]), close + RatioATR), iff(close > nz(TrailStop[1], 0), close - RatioATR, close + RatioATR)))
 
pos = 0
pos := iff(close[1] < nz(TrailStop[1], 0) and close > nz(TrailStop[1], 0), 1, iff(close[1] > nz(TrailStop[1], 0) and close < nz(TrailStop[1], 0), -1, nz(pos[1], 0))) 
 
colorTrail = pos == -1 ? color.orange: pos == 1 ? color.yellow : color.blue 
 
plot(TrailStop, color=colorTrail, linewidth = 2, title = "Trailing ATR Stop")
plot(ShortStop, color=color.red, linewidth = 2, title = "Short Chandelier Stop")
plot(LongStop, color=color.green, linewidth = 2, title = "Long Chandelier Stop")
ss = plot(ShortStopBand, color=color.fuchsia, linewidth = 1, title = "Short ATR Stop Band")
ls = plot(LongStopBand, color=color.aqua, linewidth = 1, title = "Long ATR Stop Band")
fill(ss, ls, color=color.navy, transp=85, title = "Background Fill")

← 返回列表