CDF Approximation For ThinkOrSwim

amalia

Member
#amalia 8.22.22
#equation 7.1.26 from reference the “Handbook of Mathematical Functions” (1965), by Abramowitz and Stegun.
#Hint: The error function here is a very close approximation to a Cumulative Distribution Function.

declare lower;

input n = 252;
input price = Close;

def u = average(price, n);
def sigma = StDev(price, n);
def z = (price - u) / sigma;

def p = 0.3275911;
def a1 = 0.254829592;
def a2 = -0.284496736;
def a3 = 1.421413741;
def a4 = -1.453152027;
def a5 = 1.061405429;

def sign = If((z < 0.0), -1, 1);

def x = AbsValue(z) / Sqrt(2.0);
def t = 1.0 / (1.0 + p * x);
def erf = 1.0 - (((((a5 * t + a4) * t) + a3) * t + a2) * t + a1) * t * Exp(-x * x);

plot CDF = 0.5 * (1.0 + sign * erf);

Please note that this is for a normal distribution.
 
Just a fancy way of looking at a normal distribution. Load this study on a chart with a ZScore of the same length/n/population sample and you'll begin to understand it a bit better.

@amalia : Thanks for following-up and for the tip :) It's a wee bit above my paygrade, but, as recommended, I'll hook it up with ZScore and let the Enlightenment begin :LOL: I'm always up for a new learning experience...

Good Luck and Good Trading :cool:
 
I took your indicator and changed it from using just an average to using a 2 pole Butterworth filter. I'm using Guppy lengths and I'm looking for when they are above .5 or below .5 and created a binary indicator
Code:
declare Lower;
input period1 = 3;
input period2 = 5;
input period3 = 8;
input period4 = 10;
input period5 = 12;
input period6 = 15;
input period7 = 30;
input period8 = 35;
input period9 = 40;
input period10 = 45;
input period11 = 50;
input period12 = 60;
input paintbars = 0;
Input dotsize = 3;
Def price = (Open + Close)/2;
def a1A = exp(-1.414 * 3.14159 / Period1);
def b1A = 2 * a1A * Cos(1.414 * 3.14159 / Period1);
def coef2A =b1A;
def coef3A = -a1A * a1A;
def coef1A = (1 – b1A + a1A * a1A) / 4;
rec ButterA = if barNumber() < 3 then Price else coef1A * (Price + 2 * Price[1] + Price[2]) + coef2A * ButterA[1] + coef3A * ButterA[2];
def a1B = exp(-1.414 * 3.14159 / Period2);
def b1B = 2 * a1B * Cos(1.414 * 3.14159 / Period2);
def coef2B =b1B;
def coef3B = -a1B * a1B;
def coef1B = (1 – b1B + a1B * a1B) / 4;
rec ButterB = if barNumber() < 3 then Price else coef1B * (Price + 2 * Price[1] + Price[2]) + coef2B * ButterB[1] + coef3B * ButterB[2];
def a1C = exp(-1.414 * 3.14159 / Period3);
def b1C = 2 * a1C * Cos(1.414 * 3.14159 / Period3);
def coef2C =b1C;
def coef3C = -a1C * a1C;
def coef1C = (1 – b1C + a1C * a1C) / 4;
rec ButterC = if barNumber() < 3 then Price else coef1C * (Price + 2 * Price[1] + Price[2]) + coef2C * ButterC[1] + coef3C * ButterC[2];
def a1D = exp(-1.414 * 3.14159 / Period4);
def b1D = 2 * a1D * Cos(1.414 * 3.14159 / Period4);
def coef2D =b1D;
def coef3D = -a1D * a1D;
def coef1D = (1 – b1D + a1D * a1D) / 4;
rec ButterD= if barNumber() < 3 then Price else coef1D * (Price + 2 * Price[1] + Price[2]) + coef2D * ButterD[1] + coef3D * ButterD[2];
def a1E = exp(-1.414 * 3.14159 / Period5);
def b1E = 2 * a1E * Cos(1.414 * 3.14159 / Period5);
def coef2E =b1E;
def coef3E = -a1E * a1E;
def coef1E = (1 – b1E + a1E * a1E) / 4;
rec ButterE = if barNumber() < 3 then Price else coef1E * (Price + 2 * Price[1] + Price[2]) + coef2E * ButterE[1] + coef3E * ButterE[2];
def a1F = exp(-1.414 * 3.14159 / Period6);
def b1F = 2 * a1F * Cos(1.414 * 3.14159 / Period6);
def coef2F =b1F;
def coef3F = -a1F * a1F;
def coef1F = (1 – b1F + a1F * a1F) / 4;
rec ButterF = if barNumber() < 3 then Price else coef1F * (Price + 2 * Price[1] + Price[2]) + coef2F * ButterF[1] + coef3F * ButterF[2];
def a1G = exp(-1.414 * 3.14159 / Period7);
def b1G = 2 * a1G * Cos(1.414 * 3.14159 / Period7);
def coef2G =b1G;
def coef3G = -a1G * a1G;
def coef1G = (1 – b1G + a1G * a1G) / 4;
rec ButterG = if barNumber() < 3 then Price else coef1G * (Price + 2 * Price[1] + Price[2]) + coef2G * ButterG[1] + coef3G * ButterG[2];
def a1H = exp(-1.414 * 3.14159 / Period8);
def b1H = 2 * a1H * Cos(1.414 * 3.14159 / Period8);
def coef2H =b1H;
def coef3H = -a1H * a1H;
def coef1H = (1 – b1H + a1H * a1H) / 4;
rec ButterH = if barNumber() < 3 then Price else coef1H * (Price + 2 * Price[1] + Price[2]) + coef2H * ButterH[1] + coef3H * ButterH[2];
def a1I = exp(-1.414 * 3.14159 / Period9);
def b1I = 2 * a1I * Cos(1.414 * 3.14159 / Period9);
def coef2I =b1I;
def coef3I = -a1I * a1I;
def coef1I = (1 – b1I + a1I * a1I) / 4;
rec ButterI = if barNumber() < 3 then Price else coef1I * (Price + 2 * Price[1] + Price[2]) + coef2I * ButterI[1] + coef3I * ButterI[2];
def a1J = exp(-1.414 * 3.14159 / Period10);
def b1J = 2 * a1J * Cos(1.414 * 3.14159 / Period10);
def coef2J =b1J;
def coef3J = -a1J * a1J;
def coef1J = (1 – b1J + a1J * a1J) / 4;
rec ButterJ = if barNumber() < 3 then Price else coef1J * (Price + 2 * Price[1] + Price[2]) + coef2J * ButterJ[1] + coef3J * ButterJ[2];
def a1K = exp(-1.414 * 3.14159 / Period11);
def b1K = 2 * a1K * Cos(1.414 * 3.14159 / Period11);
def coef2K =b1K;
def coef3K = -a1K * a1K;
def coef1K = (1 – b1K + a1K * a1K) / 4;
rec ButterK = if barNumber() < 3 then Price else coef1K * (Price + 2 * Price[1] + Price[2]) + coef2K * ButterK[1] + coef3K * ButterK[2];
def a1L = exp(-1.414 * 3.14159 / Period12);
def b1L = 2 * a1L * Cos(1.414 * 3.14159 / Period12);
def coef2L =b1L;
def coef3L = -a1L * a1L;
def coef1L = (1 – b1L + a1L * a1L) / 4;
rec ButterL = if barNumber() < 3 then Price else coef1L * (Price + 2 * Price[1] + Price[2]) + coef2L * ButterL[1] + coef3L * ButterL[2];

def sigmaA = StDev(price, Period1);
def sigmaB = StDev(price, Period2);
def sigmaC = StDev(price, Period3);
def sigmaD = StDev(price, Period4);
def sigmaE = StDev(price, Period5);
def sigmaF = StDev(price, Period6);
def sigmaG = StDev(price, Period7);
def sigmaH = StDev(price, Period8);
def sigmaI = StDev(price, Period9);
def sigmaJ = StDev(price, Period10);
def sigmaK = StDev(price, Period11);
def sigmaL = StDev(price, Period12);

def zA = (price - ButterA) / sigmaA;
def zB = (price - ButterB) / sigmaB;
def zC = (price - ButterC) / sigmaC;
def zD = (price - ButterD) / sigmaD;
def zE = (price - ButterE) / sigmaE;
def zF = (price - ButterF) / sigmaF;
def zG = (price - ButterG) / sigmaG;
def zH = (price - ButterH) / sigmaH;
def zI = (price - ButterI) / sigmaI;
def zJ = (price - ButterJ) / sigmaJ;
def zK = (price - ButterK) / sigmaK;
def Zl = (price - ButterL) / sigmaL;

def p = 0.3275911;
def a1 = 0.254829592;
def a2 = -0.284496736;
def a3 = 1.421413741;
def a4 = -1.453152027;
def a5 = 1.061405429;

def signA = If((zA < 0.0), -1, 1);
def signB = If((zB < 0.0), -1, 1);
def signC = If((zC < 0.0), -1, 1);
def signD = If((zD < 0.0), -1, 1);
def signE = If((zE < 0.0), -1, 1);
def signF = If((zF < 0.0), -1, 1);
def signG = If((zG < 0.0), -1, 1);
def signH = If((zH < 0.0), -1, 1);
def signI = If((zI < 0.0), -1, 1);
def signJ = If((zJ < 0.0), -1, 1);
def signK = If((zK < 0.0), -1, 1);
def signL = If((zL < 0.0), -1, 1);
def xA = AbsValue(zA) / Sqrt(2.0);
def xB = AbsValue(zB) / Sqrt(2.0);
def xC = AbsValue(zC) / Sqrt(2.0);
def xD = AbsValue(zD) / Sqrt(2.0);
def xE = AbsValue(zE) / Sqrt(2.0);
def xF = AbsValue(zF) / Sqrt(2.0);
def xG = AbsValue(zG) / Sqrt(2.0);
def xH = AbsValue(zH) / Sqrt(2.0);
def xI = AbsValue(zI) / Sqrt(2.0);
def xJ = AbsValue(zJ) / Sqrt(2.0);
def xK = AbsValue(zK) / Sqrt(2.0);
def xL = AbsValue(zL) / Sqrt(2.0);

def tA = 1.0 / (1.0 + p * xA);
def tB = 1.0 / (1.0 + p * xB);
def tC = 1.0 / (1.0 + p * xC);
def tD = 1.0 / (1.0 + p * xD);
def tE = 1.0 / (1.0 + p * xE);
def tF = 1.0 / (1.0 + p * xF);
def tG = 1.0 / (1.0 + p * xG);
def tH = 1.0 / (1.0 + p * xH);
def tI = 1.0 / (1.0 + p * xI);
def tJ = 1.0 / (1.0 + p * xJ);
def tK = 1.0 / (1.0 + p * xK);
def tL = 1.0 / (1.0 + p * xL);

