Range Identifier PineScript Code (version 6)
Range Identifier PineScript Code (version 6)
0
at https://mozilla.org/MPL/2.0/
// © AlgoTrade_Pro
//@version=6
indicator('Range Identifier [ATP🤖]')
// Inputs
i_maSource = input(close, 'Source')
i_maType = input.string('WMA', 'MA Type', options = ['EMA', 'DEMA', 'TEMA', 'WMA',
'VWMA', 'SMA', 'SMMA', 'HMA', 'LSMA', 'Kijun', 'McGinley'])
i_maLen1 = input(8, 'MA Fast Length')
i_maLen2 = input(32, 'MA Slow Length')
i_atrLen1 = input(3, 'ATR Period 1')
i_atrLen2 = input(24, 'ATR Period 2')
i_treshold = input(false, 'Custom Treshold ? Default is Auto.')
i_custom = input.float(0.1, 'Custom Treshold', minval = 0.001)
i_showBG = input(true, 'Show Background Color?')
// Moving Averages
ma(type, src, len) =>
float result = 0
if type == 'SMA' // Simple
result := ta.sma(src, len)
result
if type == 'EMA' // Exponential
result := ta.ema(src, len)
result
if type == 'DEMA' // Double Exponential
e = ta.ema(src, len)
result := 2 * e - ta.ema(e, len)
result
if type == 'TEMA' // Triple Exponential
e = ta.ema(src, len)
result := 3 * (e - ta.ema(e, len)) + ta.ema(ta.ema(e, len), len)
result
if type == 'WMA' // Weighted
result := ta.wma(src, len)
result
if type == 'VWMA' // Volume Weighted
result := ta.vwma(src, len)
result
if type == 'SMMA' // Smoothed
w = ta.wma(src, len)
result := na(w[1]) ? ta.sma(src, len) : (w[1] * (len - 1) + src) / len
result
if type == 'RMA'
result := ta.rma(src, len)
result
if type == 'HMA' // Hull
result := ta.wma(2 * ta.wma(src, len / 2) - ta.wma(src, len),
math.round(math.sqrt(len)))
result
if type == 'LSMA' // Least Squares
result := ta.linreg(src, len, 0)
result
if type == 'Kijun' //Kijun-sen
kijun = math.avg(ta.lowest(len), ta.highest(len))
result := kijun
result
if type == 'McGinley'
mg = 0.0
mg := na(mg[1]) ? ta.ema(src, len) : mg[1] + (src - mg[1]) / (len *
math.pow(src / mg[1], 4))
result := mg
result
result
// Plots
c_range = range_1 >= (i_treshold ? i_custom : treshold) ? color.lime : range_1 <= -
(i_treshold ? i_custom : treshold) ? color.red : color.gray
c_background = range_1 >= (i_treshold ? i_custom : treshold) ? color.lime : range_1
<= -(i_treshold ? i_custom : treshold) ? color.red : color.gray
// Color definitions
color_up = color.green
color_dn = color.red
//End