Anchored Chandelier Exit

Amphibiantrading · study · 62 行 · 点赞 890 · TradingView 原页

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

Pine Script

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Amphibiantrading
 
//@version=5
indicator("Anchored Chandelier Exit", overlay = true)
 
//----------settings---------//
mult        = input.float(3.0, 'ATR Mulitplier', inline = '1')
len         = input.int(10, 'Length', inline = '1')
date        = input.time(timestamp('Oct 01 2023'), 'Anchor Date', confirm = true)
bias        = input.string('Bullish', 'Bias', ['Bullish', 'Bearish'], confirm = true)
col         = input.color(color.red, 'Line Color', inline = '3')
labCol      = input.color(color.new(color.red,46), 'Label Color', inline = '3')
txtCol      = input.color(color.white, 'Text Color', inline = '3')
showLabs    = input.bool(true, 'Show Exit Label')
eoc         = input.bool(false, 'Exit on Close', tooltip = 'Require a close above/below the Chandelier exit line rather than wick')
 
//----------variables---------//
var stopped = false 
var float h = na
var float l = na
 
if time == date
    h := high
    l := low
 
if time > date
    if high > h
        h := high
    if low < l
        l := low
 
//----------calculations---------//
atr     = ta.atr(len) * mult
bullish = bias == 'Bullish'
 
cel     = h - atr
prevCel = nz(cel[1], cel)
cel     := close[1] > prevCel ? math.max(cel, prevCel) : cel
 
ces     = l + atr
prevCes = nz(ces[1], ces)
ces     := close[1] < prevCes ? math.min(ces, prevCes) : ces
 
//----------plots---------//
plot(time >= date and bullish and not stopped ? cel : na, style = plot.style_linebr, color = col, linewidth = 2)
plot(time >= date and not bullish and not stopped ? ces : na, color = col, style = plot.style_linebr, linewidth = 2)
 
//----------labels & alerts---------//
if time >= date and not bullish and (not eoc ? high > ces : close > ces and barstate.isconfirmed) and not stopped
    stopped := true
    if showLabs
        label.new(bar_index,ces, style = label.style_circle, color = labCol, size = size.tiny)
        label.new(bar_index,high, 'Exit', yloc = yloc.abovebar, style = label.style_label_down, color = na, textcolor = txtCol)
    alert('Stop Hit', alert.freq_once_per_bar)
 
if time >= date and bullish and (not eoc ? low < cel : close < cel and barstate.isconfirmed) and not stopped
    stopped := true
    if showLabs
        label.new(bar_index,cel, style = label.style_circle, color = labCol, size = size.tiny)
        label.new(bar_index,low, 'Exit', yloc = yloc.belowbar, style = label.style_label_up, color = na, textcolor = txtCol)
    alert('Stop Hit', alert.freq_once_per_bar)

← 返回列表