Author Message:
The Predictive Channels indicator is a real-time estimate of a trend channel. The indicator returns 2 resistances, 2 supports, and an average line.
More Details : https://www.tradingview.com/v/U8SB8fWq/
CODE:
CSS:
# https://www.tradingview.com/v/U8SB8fWq/
#// This source code is subject to the terms of the Mozilla Public License 2.0
#// © LuxAlgo
#indicator("Predictive Channels [LuxAlgo]", "LuxAlgo - Predictive Channels", overlay = true)
# Converted and mod by Sam4Cok@Samer800 - 10 / 2023
input source = FundamentalType.CLOSE; # 'Source'
input useChartTimeframe = {default "Yes", "No"};
input manualTimeframe = AggregationPeriod.FIFTEEN_MIN; # 'Timeframe'
input Factor = 5; # 'Factor'
input slope = 50; # 'Slope'
input atrLength = 200;
def na = Double.NaN;
def slp = slope * Factor;
def tf = manualTimeframe;
def srcTF = Fundamental(fundamentalType = source);
def hiTf = Fundamental(fundamentalType = FundamentalType.HIGH);
def LoTf = Fundamental(fundamentalType = FundamentalType.LOW);
def srcMTF = Fundamental(fundamentalType = source, period = tf);
def hiMTF = Fundamental(fundamentalType = FundamentalType.HIGH, period = tf);
def loMTF = Fundamental(fundamentalType = FundamentalType.LOW, period = tf);
def h;def l; def c;
switch (useChartTimeframe) {
case "Yes" :
c = srcTF;
h = hiTf;
l = LoTf;
case "No" :
c = srcMTF;
h = hiMTf;
l = LoMTf;
}
#//Style
DefineGlobalColor("UpSup", Color.DARK_GREEN);
DefineGlobalColor("LoSup", Color.GREEN);
DefineGlobalColor("UpRes", Color.RED);
DefineGlobalColor("LoRes", Color.DARK_RED);
#//Calculation
def pc_avg;
def os;
def hold_atr;
def pc_avg1 = if pc_avg[1] then pc_avg[1] else c;
def os1 = (if os[1] then os[1] else 1);
def hold_atr1 = if !IsNaN(hold_atr[1]) then hold_atr[1] else 0;
def tr = TrueRange(h, c, l);
def nATR_ = WildersAverage(tr, atrLength);
def nATR = if !IsNaN(nATR_) then nATR_ else nATR[1];
def atr = nATR * Factor;
pc_avg = if AbsValue(c - pc_avg1) > atr then c else
pc_avg1 + os1 * hold_atr1 / slp;
def plotCond = pc_avg == c;
hold_atr = if plotCond then atr / 2 else hold_atr1;
os = if pc_avg > pc_avg[1] then 1 else
if pc_avg < pc_avg[1] then -1 else os1;
def pc_R2 = pc_avg + hold_atr;
def pc_R1 = pc_avg + hold_atr / 2;
def pc_S1 = pc_avg - hold_atr / 2;
def pc_S2 = pc_avg - hold_atr;
#//Plot
def plot_0 = ohlc4;
#//SR PLots
plot UpperRes = if plotCond then na else pc_R2; # 'Upper Resistance'
plot LowerRes = if plotCond then na else pc_R1; # 'Lower Resistance'
plot plot_avg = if plotCond then na else pc_avg; # 'Average'
plot UpperSupp = if plotCond then na else pc_S1; # 'Upper Support'
plot LowerSupp = if plotCond then na else pc_S2; # 'Lower Support'
plot_avg.SetStyle(Curve.MEDIUM_DASH);
UpperRes.SetDefaultColor(GlobalColor("UpRes"));
LowerRes.SetDefaultColor(GlobalColor("LoRes"));
plot_avg.SetDefaultColor(Color.GRAY);
UpperSupp.SetDefaultColor(GlobalColor("UpSup"));
LowerSupp.SetDefaultColor(GlobalColor("LoSup"));
#//Fill
def topcss = if close > pc_avg then plot_0 else na;
def btmcss = if close < pc_avg then plot_avg else na;
AddCloud(topcss, plot_avg, Color.DARK_GREEN);
AddCloud(btmcss, plot_0, Color.DARK_RED);
#-- END of CODe