def erfA = 1.0 - (((((a5 * tA + a4) * tA) + a3) * tA + a2) * tA + a1) * tA * Exp(-xA * xA);
def erfB = 1.0 - (((((a5 * tB + a4) * tB) + a3) * tB + a2) * tB + a1) * tB * Exp(-xB * xB);
def erfC = 1.0 - (((((a5 * tC + a4) * tC) + a3) * tC + a2) * tC + a1) * tC * Exp(-xC * xC);
def erfD = 1.0 - (((((a5 * tD + a4) * tD) + a3) * tD + a2) * tD + a1) * tD * Exp(-xD * xD);
def erfE = 1.0 - (((((a5 * tE + a4) * tE) + a3) * tE + a2) * tE + a1) * tE * Exp(-xE * xE);
def erfF = 1.0 - (((((a5 * tF + a4) * tF) + a3) * tF + a2) * tF + a1) * tF * Exp(-xF * xF);
def erfG = 1.0 - (((((a5 * tG + a4) * tG) + a3) * tG + a2) * tG + a1) * tG * Exp(-xG * xG);
def erfH = 1.0 - (((((a5 * tH + a4) * tH) + a3) * tH + a2) * tH + a1) * tH * Exp(-xH * xH);
def erfI = 1.0 - (((((a5 * tI + a4) * tI) + a3) * tI + a2) * tI + a1) * tI * Exp(-xI * xI);
def erfJ = 1.0 - (((((a5 * tJ + a4) * tJ) + a3) * tJ + a2) * tJ + a1) * tJ * Exp(-xJ * xJ);
def erfK = 1.0 - (((((a5 * tK + a4) * tK) + a3) * tK + a2) * tK + a1) * tK * Exp(-xK * xK);
def erfL = 1.0 - (((((a5 * tL + a4) * tL) + a3) * tL + a2) * tL + a1) * tL * Exp(-xL * xL);

DEF CDFA = 0.5 * (1.0 + signA * erfA);
DEF CDFB = 0.5 * (1.0 + signB * erfB);
DEF CDFC = 0.5 * (1.0 + signC * erfC);
DEF CDFD = 0.5 * (1.0 + signD * erfD);
DEF CDFE = 0.5 * (1.0 + signE * erfE);
DEF CDFF = 0.5 * (1.0 + signF * erfF);
DEF CDFG = 0.5 * (1.0 + signG * erfG);
DEF CDFH = 0.5 * (1.0 + signH * erfH);
DEF CDFI = 0.5 * (1.0 + signI * erfI);
DEF CDFJ = 0.5 * (1.0 + signJ * erfJ);
DEF CDFK = 0.5 * (1.0 + signK * erfK);
DEF CDFL = 0.5 * (1.0 + signL * erfL);

plot A1_Dot = if IsNaN(Close) then Double.NaN else 1;
A1_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A1_Dot.SetLineWeight(DotSize);
A1_Dot.AssignValueColor(if cdfA >= .5 then Color.Cyan else Color.Magenta);
plot A2_Dot = if IsNaN(Close) then Double.NaN else 2;
A2_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A2_Dot.SetLineWeight(DotSize);
A2_Dot.AssignValueColor(if cdfB >= .5 then Color.Cyan else Color.Magenta);
plot A3_Dot = if IsNaN(Close) then Double.NaN else 3;
A3_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A3_Dot.SetLineWeight(DotSize);
A3_Dot.AssignValueColor(if cdfC >= .5 then Color.Cyan else Color.Magenta);
plot A4_Dot = if IsNaN(Close) then Double.NaN else 4;
A4_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A4_Dot.SetLineWeight(DotSize);
A4_Dot.AssignValueColor(if cdfD >= .5 then Color.Cyan else Color.Magenta);
plot A5_Dot = if IsNaN(Close) then Double.NaN else 5;
A5_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A5_Dot.SetLineWeight(DotSize);
A5_Dot.AssignValueColor(if cdfE >= .5 then Color.Cyan else Color.Magenta);
plot A6_Dot = if IsNaN(Close) then Double.NaN else 6;
A6_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A6_Dot.SetLineWeight(DotSize);
A6_Dot.AssignValueColor(if cdfF >= .5 then Color.Cyan else Color.Magenta);
plot A8_Dot = if IsNaN(Close) then Double.NaN else 8;
A8_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A8_Dot.SetLineWeight(DotSize);
A8_Dot.AssignValueColor(if cdfG >= .5 then Color.Blue else Color.Red);
plot A9_Dot = if IsNaN(Close) then Double.NaN else 9;
A9_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A9_Dot.SetLineWeight(DotSize);
A9_Dot.AssignValueColor(if cdfH >= .5 then Color.Blue else Color.Red);
plot A10_Dot = if IsNaN(Close) then Double.NaN else 10;
A10_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A10_Dot.SetLineWeight(DotSize);
A10_Dot.AssignValueColor(if cdfI >= .5 then Color.Blue else Color.Red);
plot A11_Dot = if IsNaN(Close) then Double.NaN else 11;
A11_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A11_Dot.SetLineWeight(DotSize);
A11_Dot.AssignValueColor(if cdfJ >= .5 then Color.Blue else Color.Red);
plot A12_Dot = if IsNaN(Close) then Double.NaN else 12;
A12_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A12_Dot.SetLineWeight(DotSize);
A12_Dot.AssignValueColor(if cdfK >= .5 then Color.Blue else Color.Red);
plot A13_Dot = if IsNaN(Close) then Double.NaN else 13;
A13_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A13_Dot.SetLineWeight(DotSize);
A13_Dot.AssignValueColor(if cdfL >= .5 then Color.Blue else Color.Red);

AssignPriceColor(if paintbars == 1 and cdfA >= .5 then Color.Cyan else if paintbars == 1 and cdfA < .5 then Color.Magenta else if paintbars == 2 and cdfB >= .5 then Color.Cyan else if paintbars == 2 and cdfB < .5 then Color.Magenta else if paintbars == 3 and cdfC >= .5 then Color.Cyan else if paintbars == 3 and cdfC < .5 then Color.Magenta else if paintbars == 4 and cdfD >= .5 then Color.Cyan else if paintbars == 4 and cdfD < .5 then Color.Magenta else
if paintbars == 5 and cdfE >= .5 then Color.Cyan else if paintbars == 5 and cdfE < .5 then Color.Magenta else if paintbars == 6 and cdfF >= .5 then Color.Cyan else if paintbars == 6 and cdfF < .5 then Color.Magenta else if paintbars == 8 and cdfG >= .5 then Color.Blue else if paintbars == 8 and cdfG  <.5 then Color.Red else if paintbars == 9 and cdfH >= .5 then Color.Blue else if paintbars == 9 and cdfH  <.5 then Color.Red else
if paintbars == 10 and cdfI >= .5  then Color.Blue else if paintbars == 10 and cdfI < .5 then Color.Red else if paintbars == 11 and cdfJ >=.5 then Color.Blue else if paintbars == 11 and cdfJ < .5 then Color.Red else if paintbars == 12 and cdfK >= .5 then Color.Blue else if paintbars == 12 and cdfK < .5 then Color.Red else if paintbars == 13 and cdfL >= .5 then Color.Blue else if paintbars == 13 and cdfL < .5 then Color.Red else
color.Current);
 
Last edited:
When an approximation of the Cumulative Distribution Function meets a 2-Pole Butterworth Filter...WOW! Sparks begin to fly...

I've spent more time than I care to recall evaluating over 1400 individual indicators and this one has quickly risen to be amongst the top three...

Thank you @amalia and @henry1224 for sharing and providing the opportunity to reaffirm that the "Search for the Holy Grail" may very well be endlessly elusive. However, if you commit to looking for something long enough, you may not find what you want, you may actually find what you need...

Good Luck and Good Trading :cool:
 
When an approximation of the Cumulative Distribution Function meets a 2-Pole Butterworth Filter...WOW! Sparks begin to fly...

I've spent more time than I care to recall evaluating over 1400 individual indicators and this one has quickly risen to be amongst the top three...

Thank you @amalia and @henry1224 for sharing and providing the opportunity to reaffirm that the "Search for the Holy Grail" may very well be endlessly elusive. However, if you commit to looking for something long enough, you may not find what you want, you may actually find what you need...

Good Luck and Good Trading :cool:
Can you please explain, how we can use this indicator.
 
Where Amalia took a 252 period simple moving average as the base of this indicator, I used a 2 pole Butterworth filter.
The Butterworth filter is more responsive than a Simple moving average.
The CDF oscillates between 0 and 100, a user can adapt it like an RSI or Stochastic indicator.
I just wanted to know when it was above the .5 level or below the .5 level.
I then used several different lengths, 6 short term and 6 long term lengths to view bullishness and bearishness.
The fastest lengths are at the bottom and the longest is at the top.
 
Where Amalia took a 252 period simple moving average as the base of this indicator, I used a 2 pole Butterworth filter.
The Butterworth filter is more responsive than a Simple moving average.
The CDF oscillates between 0 and 100, a user can adapt it like an RSI or Stochastic indicator.
I just wanted to know when it was above the .5 level or below the .5 level.
I then used several different lengths, 6 short term and 6 long term lengths to view bullishness and bearishness.
The fastest lengths are at the bottom and the longest is at the top.
Thanks Henry for detailed explanation.
 
@amalia @henry1224 @Kitchasap : I wanted to follow up and post my thoughts on this great study/indicator...The power of this forum is derived from the collaborative efforts of its' members...From amalia's initial posting of the approximation of the Cumulative Distribution Function to henry1224's subsequent enhancement with the application of the 2-pole Butterworth filter, I thought the resulting study/indicator was very interesting, to say the least...

Admittedly, math skills are not my strong point, but visual pattern recognition is...As a result, I've taken the liberty of refining the study/indicator from the use of four colors down to two colors...This refinement helped me better see the emerging patterns...

a.png



b.png



c.png



d.png



Code:
declare lower;

input period1 = 3;
input period2 = 5;
input period3 = 8;
input period4 = 10;
input period5 = 12;
input period6 = 15;
input period7 = 30;
input period8 = 35;
input period9 = 40;
input period10 = 45;
input period11 = 50;
input period12 = 60;

input ApplyDotColoring = yes;
Input dotsize = 5;
Def price = (Open + Close)/2;

