Ladder ATR
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © jason5480

//@version=5
indicator(title = 'Ladder ATR',
          shorttitle = 'LATR',
          timeframe = '',
          timeframe_gaps = true)

import HeWhoMustNotBeNamed/arraymethods/1
import HeWhoMustNotBeNamed/arrayutils/21 as pa

// INPUT ============================================================================================================
atrMaType = str.lower(input.string(defval = 'SMA', title = 'ATR Smooth Type/Len', options = ['SMA', 'EMA', 'RMA', 'WMA', 'HMA'], inline = 'ATR'))
atrLength = input.int(defval = 20, title = '', minval = 1, tooltip = 'The smoothing type and the length to be used for the ATR calculation.', inline = 'ATR')

// LOGIC ============================================================================================================
var positiveTrs = array.new<float>()
var negativeTrs = array.new<float>()

if(close > open)
    positiveTrs.push(ta.tr(true), atrLength)
else
    negativeTrs.push(ta.tr(true), atrLength)

float ladderPositiveAtr = pa.ma(positiveTrs, atrMaType, atrLength)
float ladderNegativeAtr = pa.ma(negativeTrs, atrMaType, atrLength)

// PLOT =============================================================================================================
var positiveColor = color.new(#26A69A, 0)
plot(series = ladderPositiveAtr, title = 'Positive ATR', color = positiveColor, linewidth = 1, style = plot.style_line, trackprice = true)
var negativeColor = color.new(#EF5350, 0)
plot(series = ladderNegativeAtr, title = 'Negative ATR', color = negativeColor, linewidth = 1, style = plot.style_line, trackprice = true)