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