def a1A = exp(-1.414 * 3.14159 / Period1);
def b1A = 2 * a1A * Cos(1.414 * 3.14159 / Period1);
def coef2A =b1A;
def coef3A = -a1A * a1A;
def coef1A = (1 – b1A + a1A * a1A) / 4;
rec ButterA = if barNumber() < 3 then Price else coef1A * (Price + 2 * Price[1] + Price[2]) + coef2A * ButterA[1] + coef3A * ButterA[2];
def a1B = exp(-1.414 * 3.14159 / Period2);
def b1B = 2 * a1B * Cos(1.414 * 3.14159 / Period2);
def coef2B =b1B;
def coef3B = -a1B * a1B;
def coef1B = (1 – b1B + a1B * a1B) / 4;
rec ButterB = if barNumber() < 3 then Price else coef1B * (Price + 2 * Price[1] + Price[2]) + coef2B * ButterB[1] + coef3B * ButterB[2];
def a1C = exp(-1.414 * 3.14159 / Period3);
def b1C = 2 * a1C * Cos(1.414 * 3.14159 / Period3);
def coef2C =b1C;
def coef3C = -a1C * a1C;
def coef1C = (1 – b1C + a1C * a1C) / 4;
rec ButterC = if barNumber() < 3 then Price else coef1C * (Price + 2 * Price[1] + Price[2]) + coef2C * ButterC[1] + coef3C * ButterC[2];
def a1D = exp(-1.414 * 3.14159 / Period4);
def b1D = 2 * a1D * Cos(1.414 * 3.14159 / Period4);
def coef2D =b1D;
def coef3D = -a1D * a1D;
def coef1D = (1 – b1D + a1D * a1D) / 4;
rec ButterD= if barNumber() < 3 then Price else coef1D * (Price + 2 * Price[1] + Price[2]) + coef2D * ButterD[1] + coef3D * ButterD[2];
def a1E = exp(-1.414 * 3.14159 / Period5);
def b1E = 2 * a1E * Cos(1.414 * 3.14159 / Period5);
def coef2E =b1E;
def coef3E = -a1E * a1E;
def coef1E = (1 – b1E + a1E * a1E) / 4;
rec ButterE = if barNumber() < 3 then Price else coef1E * (Price + 2 * Price[1] + Price[2]) + coef2E * ButterE[1] + coef3E * ButterE[2];
def a1F = exp(-1.414 * 3.14159 / Period6);
def b1F = 2 * a1F * Cos(1.414 * 3.14159 / Period6);
def coef2F =b1F;
def coef3F = -a1F * a1F;
def coef1F = (1 – b1F + a1F * a1F) / 4;
rec ButterF = if barNumber() < 3 then Price else coef1F * (Price + 2 * Price[1] + Price[2]) + coef2F * ButterF[1] + coef3F * ButterF[2];
def a1G = exp(-1.414 * 3.14159 / Period7);
def b1G = 2 * a1G * Cos(1.414 * 3.14159 / Period7);
def coef2G =b1G;
def coef3G = -a1G * a1G;
def coef1G = (1 – b1G + a1G * a1G) / 4;
rec ButterG = if barNumber() < 3 then Price else coef1G * (Price + 2 * Price[1] + Price[2]) + coef2G * ButterG[1] + coef3G * ButterG[2];
def a1H = exp(-1.414 * 3.14159 / Period8);
def b1H = 2 * a1H * Cos(1.414 * 3.14159 / Period8);
def coef2H =b1H;
def coef3H = -a1H * a1H;
def coef1H = (1 – b1H + a1H * a1H) / 4;
rec ButterH = if barNumber() < 3 then Price else coef1H * (Price + 2 * Price[1] + Price[2]) + coef2H * ButterH[1] + coef3H * ButterH[2];
def a1I = exp(-1.414 * 3.14159 / Period9);
def b1I = 2 * a1I * Cos(1.414 * 3.14159 / Period9);
def coef2I =b1I;
def coef3I = -a1I * a1I;
def coef1I = (1 – b1I + a1I * a1I) / 4;
rec ButterI = if barNumber() < 3 then Price else coef1I * (Price + 2 * Price[1] + Price[2]) + coef2I * ButterI[1] + coef3I * ButterI[2];
def a1J = exp(-1.414 * 3.14159 / Period10);
def b1J = 2 * a1J * Cos(1.414 * 3.14159 / Period10);
def coef2J =b1J;
def coef3J = -a1J * a1J;
def coef1J = (1 – b1J + a1J * a1J) / 4;
rec ButterJ = if barNumber() < 3 then Price else coef1J * (Price + 2 * Price[1] + Price[2]) + coef2J * ButterJ[1] + coef3J * ButterJ[2];
def a1K = exp(-1.414 * 3.14159 / Period11);
def b1K = 2 * a1K * Cos(1.414 * 3.14159 / Period11);
def coef2K =b1K;
def coef3K = -a1K * a1K;
def coef1K = (1 – b1K + a1K * a1K) / 4;
rec ButterK = if barNumber() < 3 then Price else coef1K * (Price + 2 * Price[1] + Price[2]) + coef2K * ButterK[1] + coef3K * ButterK[2];
def a1L = exp(-1.414 * 3.14159 / Period12);
def b1L = 2 * a1L * Cos(1.414 * 3.14159 / Period12);
def coef2L =b1L;
def coef3L = -a1L * a1L;
def coef1L = (1 – b1L + a1L * a1L) / 4;
rec ButterL = if barNumber() < 3 then Price else coef1L * (Price + 2 * Price[1] + Price[2]) + coef2L * ButterL[1] + coef3L * ButterL[2];

def sigmaA = StDev(price, Period1);
def sigmaB = StDev(price, Period2);
def sigmaC = StDev(price, Period3);
def sigmaD = StDev(price, Period4);
def sigmaE = StDev(price, Period5);
def sigmaF = StDev(price, Period6);
def sigmaG = StDev(price, Period7);
def sigmaH = StDev(price, Period8);
def sigmaI = StDev(price, Period9);
def sigmaJ = StDev(price, Period10);
def sigmaK = StDev(price, Period11);
def sigmaL = StDev(price, Period12);

def zA = (price - ButterA) / sigmaA;
def zB = (price - ButterB) / sigmaB;
def zC = (price - ButterC) / sigmaC;
def zD = (price - ButterD) / sigmaD;
def zE = (price - ButterE) / sigmaE;
def zF = (price - ButterF) / sigmaF;
def zG = (price - ButterG) / sigmaG;
def zH = (price - ButterH) / sigmaH;
def zI = (price - ButterI) / sigmaI;
def zJ = (price - ButterJ) / sigmaJ;
def zK = (price - ButterK) / sigmaK;
def Zl = (price - ButterL) / sigmaL;

def p = 0.3275911;
def a1 = 0.254829592;
def a2 = -0.284496736;
def a3 = 1.421413741;
def a4 = -1.453152027;
def a5 = 1.061405429;

def signA = If((zA < 0.0), -1, 1);
def signB = If((zB < 0.0), -1, 1);
def signC = If((zC < 0.0), -1, 1);
def signD = If((zD < 0.0), -1, 1);
def signE = If((zE < 0.0), -1, 1);
def signF = If((zF < 0.0), -1, 1);
def signG = If((zG < 0.0), -1, 1);
def signH = If((zH < 0.0), -1, 1);
def signI = If((zI < 0.0), -1, 1);
def signJ = If((zJ < 0.0), -1, 1);
def signK = If((zK < 0.0), -1, 1);
def signL = If((zL < 0.0), -1, 1);

def xA = AbsValue(zA) / Sqrt(2.0);
def xB = AbsValue(zB) / Sqrt(2.0);
def xC = AbsValue(zC) / Sqrt(2.0);
def xD = AbsValue(zD) / Sqrt(2.0);
def xE = AbsValue(zE) / Sqrt(2.0);
def xF = AbsValue(zF) / Sqrt(2.0);
def xG = AbsValue(zG) / Sqrt(2.0);
def xH = AbsValue(zH) / Sqrt(2.0);
def xI = AbsValue(zI) / Sqrt(2.0);
def xJ = AbsValue(zJ) / Sqrt(2.0);
def xK = AbsValue(zK) / Sqrt(2.0);
def xL = AbsValue(zL) / Sqrt(2.0);

def tA = 1.0 / (1.0 + p * xA);
def tB = 1.0 / (1.0 + p * xB);
def tC = 1.0 / (1.0 + p * xC);
def tD = 1.0 / (1.0 + p * xD);
def tE = 1.0 / (1.0 + p * xE);
def tF = 1.0 / (1.0 + p * xF);
def tG = 1.0 / (1.0 + p * xG);
def tH = 1.0 / (1.0 + p * xH);
def tI = 1.0 / (1.0 + p * xI);
def tJ = 1.0 / (1.0 + p * xJ);
def tK = 1.0 / (1.0 + p * xK);
def tL = 1.0 / (1.0 + p * xL);

def erfA = 1.0 - (((((a5 * tA + a4) * tA) + a3) * tA + a2) * tA + a1) * tA * Exp(-xA * xA);
def erfB = 1.0 - (((((a5 * tB + a4) * tB) + a3) * tB + a2) * tB + a1) * tB * Exp(-xB * xB);
def erfC = 1.0 - (((((a5 * tC + a4) * tC) + a3) * tC + a2) * tC + a1) * tC * Exp(-xC * xC);
def erfD = 1.0 - (((((a5 * tD + a4) * tD) + a3) * tD + a2) * tD + a1) * tD * Exp(-xD * xD);
def erfE = 1.0 - (((((a5 * tE + a4) * tE) + a3) * tE + a2) * tE + a1) * tE * Exp(-xE * xE);
def erfF = 1.0 - (((((a5 * tF + a4) * tF) + a3) * tF + a2) * tF + a1) * tF * Exp(-xF * xF);
def erfG = 1.0 - (((((a5 * tG + a4) * tG) + a3) * tG + a2) * tG + a1) * tG * Exp(-xG * xG);
def erfH = 1.0 - (((((a5 * tH + a4) * tH) + a3) * tH + a2) * tH + a1) * tH * Exp(-xH * xH);
def erfI = 1.0 - (((((a5 * tI + a4) * tI) + a3) * tI + a2) * tI + a1) * tI * Exp(-xI * xI);
def erfJ = 1.0 - (((((a5 * tJ + a4) * tJ) + a3) * tJ + a2) * tJ + a1) * tJ * Exp(-xJ * xJ);
def erfK = 1.0 - (((((a5 * tK + a4) * tK) + a3) * tK + a2) * tK + a1) * tK * Exp(-xK * xK);
def erfL = 1.0 - (((((a5 * tL + a4) * tL) + a3) * tL + a2) * tL + a1) * tL * Exp(-xL * xL);

DEF CDFA = 0.5 * (1.0 + signA * erfA);
DEF CDFB = 0.5 * (1.0 + signB * erfB);
DEF CDFC = 0.5 * (1.0 + signC * erfC);
DEF CDFD = 0.5 * (1.0 + signD * erfD);
DEF CDFE = 0.5 * (1.0 + signE * erfE);
DEF CDFF = 0.5 * (1.0 + signF * erfF);
DEF CDFG = 0.5 * (1.0 + signG * erfG);
DEF CDFH = 0.5 * (1.0 + signH * erfH);
DEF CDFI = 0.5 * (1.0 + signI * erfI);
DEF CDFJ = 0.5 * (1.0 + signJ * erfJ);
DEF CDFK = 0.5 * (1.0 + signK * erfK);
DEF CDFL = 0.5 * (1.0 + signL * erfL);

plot A1_Dot = if IsNaN(Close) then Double.NaN else 1;
A1_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A1_Dot.SetLineWeight(DotSize);
A1_Dot.AssignValueColor(if cdfA >= .5 then Color.GREEN else Color.RED);
plot A2_Dot = if IsNaN(Close) then Double.NaN else 2;
A2_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A2_Dot.SetLineWeight(DotSize);
A2_Dot.AssignValueColor(if cdfB >= .5 then Color.GREEN else Color.RED);
plot A3_Dot = if IsNaN(Close) then Double.NaN else 3;
A3_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A3_Dot.SetLineWeight(DotSize);
A3_Dot.AssignValueColor(if cdfC >= .5 then Color.GREEN else Color.RED);
plot A4_Dot = if IsNaN(Close) then Double.NaN else 4;
A4_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A4_Dot.SetLineWeight(DotSize);
A4_Dot.AssignValueColor(if cdfD >= .5 then Color.GREEN else Color.RED);
plot A5_Dot = if IsNaN(Close) then Double.NaN else 5;
A5_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A5_Dot.SetLineWeight(DotSize);
A5_Dot.AssignValueColor(if cdfE >= .5 then Color.GREEN else Color.RED);
plot A6_Dot = if IsNaN(Close) then Double.NaN else 6;
A6_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A6_Dot.SetLineWeight(DotSize);
A6_Dot.AssignValueColor(if cdfF >= .5 then Color.GREEN else Color.RED);
plot A8_Dot = if IsNaN(Close) then Double.NaN else 8;
A8_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A8_Dot.SetLineWeight(DotSize);
A8_Dot.AssignValueColor(if cdfG >= .5 then Color.GREEN else Color.RED);
plot A9_Dot = if IsNaN(Close) then Double.NaN else 9;
A9_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A9_Dot.SetLineWeight(DotSize);
A9_Dot.AssignValueColor(if cdfH >= .5 then Color.GREEN else Color.RED);
plot A10_Dot = if IsNaN(Close) then Double.NaN else 10;
A10_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A10_Dot.SetLineWeight(DotSize);
A10_Dot.AssignValueColor(if cdfI >= .5 then Color.GREEN else Color.RED);
plot A11_Dot = if IsNaN(Close) then Double.NaN else 11;
A11_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A11_Dot.SetLineWeight(DotSize);
A11_Dot.AssignValueColor(if cdfJ >= .5 then Color.GREEN else Color.RED);
plot A12_Dot = if IsNaN(Close) then Double.NaN else 12;
A12_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A12_Dot.SetLineWeight(DotSize);
A12_Dot.AssignValueColor(if cdfK >= .5 then Color.GREEN else Color.RED);
plot A13_Dot = if IsNaN(Close) then Double.NaN else 13;
A13_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A13_Dot.SetLineWeight(DotSize);
A13_Dot.AssignValueColor(if cdfL >= .5 then Color.GREEN else Color.RED);

