Untitled

mail@pastecode.io avatar
unknown
plain_text
5 months ago
1.9 kB
2
Indexable
//@version=5
indicator("Bollinger ATR", overlay=true, format=format.price, precision=2)


// 
BBperiod = input.int(defval=21, title='BB Period', minval=1)
BBdeviations = input.float(defval=1.00, title='BB Deviations', minval=0.1, step=0.05)
UseATRfilter = input(defval=false, title='ATR Filter')
ATRperiod = input.int(defval=5, title='ATR Period', minval=1)

//
BBUpper = ta.sma(close, BBperiod) + ta.stdev(close, BBperiod) * BBdeviations
BBLower = ta.sma(close, BBperiod) - ta.stdev(close, BBperiod) * BBdeviations
//
TrendLine = 0.0
iTrend = 0.0
longcondition = 0.0
shortcondition = 0.0
//
BBSignal = close > BBUpper ? 1 : close < BBLower ? -1 : 0
// 
if BBSignal == 1 and UseATRfilter == 1
    TrendLine := low - ta.atr(ATRperiod)
    if TrendLine < TrendLine[1]
        TrendLine := TrendLine[1]
        TrendLine
if BBSignal == -1 and UseATRfilter == 1
    TrendLine := high + ta.atr(ATRperiod)
    if TrendLine > TrendLine[1]
        TrendLine := TrendLine[1]
        TrendLine
if BBSignal == 0 and UseATRfilter == 1
    TrendLine := TrendLine[1]
    TrendLine
//
if BBSignal == 1 and UseATRfilter == 0
    TrendLine := low
    if TrendLine < TrendLine[1]
        TrendLine := TrendLine[1]
        TrendLine
if BBSignal == -1 and UseATRfilter == 0
    TrendLine := high
    if TrendLine > TrendLine[1]
        TrendLine := TrendLine[1]
        TrendLine
if BBSignal == 0 and UseATRfilter == 0
    TrendLine := TrendLine[1]
    TrendLine
//
iTrend := iTrend[1]
if TrendLine > TrendLine[1]
    iTrend := 1
    iTrend
if TrendLine < TrendLine[1]
    iTrend := -1
    iTrend
//
longcondition := iTrend[1] == -1 and iTrend == 1 ? 1 : na
shortcondition := iTrend[1] == 1 and iTrend == -1 ? 1 : na
//
plot(TrendLine, color=iTrend > 0 ? color.blue : color.red, style=plot.style_line, linewidth=2, title='Trend Line', transp=0, force_overlay=true)
Leave a Comment