本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=3
// Copyright (c) 2019-present, Alex Orekhov (everget)
// Chandelier Exit script may be freely distributed under the MIT license.
study("Chandelier Exit", shorttitle="CE", overlay=true)
length = input(title="ATR Period", type=integer, defval=22)
mult = input(title="ATR Multiplier", type=float, step=0.1, defval=3.0)
atr = mult * atr(length)
long = highest(length) - atr
short = lowest(length) + atr
longStop = 0.0
longStop := close[1] > longStop[1] ? max(long, longStop[1]) : long
shortStop = 0.0
shortStop := close[1] < shortStop[1] ? min(short, shortStop[1]) : short
dir = 1
dir := close > shortStop[1] ? 1 : close < longStop[1] ? -1 : nz(dir[1], dir)
longColor = green
shortColor = red
plot(dir == 1 ? longStop : na, title="Long Stop", style=linebr, linewidth=2, color=longColor)
plotshape(dir == 1 and dir[1] == -1 ? longStop : na, title="Long Stop Start", location=location.absolute, style=shape.circle, size=size.tiny, color=longColor, transp=0)
plot(dir == 1 ? na : shortStop, title="Short Stop", style=linebr, linewidth=2, color=shortColor)
plotshape(dir == -1 and dir[1] == 1 ? shortStop : na, title="Short Stop Start", location=location.absolute, style=shape.circle, size=size.tiny, color=shortColor, transp=0)
changeCond = dir != dir[1]
alertcondition(changeCond, title="Alert on Chandelier Exit Direction Change", message="Chandelier Exit has changed direction!")