AssignPriceColor(
if ApplyDotColoring and cdfA >= .5 then Color.GREEN
else if ApplyDotColoring and cdfA < .5 then Color.RED
else if ApplyDotColoring and cdfB >= .5 then Color.GREEN
else if ApplyDotColoring and cdfB < .5 then Color.RED
else if ApplyDotColoring and cdfC >= .5 then Color.GREEN
else if ApplyDotColoring and cdfC < .5 then Color.RED
else if ApplyDotColoring and cdfD >= .5 then Color.GREEN
else if ApplyDotColoring and cdfD < .5 then Color.RED
else if ApplyDotColoring and cdfE >= .5 then Color.GREEN
else if ApplyDotColoring and cdfE < .5 then Color.RED
else if ApplyDotColoring and cdfF >= .5 then Color.GREEN
else if ApplyDotColoring and cdfF < .5 then Color.RED
else if ApplyDotColoring and cdfG >= .5 then Color.GREEN
else if ApplyDotColoring and cdfG  <.5 then Color.RED
else if ApplyDotColoring and cdfH >= .5 then Color.GREEN
else if ApplyDotColoring and cdfH  <.5 then Color.RED
else if ApplyDotColoring and cdfI >= .5 then Color.GREEN
else if ApplyDotColoring and cdfI < .5 then Color.RED
else if ApplyDotColoring and cdfJ >=.5 then Color.GREEN
else if ApplyDotColoring and cdfJ < .5 then Color.RED
else if ApplyDotColoring and cdfK >= .5 then Color.GREEN
else if ApplyDotColoring and cdfK < .5 then Color.RED
else if ApplyDotColoring and cdfL >= .5 then Color.GREEN
else if ApplyDotColoring and cdfL < .5 then Color.RED
else color.Current);

Hope this helps...

Good Luck and Good Trading :cool:
 
@amalia @henry1224 @Kitchasap : I wanted to follow up and post my thoughts on this great study/indicator...The power of this forum is derived from the collaborative efforts of its' members...From amalia's initial posting of the approximation of the Cumulative Distribution Function to henry1224's subsequent enhancement with the application of the 2-pole Butterworth filter, I thought the resulting study/indicator was very interesting, to say the least...

Admittedly, math skills are not my strong point, but visual pattern recognition is...As a result, I've taken the liberty of refining the study/indicator from the use of four colors down to two colors...This refinement helped me better see the emerging patterns...

a.png



b.png



c.png



d.png



Code:
declare lower;

input period1 = 3;
input period2 = 5;
input period3 = 8;
input period4 = 10;
input period5 = 12;
input period6 = 15;
input period7 = 30;
input period8 = 35;
input period9 = 40;
input period10 = 45;
input period11 = 50;
input period12 = 60;

input ApplyDotColoring = yes;
Input dotsize = 5;
Def price = (Open + Close)/2;

def a1A = exp(-1.414 * 3.14159 / Period1);
def b1A = 2 * a1A * Cos(1.414 * 3.14159 / Period1);
def coef2A =b1A;
def coef3A = -a1A * a1A;
def coef1A = (1 – b1A + a1A * a1A) / 4;
rec ButterA = if barNumber() < 3 then Price else coef1A * (Price + 2 * Price[1] + Price[2]) + coef2A * ButterA[1] + coef3A * ButterA[2];
def a1B = exp(-1.414 * 3.14159 / Period2);
def b1B = 2 * a1B * Cos(1.414 * 3.14159 / Period2);
def coef2B =b1B;
def coef3B = -a1B * a1B;
def coef1B = (1 – b1B + a1B * a1B) / 4;
rec ButterB = if barNumber() < 3 then Price else coef1B * (Price + 2 * Price[1] + Price[2]) + coef2B * ButterB[1] + coef3B * ButterB[2];
def a1C = exp(-1.414 * 3.14159 / Period3);
def b1C = 2 * a1C * Cos(1.414 * 3.14159 / Period3);
def coef2C =b1C;
def coef3C = -a1C * a1C;
def coef1C = (1 – b1C + a1C * a1C) / 4;
rec ButterC = if barNumber() < 3 then Price else coef1C * (Price + 2 * Price[1] + Price[2]) + coef2C * ButterC[1] + coef3C * ButterC[2];
def a1D = exp(-1.414 * 3.14159 / Period4);
def b1D = 2 * a1D * Cos(1.414 * 3.14159 / Period4);
def coef2D =b1D;
def coef3D = -a1D * a1D;
def coef1D = (1 – b1D + a1D * a1D) / 4;
rec ButterD= if barNumber() < 3 then Price else coef1D * (Price + 2 * Price[1] + Price[2]) + coef2D * ButterD[1] + coef3D * ButterD[2];
def a1E = exp(-1.414 * 3.14159 / Period5);
def b1E = 2 * a1E * Cos(1.414 * 3.14159 / Period5);
def coef2E =b1E;
def coef3E = -a1E * a1E;
def coef1E = (1 – b1E + a1E * a1E) / 4;
rec ButterE = if barNumber() < 3 then Price else coef1E * (Price + 2 * Price[1] + Price[2]) + coef2E * ButterE[1] + coef3E * ButterE[2];
def a1F = exp(-1.414 * 3.14159 / Period6);
def b1F = 2 * a1F * Cos(1.414 * 3.14159 / Period6);
def coef2F =b1F;
def coef3F = -a1F * a1F;
def coef1F = (1 – b1F + a1F * a1F) / 4;
rec ButterF = if barNumber() < 3 then Price else coef1F * (Price + 2 * Price[1] + Price[2]) + coef2F * ButterF[1] + coef3F * ButterF[2];
def a1G = exp(-1.414 * 3.14159 / Period7);
def b1G = 2 * a1G * Cos(1.414 * 3.14159 / Period7);
def coef2G =b1G;
def coef3G = -a1G * a1G;
def coef1G = (1 – b1G + a1G * a1G) / 4;
rec ButterG = if barNumber() < 3 then Price else coef1G * (Price + 2 * Price[1] + Price[2]) + coef2G * ButterG[1] + coef3G * ButterG[2];
def a1H = exp(-1.414 * 3.14159 / Period8);
def b1H = 2 * a1H * Cos(1.414 * 3.14159 / Period8);
def coef2H =b1H;
def coef3H = -a1H * a1H;
def coef1H = (1 – b1H + a1H * a1H) / 4;
rec ButterH = if barNumber() < 3 then Price else coef1H * (Price + 2 * Price[1] + Price[2]) + coef2H * ButterH[1] + coef3H * ButterH[2];
def a1I = exp(-1.414 * 3.14159 / Period9);
def b1I = 2 * a1I * Cos(1.414 * 3.14159 / Period9);
def coef2I =b1I;
def coef3I = -a1I * a1I;
def coef1I = (1 – b1I + a1I * a1I) / 4;
rec ButterI = if barNumber() < 3 then Price else coef1I * (Price + 2 * Price[1] + Price[2]) + coef2I * ButterI[1] + coef3I * ButterI[2];
def a1J = exp(-1.414 * 3.14159 / Period10);
def b1J = 2 * a1J * Cos(1.414 * 3.14159 / Period10);
def coef2J =b1J;
def coef3J = -a1J * a1J;
def coef1J = (1 – b1J + a1J * a1J) / 4;
rec ButterJ = if barNumber() < 3 then Price else coef1J * (Price + 2 * Price[1] + Price[2]) + coef2J * ButterJ[1] + coef3J * ButterJ[2];
def a1K = exp(-1.414 * 3.14159 / Period11);
def b1K = 2 * a1K * Cos(1.414 * 3.14159 / Period11);
def coef2K =b1K;
def coef3K = -a1K * a1K;
def coef1K = (1 – b1K + a1K * a1K) / 4;
rec ButterK = if barNumber() < 3 then Price else coef1K * (Price + 2 * Price[1] + Price[2]) + coef2K * ButterK[1] + coef3K * ButterK[2];
def a1L = exp(-1.414 * 3.14159 / Period12);
def b1L = 2 * a1L * Cos(1.414 * 3.14159 / Period12);
def coef2L =b1L;
def coef3L = -a1L * a1L;
def coef1L = (1 – b1L + a1L * a1L) / 4;
rec ButterL = if barNumber() < 3 then Price else coef1L * (Price + 2 * Price[1] + Price[2]) + coef2L * ButterL[1] + coef3L * ButterL[2];

def sigmaA = StDev(price, Period1);
def sigmaB = StDev(price, Period2);
def sigmaC = StDev(price, Period3);
def sigmaD = StDev(price, Period4);
def sigmaE = StDev(price, Period5);
def sigmaF = StDev(price, Period6);
def sigmaG = StDev(price, Period7);
def sigmaH = StDev(price, Period8);
def sigmaI = StDev(price, Period9);
def sigmaJ = StDev(price, Period10);
def sigmaK = StDev(price, Period11);
def sigmaL = StDev(price, Period12);

def zA = (price - ButterA) / sigmaA;
def zB = (price - ButterB) / sigmaB;
def zC = (price - ButterC) / sigmaC;
def zD = (price - ButterD) / sigmaD;
def zE = (price - ButterE) / sigmaE;
def zF = (price - ButterF) / sigmaF;
def zG = (price - ButterG) / sigmaG;
def zH = (price - ButterH) / sigmaH;
def zI = (price - ButterI) / sigmaI;
def zJ = (price - ButterJ) / sigmaJ;
def zK = (price - ButterK) / sigmaK;
def Zl = (price - ButterL) / sigmaL;

def p = 0.3275911;
def a1 = 0.254829592;
def a2 = -0.284496736;
def a3 = 1.421413741;
def a4 = -1.453152027;
def a5 = 1.061405429;

def signA = If((zA < 0.0), -1, 1);
def signB = If((zB < 0.0), -1, 1);
def signC = If((zC < 0.0), -1, 1);
def signD = If((zD < 0.0), -1, 1);
def signE = If((zE < 0.0), -1, 1);
def signF = If((zF < 0.0), -1, 1);
def signG = If((zG < 0.0), -1, 1);
def signH = If((zH < 0.0), -1, 1);
def signI = If((zI < 0.0), -1, 1);
def signJ = If((zJ < 0.0), -1, 1);
def signK = If((zK < 0.0), -1, 1);
def signL = If((zL < 0.0), -1, 1);

def xA = AbsValue(zA) / Sqrt(2.0);
def xB = AbsValue(zB) / Sqrt(2.0);
def xC = AbsValue(zC) / Sqrt(2.0);
def xD = AbsValue(zD) / Sqrt(2.0);
def xE = AbsValue(zE) / Sqrt(2.0);
def xF = AbsValue(zF) / Sqrt(2.0);
def xG = AbsValue(zG) / Sqrt(2.0);
def xH = AbsValue(zH) / Sqrt(2.0);
def xI = AbsValue(zI) / Sqrt(2.0);
def xJ = AbsValue(zJ) / Sqrt(2.0);
def xK = AbsValue(zK) / Sqrt(2.0);
def xL = AbsValue(zL) / Sqrt(2.0);

