Created TradingView Range Identifier Indicator For ThinkOrSwim

Status
Not open for further replies.

kelvin

Member
https://www.tradingview.com/script/27DO5DG7-Range-Identifier/
//@version=4
study("Range Identifier")

// Inputs
i_maSource = input(close, "Source", input.source)
i_maType = input("WMA", "MA Type", input.string, options = ["EMA", "DEMA", "TEMA", "WMA", "VWMA", "SMA", "SMMA", "HMA", "LSMA", "Kijun", "McGinley"])
i_maLen1 = input(3, "MA Fast Length", input.integer)
i_maLen2 = input(24, "MA Slow Length", input.integer)
i_atrLen1 = input(3, "ATR Period 1", input.integer)
i_atrLen2 = input(24, "ATR Period 2", input.integer)
i_treshold = input(false, "Custom Treshold ? Default is Auto.", input.bool)
i_custom = input(0.1, "Custom Treshold", input.float, minval = 0.001)
i_showBG = input(true,"Show Background Color?")

// Moving Averages
ma(type, src, len) =>
float result = 0
if type=="SMA" // Simple
result := sma(src, len)
if type=="EMA" // Exponential
result := ema(src, len)
if type=="DEMA" // Double Exponential
e = ema(src, len)
result := 2 * e - ema(e, len)
if type=="TEMA" // Triple Exponential
e = ema(src, len)
result := 3 * (e - ema(e, len)) + ema(ema(e, len), len)
if type=="WMA" // Weighted
result := wma(src, len)
if type=="VWMA" // Volume Weighted
result := vwma(src, len)
if type=="SMMA" // Smoothed
w = wma(src, len)
result := na(w[1]) ? sma(src, len) : (w[1] * (len - 1) + src) / len
if type == "RMA"
result := rma(src, len)
if type=="HMA" // Hull
result := wma(2 * wma(src, len / 2) - wma(src, len), round(sqrt(len)))
if type=="LSMA" // Least Squares
result := linreg(src, len, 0)
if type=="Kijun" //Kijun-sen
kijun = avg(lowest(len), highest(len))
result :=kijun
if type=="McGinley"
mg = 0.0
mg := na(mg[1]) ? ema(src, len) : mg[1] + (src - mg[1]) / (len * pow(src/mg[1], 4))
result :=mg
result

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

ma1 = 100 * (ma(i_maType, i_maSource, i_maLen1) - ma(i_maType, i_maSource, i_maLen2)) * atr(i_atrLen1) + 0.00001
ma2 = ma1 / ma(i_maType, i_maSource, i_maLen2) / atr(i_atrLen2)
range = (exp(2.0*ma2) - 1.0) / (exp(2.0 * ma2) + 1.0)

// Plots
c_range = range >= (i_treshold ? i_custom : treshold) ? color.lime : range <= -(i_treshold ? i_custom : treshold) ? color.red : color.gray
c_background = range >= (i_treshold ? i_custom : treshold) ? color.lime : range <= -(i_treshold ? i_custom : treshold) ? color.red : color.gray

plot(range, "Range", c_range, 4, plot.style_line)
plot((i_treshold ? i_custom : treshold), "Upper Treshold", color.gray, 1, plot.style_circles)
plot(-(i_treshold ? i_custom : treshold), "Lower Treshold", color.gray, 1, plot.style_circles)
bgcolor(i_showBG ? c_background : na)
 
Last edited by a moderator:
https://www.tradingview.com/script/27DO5DG7-Range-Identifier/
//@version=4
study("Range Identifier")

// Inputs
i_maSource = input(close, "Source", input.source)
i_maType = input("WMA", "MA Type", input.string, options = ["EMA", "DEMA", "TEMA", "WMA", "VWMA", "SMA", "SMMA", "HMA", "LSMA", "Kijun", "McGinley"])
i_maLen1 = input(3, "MA Fast Length", input.integer)
i_maLen2 = input(24, "MA Slow Length", input.integer)
i_atrLen1 = input(3, "ATR Period 1", input.integer)
i_atrLen2 = input(24, "ATR Period 2", input.integer)
i_treshold = input(false, "Custom Treshold ? Default is Auto.", input.bool)
i_custom = input(0.1, "Custom Treshold", input.float, minval = 0.001)
i_showBG = input(true,"Show Background Color?")

// Moving Averages
ma(type, src, len) =>
float result = 0
if type=="SMA" // Simple
result := sma(src, len)
if type=="EMA" // Exponential
result := ema(src, len)
if type=="DEMA" // Double Exponential
e = ema(src, len)
result := 2 * e - ema(e, len)
if type=="TEMA" // Triple Exponential
e = ema(src, len)
result := 3 * (e - ema(e, len)) + ema(ema(e, len), len)
if type=="WMA" // Weighted
result := wma(src, len)
if type=="VWMA" // Volume Weighted
result := vwma(src, len)
if type=="SMMA" // Smoothed
w = wma(src, len)
result := na(w[1]) ? sma(src, len) : (w[1] * (len - 1) + src) / len
if type == "RMA"
result := rma(src, len)
if type=="HMA" // Hull
result := wma(2 * wma(src, len / 2) - wma(src, len), round(sqrt(len)))
if type=="LSMA" // Least Squares
result := linreg(src, len, 0)
if type=="Kijun" //Kijun-sen
kijun = avg(lowest(len), highest(len))
result :=kijun
if type=="McGinley"
mg = 0.0
mg := na(mg[1]) ? ema(src, len) : mg[1] + (src - mg[1]) / (len * pow(src/mg[1], 4))
result :=mg
result

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

ma1 = 100 * (ma(i_maType, i_maSource, i_maLen1) - ma(i_maType, i_maSource, i_maLen2)) * atr(i_atrLen1) + 0.00001
ma2 = ma1 / ma(i_maType, i_maSource, i_maLen2) / atr(i_atrLen2)
range = (exp(2.0*ma2) - 1.0) / (exp(2.0 * ma2) + 1.0)

// Plots
c_range = range >= (i_treshold ? i_custom : treshold) ? color.lime : range <= -(i_treshold ? i_custom : treshold) ? color.red : color.gray
c_background = range >= (i_treshold ? i_custom : treshold) ? color.lime : range <= -(i_treshold ? i_custom : treshold) ? color.red : color.gray

plot(range, "Range", c_range, 4, plot.style_line)
plot((i_treshold ? i_custom : treshold), "Upper Treshold", color.gray, 1, plot.style_circles)
plot(-(i_treshold ? i_custom : treshold), "Lower Treshold", color.gray, 1, plot.style_circles)
bgcolor(i_showBG ? c_background : na)
here we go - pls test it

https://usethinkscript.com/threads/range-identifier-indicator-for-thinkorswim.11871/
 
Last edited by a moderator:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Status
Not open for further replies.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
320 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top