Predictive Trend and Structure (Expo) for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
jkEFnxd.png


Author Message:
The Predictive Trend and Structure indicator is designed for traders seeking to identify future trend directions and interruptions in trend continuation. This indicator is unique because it employs standard deviation to predict upcoming trend directions and potential trend continuation levels. This enables traders to stay ahead of the market.
More Details : https://www.tradingview.com/v/LeeciZlD/

CODE:

CSS:
#https://www.tradingview.com/v/LeeciZlD/
#/ This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)
#// © Zeiierman
#indicator("Predictive Trend and Structure (Expo)", overlay = true)
# converted by Sam4Cok@Samer800     - 10/2023

#// ~~ Inputs {
input PeriodForStdDev  = 20;         # "Period for Std Dev"
input stdDevScaler  = 5;             # "Standard Deviation Scaler"
input PredictiveStructure   = no;    # "Predictive Structure"
input isScalpingModeEnabled = no;
input ScalpingFactor = 1.0;
input rateOfChangeFactor = 100;

def na = Double.NaN;
def bar_index = AbsValue(BarNumber());
def scalpingDivisor = if isScalpingModeEnabled then ScalpingFactor /100 else 1;

DefineGlobalColor("s_col", CreateColor(70, 40, 204));

#/ ~~ Initialize Variables {
def trend;#        = 0
def trendDirection;# = 0
#// ~~ Function to determine the trend direction {
script trendDirectionFunction {
    input dir = close;
    def diff = dir - dir[1];
    def trend = if diff > 0 then 1 else (if diff < 0 then -1 else 0);
    plot out = trend;
}
#// ~~ Function to check if the trend direction has changed {
script trendDirectionChanged {
    input trendDirection = close;
    def trend = trendDirection != trendDirection[1];
    plot out = trend;
}
#// ~~ Function to calculate standard deviation {
script stddev_function {
    input src = close;
    input len = 20;
    input scalp = no;
    input Divisor = 1;
    def bar_index = AbsValue(BarNumber());
    def scalDe0 = close * len * Divisor;
    def scalDe1 = len * Divisor;
def sum; def mean; def sum_diff; def stdev;
 if bar_index < len - 1 {
    sum      = 0;
    mean     = 0;
    sum_diff = 0;
    stdev    = 0;
    } else {
    sum      = fold i = 0 to len with p do p + src[i];
    mean     = sum / len;
    sum_diff = fold j = 0 to len with q do q + Power(src[j] - mean, 2);
    stdev    = if scalp then Sqrt(sum_diff / scalDe0) else
                             Sqrt(sum_diff / scalDe1);
}
    plot out = stdev;
}
def trend1 = if trend[1] then trend[1] else close;
def stdev = stddev_function(trend[1], PeriodForStdDev, isScalpingModeEnabled, scalpingDivisor);
def scaledStdDev    = stdDevScaler  * stdev;
def priceDifference = if close - trend1 > 0 then close - trend1 else trend1 - close;
def div = if PredictiveStructure then 0.00001 else 1 / rateOfChangeFactor;
def reciprocal_factors    = (1 / stdDevScaler) * div;

trend = if priceDifference > scaledStdDev then (close + trend1) / 2 else
           trendDirection[1] * (if trendDirectionChanged(trendDirection[1]) then scaledStdDev else
                               reciprocal_factors * scaledStdDev) + trend1;
trendDirection = trendDirectionFunction(trend);
def dirTrend = trendDirectionChanged(trendDirection);
#// ~~ Plot {
def bullish_col = if PredictiveStructure then 0 else 1;
def bearish_col = if PredictiveStructure then 0 else -1;

def col = if trendDirection == 1 then bullish_col else bearish_col;

plot trendLine = if dirTrend then na else trend;        # "Trend"
trendLine.AssignValueColor(if col > 0 then Color.CYAN else
                           if Col < 0 then Color.MAGENTA else GlobalColor("s_col"));

AddCloud(trendLine, trendLine[2], Color.VIOLET, Color.PLUM);

plot Wedges = if dirTrend then trend[-1] else na;
Wedges.SetLineWeight(2);
Wedges.SetPaintingStrategy(PaintingStrategy.SQUARES);
Wedges.AssignValueColor(if col > 0 then Color.CYAN else
                        if col < 0 then Color.MAGENTA else GlobalColor("s_col"));


#-- 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
231 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