def tA = 1.0 / (1.0 + p * xA);
def tB = 1.0 / (1.0 + p * xB);
def tC = 1.0 / (1.0 + p * xC);
def tD = 1.0 / (1.0 + p * xD);
def tE = 1.0 / (1.0 + p * xE);
def tF = 1.0 / (1.0 + p * xF);
def tG = 1.0 / (1.0 + p * xG);
def tH = 1.0 / (1.0 + p * xH);
def tI = 1.0 / (1.0 + p * xI);
def tJ = 1.0 / (1.0 + p * xJ);
def tK = 1.0 / (1.0 + p * xK);
def tL = 1.0 / (1.0 + p * xL);

def erfA = 1.0 - (((((a5 * tA + a4) * tA) + a3) * tA + a2) * tA + a1) * tA * Exp(-xA * xA);
def erfB = 1.0 - (((((a5 * tB + a4) * tB) + a3) * tB + a2) * tB + a1) * tB * Exp(-xB * xB);
def erfC = 1.0 - (((((a5 * tC + a4) * tC) + a3) * tC + a2) * tC + a1) * tC * Exp(-xC * xC);
def erfD = 1.0 - (((((a5 * tD + a4) * tD) + a3) * tD + a2) * tD + a1) * tD * Exp(-xD * xD);
def erfE = 1.0 - (((((a5 * tE + a4) * tE) + a3) * tE + a2) * tE + a1) * tE * Exp(-xE * xE);
def erfF = 1.0 - (((((a5 * tF + a4) * tF) + a3) * tF + a2) * tF + a1) * tF * Exp(-xF * xF);
def erfG = 1.0 - (((((a5 * tG + a4) * tG) + a3) * tG + a2) * tG + a1) * tG * Exp(-xG * xG);
def erfH = 1.0 - (((((a5 * tH + a4) * tH) + a3) * tH + a2) * tH + a1) * tH * Exp(-xH * xH);
def erfI = 1.0 - (((((a5 * tI + a4) * tI) + a3) * tI + a2) * tI + a1) * tI * Exp(-xI * xI);
def erfJ = 1.0 - (((((a5 * tJ + a4) * tJ) + a3) * tJ + a2) * tJ + a1) * tJ * Exp(-xJ * xJ);
def erfK = 1.0 - (((((a5 * tK + a4) * tK) + a3) * tK + a2) * tK + a1) * tK * Exp(-xK * xK);
def erfL = 1.0 - (((((a5 * tL + a4) * tL) + a3) * tL + a2) * tL + a1) * tL * Exp(-xL * xL);

DEF CDFA = 0.5 * (1.0 + signA * erfA);
DEF CDFB = 0.5 * (1.0 + signB * erfB);
DEF CDFC = 0.5 * (1.0 + signC * erfC);
DEF CDFD = 0.5 * (1.0 + signD * erfD);
DEF CDFE = 0.5 * (1.0 + signE * erfE);
DEF CDFF = 0.5 * (1.0 + signF * erfF);
DEF CDFG = 0.5 * (1.0 + signG * erfG);
DEF CDFH = 0.5 * (1.0 + signH * erfH);
DEF CDFI = 0.5 * (1.0 + signI * erfI);
DEF CDFJ = 0.5 * (1.0 + signJ * erfJ);
DEF CDFK = 0.5 * (1.0 + signK * erfK);
DEF CDFL = 0.5 * (1.0 + signL * erfL);

plot A1_Dot = if IsNaN(Close) then Double.NaN else 1;
A1_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A1_Dot.SetLineWeight(DotSize);
A1_Dot.AssignValueColor(if cdfA >= .5 then Color.GREEN else Color.RED);
plot A2_Dot = if IsNaN(Close) then Double.NaN else 2;
A2_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A2_Dot.SetLineWeight(DotSize);
A2_Dot.AssignValueColor(if cdfB >= .5 then Color.GREEN else Color.RED);
plot A3_Dot = if IsNaN(Close) then Double.NaN else 3;
A3_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A3_Dot.SetLineWeight(DotSize);
A3_Dot.AssignValueColor(if cdfC >= .5 then Color.GREEN else Color.RED);
plot A4_Dot = if IsNaN(Close) then Double.NaN else 4;
A4_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A4_Dot.SetLineWeight(DotSize);
A4_Dot.AssignValueColor(if cdfD >= .5 then Color.GREEN else Color.RED);
plot A5_Dot = if IsNaN(Close) then Double.NaN else 5;
A5_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A5_Dot.SetLineWeight(DotSize);
A5_Dot.AssignValueColor(if cdfE >= .5 then Color.GREEN else Color.RED);
plot A6_Dot = if IsNaN(Close) then Double.NaN else 6;
A6_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A6_Dot.SetLineWeight(DotSize);
A6_Dot.AssignValueColor(if cdfF >= .5 then Color.GREEN else Color.RED);
plot A8_Dot = if IsNaN(Close) then Double.NaN else 8;
A8_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A8_Dot.SetLineWeight(DotSize);
A8_Dot.AssignValueColor(if cdfG >= .5 then Color.GREEN else Color.RED);
plot A9_Dot = if IsNaN(Close) then Double.NaN else 9;
A9_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A9_Dot.SetLineWeight(DotSize);
A9_Dot.AssignValueColor(if cdfH >= .5 then Color.GREEN else Color.RED);
plot A10_Dot = if IsNaN(Close) then Double.NaN else 10;
A10_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A10_Dot.SetLineWeight(DotSize);
A10_Dot.AssignValueColor(if cdfI >= .5 then Color.GREEN else Color.RED);
plot A11_Dot = if IsNaN(Close) then Double.NaN else 11;
A11_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A11_Dot.SetLineWeight(DotSize);
A11_Dot.AssignValueColor(if cdfJ >= .5 then Color.GREEN else Color.RED);
plot A12_Dot = if IsNaN(Close) then Double.NaN else 12;
A12_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A12_Dot.SetLineWeight(DotSize);
A12_Dot.AssignValueColor(if cdfK >= .5 then Color.GREEN else Color.RED);
plot A13_Dot = if IsNaN(Close) then Double.NaN else 13;
A13_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A13_Dot.SetLineWeight(DotSize);
A13_Dot.AssignValueColor(if cdfL >= .5 then Color.GREEN else Color.RED);

AssignPriceColor(
if ApplyDotColoring and cdfA >= .5 then Color.GREEN
else if ApplyDotColoring and cdfA < .5 then Color.RED
else if ApplyDotColoring and cdfB >= .5 then Color.GREEN
else if ApplyDotColoring and cdfB < .5 then Color.RED
else if ApplyDotColoring and cdfC >= .5 then Color.GREEN
else if ApplyDotColoring and cdfC < .5 then Color.RED
else if ApplyDotColoring and cdfD >= .5 then Color.GREEN
else if ApplyDotColoring and cdfD < .5 then Color.RED
else if ApplyDotColoring and cdfE >= .5 then Color.GREEN
else if ApplyDotColoring and cdfE < .5 then Color.RED
else if ApplyDotColoring and cdfF >= .5 then Color.GREEN
else if ApplyDotColoring and cdfF < .5 then Color.RED
else if ApplyDotColoring and cdfG >= .5 then Color.GREEN
else if ApplyDotColoring and cdfG  <.5 then Color.RED
else if ApplyDotColoring and cdfH >= .5 then Color.GREEN
else if ApplyDotColoring and cdfH  <.5 then Color.RED
else if ApplyDotColoring and cdfI >= .5 then Color.GREEN
else if ApplyDotColoring and cdfI < .5 then Color.RED
else if ApplyDotColoring and cdfJ >=.5 then Color.GREEN
else if ApplyDotColoring and cdfJ < .5 then Color.RED
else if ApplyDotColoring and cdfK >= .5 then Color.GREEN
else if ApplyDotColoring and cdfK < .5 then Color.RED
else if ApplyDotColoring and cdfL >= .5 then Color.GREEN
else if ApplyDotColoring and cdfL < .5 then Color.RED
else color.Current);

Hope this helps...

Good Luck and Good Trading :cool:
Thanks a lot for taking your time and educating me!. You deserve the best ..
 
The reason I use 4 colors{Cyan & Magenta} vs {Blue & Red}

Short term averages are Cyan = Bullish __ Magenta = Bearish
Long Term Averages are Blue = Bullish __ Red = Bearish

even though I put in a blank space between the two the colors help me define the two
 
Thanks a lot for taking your time and educating me!. You deserve the best ..

@Kitchasap : You are certainly welcome! Thank you for the kind words...Happy to help if I can...


The reason I use 4 colors{Cyan & Magenta} vs {Blue & Red}

Short term averages are Cyan = Bullish __ Magenta = Bearish
Long Term Averages are Blue = Bullish __ Red = Bearish

even though I put in a blank space between the two the colors help me define the two

@henry1224: Thank you for the additional clarification...I better understand your approach now, though I prefer the two-color method...


Good Luck and Good Trading :cool:
 
@amalia @henry1224 @Kitchasap : I wanted to follow up and post my thoughts on this great study/indicator...The power of this forum is derived from the collaborative efforts of its' members...From amalia's initial posting of the approximation of the Cumulative Distribution Function to henry1224's subsequent enhancement with the application of the 2-pole Butterworth filter, I thought the resulting study/indicator was very interesting, to say the least...

Admittedly, math skills are not my strong point, but visual pattern recognition is...As a result, I've taken the liberty of refining the study/indicator from the use of four colors down to two colors...This refinement helped me better see the emerging patterns...

a.png



b.png



c.png



d.png



Code:
declare lower;

input period1 = 3;
input period2 = 5;
input period3 = 8;
input period4 = 10;
input period5 = 12;
input period6 = 15;
input period7 = 30;
input period8 = 35;
input period9 = 40;
input period10 = 45;
input period11 = 50;
input period12 = 60;

input ApplyDotColoring = yes;
Input dotsize = 5;
Def price = (Open + Close)/2;

