0% found this document useful (0 votes)
244 views3 pages

Range Identifier PineScript Code (version 6)

This document contains a Pine Script™ code for a trading indicator called 'Range Identifier'. It allows users to customize moving averages, ATR periods, and thresholds for identifying market ranges and generating buy/sell signals. The script includes options for background coloring and various moving average types to enhance visual analysis on trading charts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
244 views3 pages

Range Identifier PineScript Code (version 6)

This document contains a Pine Script™ code for a trading indicator called 'Range Identifier'. It allows users to customize moving averages, ATR periods, and thresholds for identifying market ranges and generating buy/sell signals. The script includes options for background coloring and various moving average types to enhance visual analysis on trading charts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.

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

// Auto Set Treshold


float treshold = na
if timeframe.period == 'M' or timeframe.period == 'W'
treshold := 0.5
treshold
else
if timeframe.period == 'D'
treshold := 0.4
treshold
else
if timeframe.period == '240'
treshold := 0.14
treshold
else
if timeframe.period == '60'
treshold := 0.08
treshold
else
if timeframe.period == '30'
treshold := 0.05
treshold
else
if timeframe.period == '15'
treshold := 0.04
treshold
else
if timeframe.period == '5'
treshold := 0.02
treshold
else
if timeframe.period == '1'
treshold := 0.01
treshold

ma1 = 100 * (ma(i_maType, i_maSource, i_maLen1) - ma(i_maType, i_maSource,


i_maLen2)) * ta.atr(i_atrLen1) + 0.00001
ma2 = ma1 / ma(i_maType, i_maSource, i_maLen2) / ta.atr(i_atrLen2)
range_1 = (math.exp(2.0 * ma2) - 1.0) / (math.exp(2.0 * ma2) + 1.0)

// 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

plot(range_1, 'Range', c_range, 4, plot.style_line)


plot(i_treshold ? i_custom : treshold, 'Upper Treshold', color.new(color.gray, 0),
1, plot.style_circles)
plot(-(i_treshold ? i_custom : treshold), 'Lower Treshold', color.new(color.gray,
0), 1, plot.style_circles)
bgcolor(i_showBG ? c_background : na)

// Detect crossovers for signal generation


up = ta.crossover(range_1, i_treshold ? i_custom : treshold)
dn = ta.crossunder(range_1, -(i_treshold ? i_custom : treshold))

// Color definitions
color_up = color.green
color_dn = color.red

// Plot signals on the chart


plotshape(up, 'BUY Label', shape.triangleup, location.bottom, color_up, 0, 'BUY',
chart.fg_color, true, size.tiny, force_overlay = true)
plotshape(dn, 'SELL Label', shape.triangledown, location.top, color_dn, 0, 'SELL',
chart.fg_color, true, size.tiny, force_overlay = true)

// Color the background on signal occurrences


bgcolor(up ? color.new(color_up, 90) : na, force_overlay = true, editable = true)
bgcolor(dn ? color.new(color_dn, 90) : na, force_overlay = true, editable = true)

//End

You might also like