Predictive Ranges [LuxAlgo] for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
rangeprede_CHARTS.png


Author Message:

The Predictive Ranges indicator aims to efficiently predict future trading ranges in real-time, providing multiple effective support & resistance levels as well as indications of the current trend direction.

Predictive Ranges was a premium feature originally released by LuxAlgo in 2020.

The feature was discontinued & made legacy, however, due to its popularity and reproduction attempts, we deemed it necessary to release it open source to the community.

CODE:
CSS:
#// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)
# https://www.tradingview.com/v/lIdNGLiV/
#// © LuxAlgo
#indicator("Predictive Ranges [LuxAlgo]", "LuxAlgo - Predictive Ranges", overlay = true)
# Converted by Sam4Cok@Samer800    - 07/2023

input showCloud = yes;
input useChartTimeframe = {Default "Yes", "No"};
input manualTimeframe   = AggregationPeriod.FIFTEEN_MIN;    # 'Timeframe'
input Source    = close;    # 'Source'
input atrLength = 200;      # 'Length'
input atrMulti = 6.0;       # 'Factor'
input rangeMulti = 2.0;


def na = Double.NaN;
DefineGlobalColor("pru", CreateColor(242,54,69));
DefineGlobalColor("dpru", CreateColor(201, 95, 104));
DefineGlobalColor("avg", CreateColor(91,156,246));
DefineGlobalColor("prl", CreateColor(8,153,129));
DefineGlobalColor("dprl", CreateColor(27,134,117));

def src; def hi; def lo;
Switch (useChartTimeframe) {
Case "Yes" : src = Source;
              hi = high;
              lo = low;
Case "No"  : src = close(Period=manualTimeframe);
              hi = high(Period=manualTimeframe);
              lo = low(Period=manualTimeframe);
}
def tr = TrueRange(hi, src, lo);
#pred_ranges(length, mult)=>
    def avg;
    def ATRtf = WildersAverage(tr, atrLength);
    def nATR =  if(isNaN(ATRtf), 0, ATRtf) * atrMulti;
    def avg_ = if (isNaN(avg[1]) or avg[1]==0) then src else avg[1];
        avg  = if src - avg_ > nATR then avg_ + nATR else
               if avg_ - src > nATR then avg_ - nATR else avg_;

    def hold_atr = if avg != avg[1] then nATR / 2 else hold_atr[1];
    def prR2 = avg + hold_atr * rangeMulti;
    def prR1 = avg + hold_atr;
    def avg0  = avg;
    def prS1 = avg - hold_atr;
    def prS2 = avg - hold_atr * rangeMulti;

#//Plots
plot plot_pru2  = if avg!=avg[1] then na else prR2;#, 'PR Upper 2'
plot plot_pru1  = if avg!=avg[1] then na else prR1;#, 'PR Upper 1'
plot plot_pravg = if avg!=avg[1] then na else avg0;# , 'PR Average'
plot plot_prl1  = if avg!=avg[1] then na else prS1;#, 'PR Lower 1'
plot plot_prl2  = if avg!=avg[1] then na else prS2;#, 'PR Lower 2'

plot_pru2.SetDefaultColor(GlobalColor("pru"));
plot_pru1.SetDefaultColor(GlobalColor("pru"));
plot_pravg.SetDefaultColor(GlobalColor("avg"));
plot_prl1.SetDefaultColor(GlobalColor("prl"));
plot_prl2.SetDefaultColor(GlobalColor("prl"));
#//Fills
AddCloud(if !showCloud or avg0!=avg0[1] then na else plot_pru2, plot_pru1, GlobalColor("dpru"));
AddCloud(if !showCloud or avg0!=avg0[1] then na else plot_prl1, plot_prl2, GlobalColor("dprl"));


#-- END of CODE
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
407 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