def a1A = exp(-1.414 * 3.14159 / Period1);
def b1A = 2 * a1A * Cos(1.414 * 3.14159 / Period1);
def coef2A =b1A;
def coef3A = -a1A * a1A;
def coef1A = (1 – b1A + a1A * a1A) / 4;
rec ButterA = if barNumber() < 3 then Price else coef1A * (Price + 2 * Price[1] + Price[2]) + coef2A * ButterA[1] + coef3A * ButterA[2];
def a1B = exp(-1.414 * 3.14159 / Period2);
def b1B = 2 * a1B * Cos(1.414 * 3.14159 / Period2);
def coef2B =b1B;
def coef3B = -a1B * a1B;
def coef1B = (1 – b1B + a1B * a1B) / 4;
rec ButterB = if barNumber() < 3 then Price else coef1B * (Price + 2 * Price[1] + Price[2]) + coef2B * ButterB[1] + coef3B * ButterB[2];
def a1C = exp(-1.414 * 3.14159 / Period3);
def b1C = 2 * a1C * Cos(1.414 * 3.14159 / Period3);
def coef2C =b1C;
def coef3C = -a1C * a1C;
def coef1C = (1 – b1C + a1C * a1C) / 4;
rec ButterC = if barNumber() < 3 then Price else coef1C * (Price + 2 * Price[1] + Price[2]) + coef2C * ButterC[1] + coef3C * ButterC[2];
def a1D = exp(-1.414 * 3.14159 / Period4);
def b1D = 2 * a1D * Cos(1.414 * 3.14159 / Period4);
def coef2D =b1D;
def coef3D = -a1D * a1D;
def coef1D = (1 – b1D + a1D * a1D) / 4;
rec ButterD= if barNumber() < 3 then Price else coef1D * (Price + 2 * Price[1] + Price[2]) + coef2D * ButterD[1] + coef3D * ButterD[2];
def a1E = exp(-1.414 * 3.14159 / Period5);
def b1E = 2 * a1E * Cos(1.414 * 3.14159 / Period5);
def coef2E =b1E;
def coef3E = -a1E * a1E;
def coef1E = (1 – b1E + a1E * a1E) / 4;
rec ButterE = if barNumber() < 3 then Price else coef1E * (Price + 2 * Price[1] + Price[2]) + coef2E * ButterE[1] + coef3E * ButterE[2];
def a1F = exp(-1.414 * 3.14159 / Period6);
def b1F = 2 * a1F * Cos(1.414 * 3.14159 / Period6);
def coef2F =b1F;
def coef3F = -a1F * a1F;
def coef1F = (1 – b1F + a1F * a1F) / 4;
rec ButterF = if barNumber() < 3 then Price else coef1F * (Price + 2 * Price[1] + Price[2]) + coef2F * ButterF[1] + coef3F * ButterF[2];
def a1G = exp(-1.414 * 3.14159 / Period7);
def b1G = 2 * a1G * Cos(1.414 * 3.14159 / Period7);
def coef2G =b1G;
def coef3G = -a1G * a1G;
def coef1G = (1 – b1G + a1G * a1G) / 4;
rec ButterG = if barNumber() < 3 then Price else coef1G * (Price + 2 * Price[1] + Price[2]) + coef2G * ButterG[1] + coef3G * ButterG[2];
def a1H = exp(-1.414 * 3.14159 / Period8);
def b1H = 2 * a1H * Cos(1.414 * 3.14159 / Period8);
def coef2H =b1H;
def coef3H = -a1H * a1H;
def coef1H = (1 – b1H + a1H * a1H) / 4;
rec ButterH = if barNumber() < 3 then Price else coef1H * (Price + 2 * Price[1] + Price[2]) + coef2H * ButterH[1] + coef3H * ButterH[2];
def a1I = exp(-1.414 * 3.14159 / Period9);
def b1I = 2 * a1I * Cos(1.414 * 3.14159 / Period9);
def coef2I =b1I;
def coef3I = -a1I * a1I;
def coef1I = (1 – b1I + a1I * a1I) / 4;
rec ButterI = if barNumber() < 3 then Price else coef1I * (Price + 2 * Price[1] + Price[2]) + coef2I * ButterI[1] + coef3I * ButterI[2];
def a1J = exp(-1.414 * 3.14159 / Period10);
def b1J = 2 * a1J * Cos(1.414 * 3.14159 / Period10);
def coef2J =b1J;
def coef3J = -a1J * a1J;
def coef1J = (1 – b1J + a1J * a1J) / 4;
rec ButterJ = if barNumber() < 3 then Price else coef1J * (Price + 2 * Price[1] + Price[2]) + coef2J * ButterJ[1] + coef3J * ButterJ[2];
def a1K = exp(-1.414 * 3.14159 / Period11);
def b1K = 2 * a1K * Cos(1.414 * 3.14159 / Period11);
def coef2K =b1K;
def coef3K = -a1K * a1K;
def coef1K = (1 – b1K + a1K * a1K) / 4;
rec ButterK = if barNumber() < 3 then Price else coef1K * (Price + 2 * Price[1] + Price[2]) + coef2K * ButterK[1] + coef3K * ButterK[2];
def a1L = exp(-1.414 * 3.14159 / Period12);
def b1L = 2 * a1L * Cos(1.414 * 3.14159 / Period12);
def coef2L =b1L;
def coef3L = -a1L * a1L;
def coef1L = (1 – b1L + a1L * a1L) / 4;
rec ButterL = if barNumber() < 3 then Price else coef1L * (Price + 2 * Price[1] + Price[2]) + coef2L * ButterL[1] + coef3L * ButterL[2];

def sigmaA = StDev(price, Period1);
def sigmaB = StDev(price, Period2);
def sigmaC = StDev(price, Period3);
def sigmaD = StDev(price, Period4);
def sigmaE = StDev(price, Period5);
def sigmaF = StDev(price, Period6);
def sigmaG = StDev(price, Period7);
def sigmaH = StDev(price, Period8);
def sigmaI = StDev(price, Period9);
def sigmaJ = StDev(price, Period10);
def sigmaK = StDev(price, Period11);
def sigmaL = StDev(price, Period12);

def zA = (price - ButterA) / sigmaA;
def zB = (price - ButterB) / sigmaB;
def zC = (price - ButterC) / sigmaC;
def zD = (price - ButterD) / sigmaD;
def zE = (price - ButterE) / sigmaE;
def zF = (price - ButterF) / sigmaF;
def zG = (price - ButterG) / sigmaG;
def zH = (price - ButterH) / sigmaH;
def zI = (price - ButterI) / sigmaI;
def zJ = (price - ButterJ) / sigmaJ;
def zK = (price - ButterK) / sigmaK;
def Zl = (price - ButterL) / sigmaL;

def p = 0.3275911;
def a1 = 0.254829592;
def a2 = -0.284496736;
def a3 = 1.421413741;
def a4 = -1.453152027;
def a5 = 1.061405429;

def signA = If((zA < 0.0), -1, 1);
def signB = If((zB < 0.0), -1, 1);
def signC = If((zC < 0.0), -1, 1);
def signD = If((zD < 0.0), -1, 1);
def signE = If((zE < 0.0), -1, 1);
def signF = If((zF < 0.0), -1, 1);
def signG = If((zG < 0.0), -1, 1);
def signH = If((zH < 0.0), -1, 1);
def signI = If((zI < 0.0), -1, 1);
def signJ = If((zJ < 0.0), -1, 1);
def signK = If((zK < 0.0), -1, 1);
def signL = If((zL < 0.0), -1, 1);

def xA = AbsValue(zA) / Sqrt(2.0);
def xB = AbsValue(zB) / Sqrt(2.0);
def xC = AbsValue(zC) / Sqrt(2.0);
def xD = AbsValue(zD) / Sqrt(2.0);
def xE = AbsValue(zE) / Sqrt(2.0);
def xF = AbsValue(zF) / Sqrt(2.0);
def xG = AbsValue(zG) / Sqrt(2.0);
def xH = AbsValue(zH) / Sqrt(2.0);
def xI = AbsValue(zI) / Sqrt(2.0);
def xJ = AbsValue(zJ) / Sqrt(2.0);
def xK = AbsValue(zK) / Sqrt(2.0);
def xL = AbsValue(zL) / Sqrt(2.0);

def tA = 1.0 / (1.0 + p * xA);
def tB = 1.0 / (1.0 + p * xB);
def tC = 1.0 / (1.0 + p * xC);
def tD = 1.0 / (1.0 + p * xD);
def tE = 1.0 / (1.0 + p * xE);
def tF = 1.0 / (1.0 + p * xF);
def tG = 1.0 / (1.0 + p * xG);
def tH = 1.0 / (1.0 + p * xH);
def tI = 1.0 / (1.0 + p * xI);
def tJ = 1.0 / (1.0 + p * xJ);
def tK = 1.0 / (1.0 + p * xK);
def tL = 1.0 / (1.0 + p * xL);

def erfA = 1.0 - (((((a5 * tA + a4) * tA) + a3) * tA + a2) * tA + a1) * tA * Exp(-xA * xA);
def erfB = 1.0 - (((((a5 * tB + a4) * tB) + a3) * tB + a2) * tB + a1) * tB * Exp(-xB * xB);
def erfC = 1.0 - (((((a5 * tC + a4) * tC) + a3) * tC + a2) * tC + a1) * tC * Exp(-xC * xC);
def erfD = 1.0 - (((((a5 * tD + a4) * tD) + a3) * tD + a2) * tD + a1) * tD * Exp(-xD * xD);
def erfE = 1.0 - (((((a5 * tE + a4) * tE) + a3) * tE + a2) * tE + a1) * tE * Exp(-xE * xE);
def erfF = 1.0 - (((((a5 * tF + a4) * tF) + a3) * tF + a2) * tF + a1) * tF * Exp(-xF * xF);
def erfG = 1.0 - (((((a5 * tG + a4) * tG) + a3) * tG + a2) * tG + a1) * tG * Exp(-xG * xG);
def erfH = 1.0 - (((((a5 * tH + a4) * tH) + a3) * tH + a2) * tH + a1) * tH * Exp(-xH * xH);
def erfI = 1.0 - (((((a5 * tI + a4) * tI) + a3) * tI + a2) * tI + a1) * tI * Exp(-xI * xI);
def erfJ = 1.0 - (((((a5 * tJ + a4) * tJ) + a3) * tJ + a2) * tJ + a1) * tJ * Exp(-xJ * xJ);
def erfK = 1.0 - (((((a5 * tK + a4) * tK) + a3) * tK + a2) * tK + a1) * tK * Exp(-xK * xK);
def erfL = 1.0 - (((((a5 * tL + a4) * tL) + a3) * tL + a2) * tL + a1) * tL * Exp(-xL * xL);

DEF CDFA = 0.5 * (1.0 + signA * erfA);
DEF CDFB = 0.5 * (1.0 + signB * erfB);
DEF CDFC = 0.5 * (1.0 + signC * erfC);
DEF CDFD = 0.5 * (1.0 + signD * erfD);
DEF CDFE = 0.5 * (1.0 + signE * erfE);
DEF CDFF = 0.5 * (1.0 + signF * erfF);
DEF CDFG = 0.5 * (1.0 + signG * erfG);
DEF CDFH = 0.5 * (1.0 + signH * erfH);
DEF CDFI = 0.5 * (1.0 + signI * erfI);
DEF CDFJ = 0.5 * (1.0 + signJ * erfJ);
DEF CDFK = 0.5 * (1.0 + signK * erfK);
DEF CDFL = 0.5 * (1.0 + signL * erfL);

plot A1_Dot = if IsNaN(Close) then Double.NaN else 1;
A1_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A1_Dot.SetLineWeight(DotSize);
A1_Dot.AssignValueColor(if cdfA >= .5 then Color.GREEN else Color.RED);
plot A2_Dot = if IsNaN(Close) then Double.NaN else 2;
A2_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A2_Dot.SetLineWeight(DotSize);
A2_Dot.AssignValueColor(if cdfB >= .5 then Color.GREEN else Color.RED);
plot A3_Dot = if IsNaN(Close) then Double.NaN else 3;
A3_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A3_Dot.SetLineWeight(DotSize);
A3_Dot.AssignValueColor(if cdfC >= .5 then Color.GREEN else Color.RED);
plot A4_Dot = if IsNaN(Close) then Double.NaN else 4;
A4_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A4_Dot.SetLineWeight(DotSize);
A4_Dot.AssignValueColor(if cdfD >= .5 then Color.GREEN else Color.RED);
plot A5_Dot = if IsNaN(Close) then Double.NaN else 5;
A5_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A5_Dot.SetLineWeight(DotSize);
A5_Dot.AssignValueColor(if cdfE >= .5 then Color.GREEN else Color.RED);
plot A6_Dot = if IsNaN(Close) then Double.NaN else 6;
A6_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A6_Dot.SetLineWeight(DotSize);
A6_Dot.AssignValueColor(if cdfF >= .5 then Color.GREEN else Color.RED);
plot A8_Dot = if IsNaN(Close) then Double.NaN else 8;
A8_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A8_Dot.SetLineWeight(DotSize);
A8_Dot.AssignValueColor(if cdfG >= .5 then Color.GREEN else Color.RED);
plot A9_Dot = if IsNaN(Close) then Double.NaN else 9;
A9_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A9_Dot.SetLineWeight(DotSize);
A9_Dot.AssignValueColor(if cdfH >= .5 then Color.GREEN else Color.RED);
plot A10_Dot = if IsNaN(Close) then Double.NaN else 10;
A10_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A10_Dot.SetLineWeight(DotSize);
A10_Dot.AssignValueColor(if cdfI >= .5 then Color.GREEN else Color.RED);
plot A11_Dot = if IsNaN(Close) then Double.NaN else 11;
A11_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A11_Dot.SetLineWeight(DotSize);
A11_Dot.AssignValueColor(if cdfJ >= .5 then Color.GREEN else Color.RED);
plot A12_Dot = if IsNaN(Close) then Double.NaN else 12;
A12_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A12_Dot.SetLineWeight(DotSize);
A12_Dot.AssignValueColor(if cdfK >= .5 then Color.GREEN else Color.RED);
plot A13_Dot = if IsNaN(Close) then Double.NaN else 13;
A13_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A13_Dot.SetLineWeight(DotSize);
A13_Dot.AssignValueColor(if cdfL >= .5 then Color.GREEN else Color.RED);

