[JL] Trend or Range
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © jesselau76

//@version=5
indicator(title="[JL] Trend or Range", shorttitle="ToR")
// Getting inputs
fast_length = input.int(20,title="Fast Length")
slow_length = input.int(200,title="Slow Length")
length = input.int(200,title="Trend or Range Period")
torindex = input.float(3,title="Trend or Range index")
src = input.source(close,title="Source")
atr_length = input.int(20,title="ATR Length")



// Calculating
fast_ma = ta.sma(src, fast_length) 
slow_ma = ta.sma(src, slow_length) 
atr = ta.atr(atr_length)
bars = ta.cum((fast_ma - slow_ma)/atr) 
tor = bars - bars[length]

plot(tor, title="ToR", style=plot.style_columns, color=(math.abs(tor)>=torindex*length ? color.lime : color.gray), transp=0 )