AssignPriceColor(
if ApplyDotColoring and cdfA >= .5 then Color.GREEN
else if ApplyDotColoring and cdfA < .5 then Color.RED
else if ApplyDotColoring and cdfB >= .5 then Color.GREEN
else if ApplyDotColoring and cdfB < .5 then Color.RED
else if ApplyDotColoring and cdfC >= .5 then Color.GREEN
else if ApplyDotColoring and cdfC < .5 then Color.RED
else if ApplyDotColoring and cdfD >= .5 then Color.GREEN
else if ApplyDotColoring and cdfD < .5 then Color.RED
else if ApplyDotColoring and cdfE >= .5 then Color.GREEN
else if ApplyDotColoring and cdfE < .5 then Color.RED
else if ApplyDotColoring and cdfF >= .5 then Color.GREEN
else if ApplyDotColoring and cdfF < .5 then Color.RED
else if ApplyDotColoring and cdfG >= .5 then Color.GREEN
else if ApplyDotColoring and cdfG  <.5 then Color.RED
else if ApplyDotColoring and cdfH >= .5 then Color.GREEN
else if ApplyDotColoring and cdfH  <.5 then Color.RED
else if ApplyDotColoring and cdfI >= .5 then Color.GREEN
else if ApplyDotColoring and cdfI < .5 then Color.RED
else if ApplyDotColoring and cdfJ >=.5 then Color.GREEN
else if ApplyDotColoring and cdfJ < .5 then Color.RED
else if ApplyDotColoring and cdfK >= .5 then Color.GREEN
else if ApplyDotColoring and cdfK < .5 then Color.RED
else if ApplyDotColoring and cdfL >= .5 then Color.GREEN
else if ApplyDotColoring and cdfL < .5 then Color.RED
else color.Current);

Hope this helps...

Good Luck and Good Trading :cool:
This indicator is fantastic. Much obliged for sharing with us. What time frame is ideal for this? (At the moment, I am trading the triple leveraged elf's on a 1-minute time frame). Thank you
 
This indicator is fantastic. Much obliged for sharing with us...

@Santhosh : I agree with you...You are certainly welcome...All the credit goes to @amalia and @henry1224...

What time frame is ideal for this? (At the moment, I am trading the triple leveraged elf's on a 1-minute time frame). Thank you

In my opinion, the best time-frame is the one you're most comfortable trading...If it's the 1 minute then that sounds good to me...On that note, you mentioned trading 3x ETFs, I think you might want to take a look at trading futures...

Where you currently have to bounce back and forth between, for example, TQQQ and SQQQ, in order to achieve directional benefits...With the Futures, you only need to work on one chart and you have different levels of leverage...For instance, 1 point of movement on /NQ (Nasdaq 100) equals $20.00 and the micro version, /MNQ, equals $2.00 for every 1 point of movement...

It is also important to mention that you need to have a margin account and you might need to get approval from your broker to trade futures...

The following link provides a good overview, if you think you might be interested:

https://www.brianwweber.com/blog/2019/4/12/how-to-get-started-trading-futures

Please note: Trading futures involves the risk of loss. Please consider carefully whether futures are appropriate to your financial situation. Only risk capital should be used when trading futures. You could lose more than their initial investment. Past results are not necessarily indicative of future results. The risk of loss in trading can be substantial, carefully consider the inherent risks of such an investment in light of your financial condition.

Hope this helps...

Good Luck and Good Trading :cool:
 
Here's a mobile-friendly version of some of the code above. May or may not get the colors right, probably will not plot as dots automatically. not sure why ToS Mobile has issues with these things.

-mashume

Code:
declare lower;

input period1 = 3;
input period2 = 5;
input period3 = 8;
input period4 = 10;
input period5 = 12;
input period6 = 15;
input period7 = 30;
input period8 = 35;
input period9 = 40;
input period10 = 45;
input period11 = 50;
input period12 = 60;

input ApplyDotColoring = yes;
Input dotsize = 5;

input upper_threshold = 0.8;
input lower_threshold = 0.2;

Def price = (Open + Close)/2;

def a1A = exp(-1.414 * 3.14159 / Period1);
def b1A = 2 * a1A * Cos(1.414 * 3.14159 / Period1);
def coef2A =b1A;
def coef3A = -a1A * a1A;
def coef1A = (1 – b1A + a1A * a1A) / 4;
rec ButterA = if barNumber() < 3 then Price else coef1A * (Price + 2 * Price[1] + Price[2]) + coef2A * ButterA[1] + coef3A * ButterA[2];
def a1B = exp(-1.414 * 3.14159 / Period2);
def b1B = 2 * a1B * Cos(1.414 * 3.14159 / Period2);
def coef2B =b1B;
def coef3B = -a1B * a1B;
def coef1B = (1 – b1B + a1B * a1B) / 4;
rec ButterB = if barNumber() < 3 then Price else coef1B * (Price + 2 * Price[1] + Price[2]) + coef2B * ButterB[1] + coef3B * ButterB[2];
def a1C = exp(-1.414 * 3.14159 / Period3);
def b1C = 2 * a1C * Cos(1.414 * 3.14159 / Period3);
def coef2C =b1C;
def coef3C = -a1C * a1C;
def coef1C = (1 – b1C + a1C * a1C) / 4;
rec ButterC = if barNumber() < 3 then Price else coef1C * (Price + 2 * Price[1] + Price[2]) + coef2C * ButterC[1] + coef3C * ButterC[2];
def a1D = exp(-1.414 * 3.14159 / Period4);
def b1D = 2 * a1D * Cos(1.414 * 3.14159 / Period4);
def coef2D =b1D;
def coef3D = -a1D * a1D;
def coef1D = (1 – b1D + a1D * a1D) / 4;
rec ButterD= if barNumber() < 3 then Price else coef1D * (Price + 2 * Price[1] + Price[2]) + coef2D * ButterD[1] + coef3D * ButterD[2];
def a1E = exp(-1.414 * 3.14159 / Period5);
def b1E = 2 * a1E * Cos(1.414 * 3.14159 / Period5);
def coef2E =b1E;
def coef3E = -a1E * a1E;
def coef1E = (1 – b1E + a1E * a1E) / 4;
rec ButterE = if barNumber() < 3 then Price else coef1E * (Price + 2 * Price[1] + Price[2]) + coef2E * ButterE[1] + coef3E * ButterE[2];
def a1F = exp(-1.414 * 3.14159 / Period6);
def b1F = 2 * a1F * Cos(1.414 * 3.14159 / Period6);
def coef2F =b1F;
def coef3F = -a1F * a1F;
def coef1F = (1 – b1F + a1F * a1F) / 4;
rec ButterF = if barNumber() < 3 then Price else coef1F * (Price + 2 * Price[1] + Price[2]) + coef2F * ButterF[1] + coef3F * ButterF[2];
def a1G = exp(-1.414 * 3.14159 / Period7);
def b1G = 2 * a1G * Cos(1.414 * 3.14159 / Period7);
def coef2G =b1G;
def coef3G = -a1G * a1G;
def coef1G = (1 – b1G + a1G * a1G) / 4;
rec ButterG = if barNumber() < 3 then Price else coef1G * (Price + 2 * Price[1] + Price[2]) + coef2G * ButterG[1] + coef3G * ButterG[2];
def a1H = exp(-1.414 * 3.14159 / Period8);
def b1H = 2 * a1H * Cos(1.414 * 3.14159 / Period8);
def coef2H =b1H;
def coef3H = -a1H * a1H;
def coef1H = (1 – b1H + a1H * a1H) / 4;
rec ButterH = if barNumber() < 3 then Price else coef1H * (Price + 2 * Price[1] + Price[2]) + coef2H * ButterH[1] + coef3H * ButterH[2];
def a1I = exp(-1.414 * 3.14159 / Period9);
def b1I = 2 * a1I * Cos(1.414 * 3.14159 / Period9);
def coef2I =b1I;
def coef3I = -a1I * a1I;
def coef1I = (1 – b1I + a1I * a1I) / 4;
rec ButterI = if barNumber() < 3 then Price else coef1I * (Price + 2 * Price[1] + Price[2]) + coef2I * ButterI[1] + coef3I * ButterI[2];
def a1J = exp(-1.414 * 3.14159 / Period10);
def b1J = 2 * a1J * Cos(1.414 * 3.14159 / Period10);
def coef2J =b1J;
def coef3J = -a1J * a1J;
def coef1J = (1 – b1J + a1J * a1J) / 4;
rec ButterJ = if barNumber() < 3 then Price else coef1J * (Price + 2 * Price[1] + Price[2]) + coef2J * ButterJ[1] + coef3J * ButterJ[2];
def a1K = exp(-1.414 * 3.14159 / Period11);
def b1K = 2 * a1K * Cos(1.414 * 3.14159 / Period11);
def coef2K =b1K;
def coef3K = -a1K * a1K;
def coef1K = (1 – b1K + a1K * a1K) / 4;
rec ButterK = if barNumber() < 3 then Price else coef1K * (Price + 2 * Price[1] + Price[2]) + coef2K * ButterK[1] + coef3K * ButterK[2];
def a1L = exp(-1.414 * 3.14159 / Period12);
def b1L = 2 * a1L * Cos(1.414 * 3.14159 / Period12);
def coef2L =b1L;
def coef3L = -a1L * a1L;
def coef1L = (1 – b1L + a1L * a1L) / 4;
rec ButterL = if barNumber() < 3 then Price else coef1L * (Price + 2 * Price[1] + Price[2]) + coef2L * ButterL[1] + coef3L * ButterL[2];

def sigmaA = StDev(price, Period1);
def sigmaB = StDev(price, Period2);
def sigmaC = StDev(price, Period3);
def sigmaD = StDev(price, Period4);
def sigmaE = StDev(price, Period5);
def sigmaF = StDev(price, Period6);
def sigmaG = StDev(price, Period7);
def sigmaH = StDev(price, Period8);
def sigmaI = StDev(price, Period9);
def sigmaJ = StDev(price, Period10);
def sigmaK = StDev(price, Period11);
def sigmaL = StDev(price, Period12);

def zA = (price - ButterA) / sigmaA;
def zB = (price - ButterB) / sigmaB;
def zC = (price - ButterC) / sigmaC;
def zD = (price - ButterD) / sigmaD;
def zE = (price - ButterE) / sigmaE;
def zF = (price - ButterF) / sigmaF;
def zG = (price - ButterG) / sigmaG;
def zH = (price - ButterH) / sigmaH;
def zI = (price - ButterI) / sigmaI;
def zJ = (price - ButterJ) / sigmaJ;
def zK = (price - ButterK) / sigmaK;
def Zl = (price - ButterL) / sigmaL;

def p = 0.3275911;
def a1 = 0.254829592;
def a2 = -0.284496736;
def a3 = 1.421413741;
def a4 = -1.453152027;
def a5 = 1.061405429;

def signA = If((zA < 0.0), -1, 1);
def signB = If((zB < 0.0), -1, 1);
def signC = If((zC < 0.0), -1, 1);
def signD = If((zD < 0.0), -1, 1);
def signE = If((zE < 0.0), -1, 1);
def signF = If((zF < 0.0), -1, 1);
def signG = If((zG < 0.0), -1, 1);
def signH = If((zH < 0.0), -1, 1);
def signI = If((zI < 0.0), -1, 1);
def signJ = If((zJ < 0.0), -1, 1);
def signK = If((zK < 0.0), -1, 1);
def signL = If((zL < 0.0), -1, 1);

def xA = AbsValue(zA) / Sqrt(2.0);
def xB = AbsValue(zB) / Sqrt(2.0);
def xC = AbsValue(zC) / Sqrt(2.0);
def xD = AbsValue(zD) / Sqrt(2.0);
def xE = AbsValue(zE) / Sqrt(2.0);
def xF = AbsValue(zF) / Sqrt(2.0);
def xG = AbsValue(zG) / Sqrt(2.0);
def xH = AbsValue(zH) / Sqrt(2.0);
def xI = AbsValue(zI) / Sqrt(2.0);
def xJ = AbsValue(zJ) / Sqrt(2.0);
def xK = AbsValue(zK) / Sqrt(2.0);
def xL = AbsValue(zL) / Sqrt(2.0);

def tA = 1.0 / (1.0 + p * xA);
def tB = 1.0 / (1.0 + p * xB);
def tC = 1.0 / (1.0 + p * xC);
def tD = 1.0 / (1.0 + p * xD);
def tE = 1.0 / (1.0 + p * xE);
def tF = 1.0 / (1.0 + p * xF);
def tG = 1.0 / (1.0 + p * xG);
def tH = 1.0 / (1.0 + p * xH);
def tI = 1.0 / (1.0 + p * xI);
def tJ = 1.0 / (1.0 + p * xJ);
def tK = 1.0 / (1.0 + p * xK);
def tL = 1.0 / (1.0 + p * xL);

def erfA = 1.0 - (((((a5 * tA + a4) * tA) + a3) * tA + a2) * tA + a1) * tA * Exp(-xA * xA);
def erfB = 1.0 - (((((a5 * tB + a4) * tB) + a3) * tB + a2) * tB + a1) * tB * Exp(-xB * xB);
def erfC = 1.0 - (((((a5 * tC + a4) * tC) + a3) * tC + a2) * tC + a1) * tC * Exp(-xC * xC);
def erfD = 1.0 - (((((a5 * tD + a4) * tD) + a3) * tD + a2) * tD + a1) * tD * Exp(-xD * xD);
def erfE = 1.0 - (((((a5 * tE + a4) * tE) + a3) * tE + a2) * tE + a1) * tE * Exp(-xE * xE);
def erfF = 1.0 - (((((a5 * tF + a4) * tF) + a3) * tF + a2) * tF + a1) * tF * Exp(-xF * xF);
def erfG = 1.0 - (((((a5 * tG + a4) * tG) + a3) * tG + a2) * tG + a1) * tG * Exp(-xG * xG);
def erfH = 1.0 - (((((a5 * tH + a4) * tH) + a3) * tH + a2) * tH + a1) * tH * Exp(-xH * xH);
def erfI = 1.0 - (((((a5 * tI + a4) * tI) + a3) * tI + a2) * tI + a1) * tI * Exp(-xI * xI);
def erfJ = 1.0 - (((((a5 * tJ + a4) * tJ) + a3) * tJ + a2) * tJ + a1) * tJ * Exp(-xJ * xJ);
def erfK = 1.0 - (((((a5 * tK + a4) * tK) + a3) * tK + a2) * tK + a1) * tK * Exp(-xK * xK);
def erfL = 1.0 - (((((a5 * tL + a4) * tL) + a3) * tL + a2) * tL + a1) * tL * Exp(-xL * xL);

DEF CDFA = 0.5 * (1.0 + signA * erfA);
DEF CDFB = 0.5 * (1.0 + signB * erfB);
DEF CDFC = 0.5 * (1.0 + signC * erfC);
DEF CDFD = 0.5 * (1.0 + signD * erfD);
DEF CDFE = 0.5 * (1.0 + signE * erfE);
DEF CDFF = 0.5 * (1.0 + signF * erfF);
DEF CDFG = 0.5 * (1.0 + signG * erfG);
DEF CDFH = 0.5 * (1.0 + signH * erfH);
DEF CDFI = 0.5 * (1.0 + signI * erfI);
DEF CDFJ = 0.5 * (1.0 + signJ * erfJ);
DEF CDFK = 0.5 * (1.0 + signK * erfK);
DEF CDFL = 0.5 * (1.0 + signL * erfL);

plot A1_Dot = if cdfA < 0.5 OR IsNaN(Close) then Double.NaN else 1;
A1_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A1_Dot.SetLineWeight(DotSize);
A1_Dot.SetDefaultColor(color.green);
plot A2_Dot = if cdfB < 0.5 OR IsNaN(Close) then Double.NaN else 2;
A2_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A2_Dot.SetLineWeight(DotSize);
A2_Dot.SetDefaultColor(color.green);
plot A3_Dot = if cdfB < 0.5 OR IsNaN(Close) then Double.NaN else 3;
A3_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A3_Dot.SetLineWeight(DotSize);
A3_Dot.SetDefaultColor(color.green);
plot A4_Dot = if cdfD < 0.5 OR IsNaN(Close) then Double.NaN else 4;
A4_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A4_Dot.SetLineWeight(DotSize);
A4_Dot.SetDefaultColor(color.green);
plot A5_Dot = if cdfE < 0.5 OR IsNaN(Close) then Double.NaN else 5;
A5_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A5_Dot.SetLineWeight(DotSize);
A5_Dot.SetDefaultColor(color.green);
plot A6_Dot = if cdfF < 0.5 OR IsNaN(Close) then Double.NaN else 6;
A6_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A6_Dot.SetLineWeight(DotSize);
A6_Dot.SetDefaultColor(color.green);
plot A8_Dot = if cdfG < 0.5 OR IsNaN(Close) then Double.NaN else 8;
A8_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A8_Dot.SetLineWeight(DotSize);
A8_Dot.SetDefaultColor(color.green);
plot A9_Dot = if cdfH < 0.5 OR IsNaN(Close) then Double.NaN else 9;
A9_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A9_Dot.SetLineWeight(DotSize);
A9_Dot.SetDefaultColor(color.green);
plot A10_Dot = if cdfI < 0.5 OR IsNaN(Close) then Double.NaN else 10;
A10_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A10_Dot.SetLineWeight(DotSize);
A10_Dot.SetDefaultColor(color.green);
plot A11_Dot = if cdfJ < 0.5 OR IsNaN(Close) then Double.NaN else 11;
A11_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A11_Dot.SetLineWeight(DotSize);
A11_Dot.SetDefaultColor(color.green);
plot A12_Dot = if cdfK < 0.5 OR IsNaN(Close) then Double.NaN else 12;
A12_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A12_Dot.SetLineWeight(DotSize);
A12_Dot.SetDefaultColor(color.green);
plot A13_Dot = if cdfL < 0.5 OR IsNaN(Close) then Double.NaN else 13;
A13_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A13_Dot.SetLineWeight(DotSize);
A13_Dot.SetDefaultColor(color.green);


plot A1_Dot_dn = if cdfA >= 0.5 OR IsNaN(Close) then Double.NaN else 1;
A1_Dot_dn.SetPaintingStrategy(PaintingStrategy.POINTS);
A1_Dot_dn.SetLineWeight(DotSize);
A1_Dot_dn.setDefaultColor(color.red);
plot A2_Dot_dn = if cdfB >= 0.5 OR IsNaN(Close) then Double.NaN else 2;
A2_Dot_dn.SetPaintingStrategy(PaintingStrategy.POINTS);
A2_Dot_dn.SetLineWeight(DotSize);
A2_Dot_dn.setDefaultColor(color.red);
plot A3_Dot_dn = if cdfB >= 0.5 OR IsNaN(Close) then Double.NaN else 3;
A3_Dot_dn.SetPaintingStrategy(PaintingStrategy.POINTS);
A3_Dot_dn.SetLineWeight(DotSize);
A3_Dot_dn.setDefaultColor(color.red);
plot A4_Dot_dn = if cdfD >= 0.5 OR IsNaN(Close) then Double.NaN else 4;
A4_Dot_dn.SetPaintingStrategy(PaintingStrategy.POINTS);
A4_Dot_dn.SetLineWeight(DotSize);
A4_Dot_dn.setDefaultColor(color.red);
plot A5_Dot_dn = if cdfE >= 0.5 OR IsNaN(Close) then Double.NaN else 5;
A5_Dot_dn.SetPaintingStrategy(PaintingStrategy.POINTS);
A5_Dot_dn.SetLineWeight(DotSize);
A5_Dot_dn.setDefaultColor(color.red);
plot A6_Dot_dn = if cdfF >= 0.5 OR IsNaN(Close) then Double.NaN else 6;
A6_Dot_dn.SetPaintingStrategy(PaintingStrategy.POINTS);
A6_Dot_dn.SetLineWeight(DotSize);
A6_Dot_dn.setDefaultColor(color.red);
plot A8_Dot_dn = if cdfG >= 0.5 OR IsNaN(Close) then Double.NaN else 8;
A8_Dot_dn.SetPaintingStrategy(PaintingStrategy.POINTS);
A8_Dot_dn.SetLineWeight(DotSize);
A8_Dot_dn.setDefaultColor(color.red);
plot A9_Dot_dn = if cdfH >= 0.5 OR IsNaN(Close) then Double.NaN else 9;
A9_Dot_dn.SetPaintingStrategy(PaintingStrategy.POINTS);
A9_Dot_dn.SetLineWeight(DotSize);
A9_Dot_dn.setDefaultColor(color.red);
plot A10_Dot_dn = if cdfI >= 0.5 OR IsNaN(Close) then Double.NaN else 10;
A10_Dot_dn.SetPaintingStrategy(PaintingStrategy.POINTS);
A10_Dot_dn.SetLineWeight(DotSize);
A10_Dot_dn.setDefaultColor(color.red);
plot A11_Dot_dn = if cdfJ >= 0.5 OR IsNaN(Close) then Double.NaN else 11;
A11_Dot_dn.SetPaintingStrategy(PaintingStrategy.POINTS);
A11_Dot_dn.SetLineWeight(DotSize);
A11_Dot_dn.setDefaultColor(color.red);
plot A12_Dot_dn = if cdfK >= 0.5 OR IsNaN(Close) then Double.NaN else 12;
A12_Dot_dn.SetPaintingStrategy(PaintingStrategy.POINTS);
A12_Dot_dn.SetLineWeight(DotSize);
A12_Dot_dn.setDefaultColor(color.red);
plot A13_Dot_dn = if cdfL >= 0.5 OR IsNaN(Close) then Double.NaN else 13;
A13_Dot_dn.SetPaintingStrategy(PaintingStrategy.POINTS);
A13_Dot_dn.SetLineWeight(DotSize);
A13_Dot_dn.setDefaultColor(color.red);
 

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
133 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