• Get $40 off VIP by signing up for a free account! Sign Up

JNSAR-DP for ThinkorSwim

petergluis

Active member
I convert JNSAR-DP for ThinkorSwim, and add color changes to follow trend changes easily. Enjoy your successful tranding.
https://www.tradingview.com/script/lEuCw5DS-JNSAR-DP/

Ruby:
# © deepphalke
#https://www.tradingview.com/script/lEuCw5DS-JNSAR-DP/
def h = high;
def l = low;
def c = close;
def ema1 = ExpAverage(h, 5);
def ema2 = ExpAverage(l, 5);
def ema3= ExpAverage(c, 5);
def avg = (ema1+ema2+ema3+ExpAverage(h[1], 5)+ExpAverage(l[1], 5)+ExpAverage(c[1], 5)+ExpAverage(h[2], 5)+ExpAverage(l[2], 5)+ExpAverage(c[2], 5)+ExpAverage(h[3], 5)+ExpAverage(l[3], 5)+ExpAverage(c[3], 5)+ExpAverage(h[4], 5)+ExpAverage(l[4], 5)+ExpAverage(c[4], 5))/15;


plot Upperband = ema1;
Upperband.DefineColor("UpTrend", Color.GREEN);
Upperband.DefineColor("DownTrend", Color.RED);
Upperband.SetLineWeight(1);
Upperband.SetPaintingStrategy(PaintingStrategy.LINE);
Upperband.SetStyle(Curve.FIRM);
Upperband.AssignValueColor(if Upperband > Upperband [1] then Upperband.Color("UpTrend") else Upperband.Color("DownTrend"));
plot lowerband = ema2;
lowerband.DefineColor("UpTrend", Color.GREEN);
lowerband.DefineColor("DownTrend", Color.RED);
lowerband.SetLineWeight(1);
lowerband.SetPaintingStrategy(PaintingStrategy.LINE);
lowerband.SetStyle(Curve.FIRM);
lowerband.AssignValueColor(if lowerband  > lowerband  [1] then lowerband.Color("UpTrend") else lowerband.Color("DownTrend"));
Plot midline = ema3;
midline.DefineColor("UpTrend", Color.GREEN);
midline.DefineColor("DownTrend", Color.RED);
midline.SetLineWeight(1);
midline.SetPaintingStrategy(PaintingStrategy.LINE);
midline.SetStyle(Curve.FIRM);
midline.AssignValueColor(if midline >midline [1] then midline.Color("UpTrend") else midline.Color("DownTrend"));
input fill = yes;
def nan  =  Double.NaN;
plot LineAvg = avg;
LineAvg.DefineColor("UpTrend", Color.GREEN);
LineAvg.DefineColor("DownTrend", Color.RED);
LineAvg.SetLineWeight(3);
LineAvg.SetPaintingStrategy(PaintingStrategy.LINE);
LineAvg.SetStyle(Curve.FIRM);
LineAvg.AssignValueColor(if LineAvg  > LineAvg [1] then LineAvg.Color("UpTrend") else LineAvg.Color("DownTrend"));

def a = (UpperBand > UpperBand[1] and Midline > Midline[1]);
def b = (UpperBand < UpperBand[1] and LowerBand < LowerBand[1]);
def c1 = (UpperBand > UpperBand[1] and Midline > Midline[1]);
def d = (UpperBand < UpperBand[1] and midline < midline[1]);
def e = average(close)>midline;
def f = midline<average(close);

def Chg      =   If(a, 1, If(b, -1, 0));
def Hold     =   CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
def Chg_a      =   If((c1 or e), 1, If((d or f), -1, 0));
def Hold_a     =   CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
def LBUp     =   if fill and Hold[0] == 1 then lowerBand else nan;
def UBUp     =   if fill and Hold[0] == 1 then upperband else nan;
def LBDn     =   if fill and Hold[0] == -1 then lowerband else nan;
def UBDn     =   if fill and Hold[0] == -1 then upperband else nan;
def MBUP     =   if fill and Hold[0] == 1 then midline else nan;
def MBDn     =   if fill and Hold[0] == -1 then Midline else nan;

DefineGlobalColor("Cloud Up", Color.red);
DefineGlobalColor("Cloud_Up", Color.downtick);
DefineGlobalColor("Cloud_Dn", Color.light_green);
DefineGlobalColor("Cloud Dn", Color.cyan);
AddCloud(LBUp, UBUp, GlobalColor("Cloud Up"), GlobalColor("Cloud Dn"));
AddCloud(LBDn, UBDn, GlobalColor("Cloud Dn"), GlobalColor("Cloud Up"));
AddCloud(MBUp, UBUp, GlobalColor("Cloud_Up"), GlobalColor("Cloud_Dn"));
AddCloud(MBDn, UBDn, GlobalColor("Cloud_Dn"), GlobalColor("Cloud_Up"));
 
Last edited:

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

I used Hull moving average instead of exponential average to enhance the indicator sensitivity to the trend changes.
Ruby:
# © deepphalke
#https://www.tradingview.com/script/lEuCw5DS-JNSAR-DP/
#Peter Luis conversion
# April 24, 2022

def h = high;
def l = low;
def c = close;

def Hull1 = HullMovingAvg(h, 5);
def Hull2 = HullMovingAvg(l, 5);
def Hull3 = HullMovingAvg(c, 5);
def avg = (Hull1+ Hull2 + Hull3 + HullMovingAvg(h[1], 5)+ HullMovingAvg(l[1], 5)+ HullMovingAvg(c[1], 5)+ HullMovingAvg(h[2], 5)+ HullMovingAvg(l[2], 5)+ HullMovingAvg(c[2], 5)+ HullMovingAvg(h[3], 5)+ HullMovingAvg(l[3], 5)+ HullMovingAvg(c[3], 5)+ HullMovingAvg(h[4], 5)+ HullMovingAvg(l[4], 5)+ HullMovingAvg(c[4], 5))/15;

plot Upperband = hull1;
Upperband.DefineColor("UpTrend", Color.GREEN);
Upperband.DefineColor("DownTrend", Color.RED);
Upperband.SetLineWeight(1);
Upperband.SetPaintingStrategy(PaintingStrategy.LINE);
Upperband.SetStyle(Curve.FIRM);
Upperband.AssignValueColor(if Upperband > Upperband [1] then Upperband.Color("UpTrend") else Upperband.Color("DownTrend"));
plot lowerband = Hull2;
lowerband.DefineColor("UpTrend", Color.GREEN);
lowerband.DefineColor("DownTrend", Color.RED);
lowerband.SetLineWeight(1);
lowerband.SetPaintingStrategy(PaintingStrategy.LINE);
lowerband.SetStyle(Curve.FIRM);
lowerband.AssignValueColor(if lowerband  > lowerband  [1] then lowerband.Color("UpTrend") else lowerband.Color("DownTrend"));
Plot midline = hull3;
midline.DefineColor("UpTrend", Color.GREEN);
midline.DefineColor("DownTrend", Color.RED);
midline.SetLineWeight(1);
midline.SetPaintingStrategy(PaintingStrategy.LINE);
midline.SetStyle(Curve.FIRM);
midline.AssignValueColor(if midline >midline [1] then midline.Color("UpTrend") else midline.Color("DownTrend"));
input fill = yes;
def nan  =  Double.NaN;
plot LineAvg = avg;
LineAvg.DefineColor("UpTrend", Color.GREEN);
LineAvg.DefineColor("DownTrend", Color.RED);
LineAvg.SetLineWeight(3);
LineAvg.SetPaintingStrategy(PaintingStrategy.LINE);
LineAvg.SetStyle(Curve.FIRM);
LineAvg.AssignValueColor(if LineAvg  > LineAvg [1] then LineAvg.Color("UpTrend") else LineAvg.Color("DownTrend"));

def a = (UpperBand > UpperBand[1] and Midline > Midline[1]);
def b = (UpperBand < UpperBand[1] and LowerBand < LowerBand[1]);
def c1 = (UpperBand > UpperBand[1] and Midline > Midline[1]);
def d = (UpperBand < UpperBand[1] and midline < midline[1]);
def e = average(close)>midline;
def f = midline<average(close);

def Chg      =   If(a, 1, If(b, -1, 0));
def Hold     =   CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
def Chg_a      =   If((c1 or e), 1, If((d or f), -1, 0));
def Hold_a     =   CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
def LBUp     =   if fill and Hold[0] == 1 then lowerBand else nan;
def UBUp     =   if fill and Hold[0] == 1 then upperband else nan;
def LBDn     =   if fill and Hold[0] == -1 then lowerband else nan;
def UBDn     =   if fill and Hold[0] == -1 then upperband else nan;
def MBUP     =   if fill and Hold[0] == 1 then midline else nan;
def MBDn     =   if fill and Hold[0] == -1 then Midline else nan;

DefineGlobalColor("Cloud Up", Color.red);
DefineGlobalColor("Cloud_Up", Color.downtick);
DefineGlobalColor("Cloud_Dn", Color.light_green);
DefineGlobalColor("Cloud Dn", Color.cyan);
AddCloud(LBUp, UBUp, GlobalColor("Cloud Up"), GlobalColor("Cloud Dn"));
AddCloud(LBDn, UBDn, GlobalColor("Cloud Dn"), GlobalColor("Cloud Up"));
AddCloud(MBUp, UBUp, GlobalColor("Cloud_Up"), GlobalColor("Cloud_Dn"));
AddCloud(MBDn, UBDn, GlobalColor("Cloud_Dn"), GlobalColor("Cloud_Up"));
 
Last edited:
I used linear regression moving averages since the indicator band clouds are more sensitive to the trend changes.

Ruby:
# © deepphalke
#https://www.tradingview.com/script/lEuCw5DS-JNSAR-DP/
#Peter Luis conversion
# April 24, 2022

def src = hl2;
input displace = 0;
def len = 6;
def w = 4;
def h = high;
def l = low;
def c = close;
def LinReg = Inertia(src[-displace], len);

def LinReg1 = Inertia(h, 5);
def LinReg2 = Inertia(l, 5);
def LinReg3 = Inertia(c, 5);
def avg = (LinReg1+ LinReg2 + LinReg3 + Inertia(h[1], 5)+ Inertia(l[1], 5)+ Inertia(c[1], 5)+ Inertia(h[2], 5)+ Inertia(l[2], 5)+ Inertia(c[2], 5)+ Inertia(h[3], 5)+ Inertia(l[3], 5)+ Inertia(c[3], 5)+ Inertia(h[4], 5)+ Inertia(l[4], 5)+ Inertia(c[4], 5))/15;

plot Upperband = LinReg1;
Upperband.DefineColor("UpTrend", Color.GREEN);
Upperband.DefineColor("DownTrend", Color.RED);
Upperband.SetLineWeight(1);
Upperband.SetPaintingStrategy(PaintingStrategy.LINE);
Upperband.SetStyle(Curve.FIRM);
Upperband.AssignValueColor(if Upperband > Upperband [1] then Upperband.Color("UpTrend") else Upperband.Color("DownTrend"));
plot lowerband = LinReg2;
lowerband.DefineColor("UpTrend", Color.GREEN);
lowerband.DefineColor("DownTrend", Color.RED);
lowerband.SetLineWeight(1);
lowerband.SetPaintingStrategy(PaintingStrategy.LINE);
lowerband.SetStyle(Curve.FIRM);
lowerband.AssignValueColor(if lowerband  > lowerband  [1] then lowerband.Color("UpTrend") else lowerband.Color("DownTrend"));
Plot midline = LinReg3;
midline.DefineColor("UpTrend", Color.GREEN);
midline.DefineColor("DownTrend", Color.RED);
midline.SetLineWeight(1);
midline.SetPaintingStrategy(PaintingStrategy.LINE);
midline.SetStyle(Curve.FIRM);
midline.AssignValueColor(if midline >midline [1] then midline.Color("UpTrend") else midline.Color("DownTrend"));
input fill = yes;
def nan  =  Double.NaN;
plot LineAvg = avg;
LineAvg.DefineColor("UpTrend", Color.GREEN);
LineAvg.DefineColor("DownTrend", Color.RED);
LineAvg.SetLineWeight(3);
LineAvg.SetPaintingStrategy(PaintingStrategy.LINE);
LineAvg.SetStyle(Curve.FIRM);
LineAvg.AssignValueColor(if LineAvg  > LineAvg [1] then LineAvg.Color("UpTrend") else LineAvg.Color("DownTrend"));

def a = (UpperBand > UpperBand[1] and Midline > Midline[1]);
def b = (UpperBand < UpperBand[1] and LowerBand < LowerBand[1]);
def c1 = (UpperBand > UpperBand[1] and Midline > Midline[1]);
def d = (UpperBand < UpperBand[1] and midline < midline[1]);
def e = average(close)>midline;
def f = midline<average(close);

def Chg      =   If(a, 1, If(b, -1, 0));
def Hold     =   CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
def Chg_a      =   If((c1 or e), 1, If((d or f), -1, 0));
def Hold_a     =   CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
def LBUp     =   if fill and Hold[0] == 1 then lowerBand else nan;
def UBUp     =   if fill and Hold[0] == 1 then upperband else nan;
def LBDn     =   if fill and Hold[0] == -1 then lowerband else nan;
def UBDn     =   if fill and Hold[0] == -1 then upperband else nan;
def MBUP     =   if fill and Hold[0] == 1 then midline else nan;
def MBDn     =   if fill and Hold[0] == -1 then Midline else nan;

DefineGlobalColor("Cloud Up", Color.red);
DefineGlobalColor("Cloud_Up", Color.downtick);
DefineGlobalColor("Cloud_Dn", Color.light_green);
DefineGlobalColor("Cloud Dn", Color.cyan);
AddCloud(LBUp, UBUp, GlobalColor("Cloud Up"), GlobalColor("Cloud Dn"));
AddCloud(LBDn, UBDn, GlobalColor("Cloud Dn"), GlobalColor("Cloud Up"));
AddCloud(MBUp, UBUp, GlobalColor("Cloud_Up"), GlobalColor("Cloud_Dn"));
AddCloud(MBDn, UBDn, GlobalColor("Cloud_Dn"), GlobalColor("Cloud_Up"));
 
Last edited:
I combined Heikin-Ashi candles and JNSAR-DP as a lower study to follow the trend changes effectively.

Ruby:
#Heiken_Ashi based on Sylvan Verboort's Trading with HA Candlestick Oscillator
#Bon Bon _last update Jan 17th 2021
# © deepphalke
#https://www.tradingview.com/script/lEuCw5DS-JNSAR-DP/
#https://usethinkscript.com/threads/heikin-ashi-candles-in-lower-section.10428/
declare lower;
input period = 1;
input hideCandles = no;
input candleSmoothing = {default Valcu, Vervoort};
input show_bubble_labels = yes;
input bubbles = yes;
input arrows = yes;
def src = hl2;
input displace = 0;
def len = 6;
def w = 4;
def h = high;
def l = low;
def c = close;
input movingAverageType = {default  TEMA, Exponential, Hull };

def openMA;
def closeMA;
def highMA;
def lowMA;

switch (movingAverageType) {
case Exponential:
    openMA = CompoundValue(1, ExpAverage(open, period), open);
    closeMA = CompoundValue(1, ExpAverage(close, period), close);
    highMA = CompoundValue(1, ExpAverage(high, period), high);
    lowMA = CompoundValue(1, ExpAverage(low, period), low);
case Hull:
    openMA = CompoundValue(1, HullMovingAvg(open, period), open);
    closeMA = CompoundValue(1,  HullMovingAvg(close, period), close);
    highMA = CompoundValue(1,  HullMovingAvg(high, period), high);
    lowMA = CompoundValue(1,  HullMovingAvg(low, period), low);
case TEMA:
    openMA = CompoundValue(1, TEMA(open, period), open);
    closeMA = CompoundValue(1, TEMA(close, period), close);
    highMA = CompoundValue(1, TEMA(high, period), high);
    lowMA = CompoundValue(1, TEMA(low, period), low);

}


HidePricePlot(hideCandles);

def haOpen;
def haClose;

switch (candleSmoothing){
case Valcu:
    haOpen = CompoundValue(1, ( (haOpen[1] + (openMA[1] + highMA[1] + lowMA[1] + closeMA[1]) / 4.0) / 2.0), open);
    haClose = ((((openMA + highMA + lowMA + closeMA) / 4.0) + haOpen + Max(highMA, haOpen) + Min(lowMA, haOpen)) / 4.0);
case Vervoort:
    haOpen = CompoundValue(1, ( (haOpen[1] + (openMA[1] + highMA[1] + lowMA[1] + closeMA[1]) / 4.0 ) / 2.0), open);
    haClose = ((((openMA + highMA + lowMA + closeMA) / 4.0) + haOpen + Max(highMA, haOpen) + Min(lowMA, haOpen)) / 4.0);

}

plot o = haOpen;
o.AssignValueColor(if o > o[1] then Color.cyan else if o < o[1] then Color.magenta else color.gray);
o.SetLineWeight (5);
o.Hide();

def haLow =  Min(lowMA, haOpen);
def haHigh = Max(highMA, haOpen);

def avg = 34;
def TMA1 = reference TEMA(haClose, avg); # triple exponential moving average (TEMA) of 34 bars
def TMA2 =  reference TEMA(TMA1, avg);
def Diff = TMA1 - TMA2;
def ZlHa = TMA1 + Diff; #Zero-lagging TEMA average on closing prices - medium term uptrend;


def TMA1_ = reference TEMA((high + low) / 2, avg);
def Diff2 = TMA1_ - TMA2;
def ZlCl = TMA1_ + Diff2; #Zero-lagging TEMA average on closing prices - medium term doenwardtrend;

def ZlDif = ZlCl - ZlHa; # Zero-Lag close - Zero-Lag HA(green candle) Uptrend when ZlDif is equal to or greater than zero

def keep1 = if (haClose >= haOpen and haClose[1] >= haOpen[1]) then 1 else 0;
def keep2 = if ZlDif >= 0 then 1 else 0;
def keep3 = if (AbsValue(close - open) < ((high - low) * 0.35)) and high >= low[1] then 1 else 0;
def keeping = if (keep1 or keep2) then 1 else 0;
def keepall = if keeping or (keeping[1]) and close >= open or close >= (close[1]) then 1 else 0;

def utr = if keepall or (keepall[1]) and keep3 then 1 else 0;


def keep1_ = if (haClose < haOpen and haClose[1] < haOpen[1]) then 1 else 0;
def keep2_ = if ZlDif < 0 then 1 else 0;
def keep3_ = if (AbsValue(close - open) < ((high - low) * 0.35)) and low <= high[1] then 1 else 0;
def keeping_ = if (keep1_ or keep2_) then 1 else 0;
def dkeepall_ = if keeping_ or (keeping_[1]) and close < open or close < (close[1]) then 1 else 0;

def dtr = if dkeepall_ or (dkeepall_[1] - 1) and keep3_ == 1 then 1 else 0;  #downtrend
def upw = if dtr and (dtr[1]) and utr then 1 else 0;
def dnw = if !utr and (utr[1] ) and dtr then 1 else 0;

def results = if upw then 1 else if dnw then 0 else results[1];


input charttype = ChartType.CANDLE;

def haopen_ = if haClose <= haOpen
              then haOpen + 0
             else Double.NaN;

def HAhi   = if haClose <= haOpen
              then haHigh
              else Double.NaN;

def HAlo =   if haClose <= haOpen
              then haLow
              else Double.NaN;


AddChart(growColor = Color.red, neutralColor = Color.CURRENT, high = HAhi, low = HAlo, open = haopen_, close = haClose, type = ChartType.CANDLE);

def HAclose1 = ohlc4;
def HAopen1  = if haClose >= haOpen
               then CompoundValue(1, (haOpen[1] + haClose[1]) / 2, (open[1] + close[1]) / 2)
               else Double.NaN;

def haopen_1 = if haOpen <= haClose
               then HAopen1 + 0  else Double.NaN;

def HAhigh1  = haHigh;
def HAlow1   = haLow;


AddChart(growColor = Color.green, neutralColor = Color.CURRENT,  high = HAhigh1, low = HAlow1, open = haopen_1, close = haClose, type = ChartType.CANDLE);

def LinReg = Inertia(src[-displace], len);

def LinReg1 = Inertia(h, 5);
def LinReg2 = Inertia(l, 5);
def LinReg3 = Inertia(c, 5);
def avg1 = (LinReg1+ LinReg2 + LinReg3 + Inertia(h[1], 5)+ Inertia(l[1], 5)+ Inertia(c[1], 5)+ Inertia(h[2], 5)+ Inertia(l[2], 5)+ Inertia(c[2], 5)+ Inertia(h[3], 5)+ Inertia(l[3], 5)+ Inertia(c[3], 5)+ Inertia(h[4], 5)+ Inertia(l[4], 5)+ Inertia(c[4], 5))/15;

plot Upperband = LinReg1;
Upperband.DefineColor("UpTrend", Color.GREEN);
Upperband.DefineColor("DownTrend", Color.RED);
Upperband.SetLineWeight(1);
Upperband.SetPaintingStrategy(PaintingStrategy.LINE);
Upperband.SetStyle(Curve.FIRM);
Upperband.AssignValueColor(if Upperband > Upperband [1] then Upperband.Color("UpTrend") else Upperband.Color("DownTrend"));
plot lowerband = LinReg2;
lowerband.DefineColor("UpTrend", Color.GREEN);
lowerband.DefineColor("DownTrend", Color.RED);
lowerband.SetLineWeight(1);
lowerband.SetPaintingStrategy(PaintingStrategy.LINE);
lowerband.SetStyle(Curve.FIRM);
lowerband.AssignValueColor(if lowerband  > lowerband  [1] then lowerband.Color("UpTrend") else lowerband.Color("DownTrend"));
Plot midline = LinReg3;
midline.DefineColor("UpTrend", Color.GREEN);
midline.DefineColor("DownTrend", Color.RED);
midline.SetLineWeight(1);
midline.SetPaintingStrategy(PaintingStrategy.LINE);
midline.SetStyle(Curve.FIRM);
midline.AssignValueColor(if midline >midline [1] then midline.Color("UpTrend") else midline.Color("DownTrend"));
input fill = yes;
def nan  =  Double.NaN;
plot LineAvg = avg1;
LineAvg.DefineColor("UpTrend", Color.GREEN);
LineAvg.DefineColor("DownTrend", Color.RED);
LineAvg.SetLineWeight(3);
LineAvg.SetPaintingStrategy(PaintingStrategy.LINE);
LineAvg.SetStyle(Curve.FIRM);
LineAvg.AssignValueColor(if LineAvg  > LineAvg [1] then LineAvg.Color("UpTrend") else LineAvg.Color("DownTrend"));

def a = (UpperBand > UpperBand[1] and Midline > Midline[1]);
def b = (UpperBand < UpperBand[1] and LowerBand < LowerBand[1]);
def c1 = (UpperBand > UpperBand[1] and Midline > Midline[1]);
def d = (UpperBand < UpperBand[1] and midline < midline[1]);
def e = average(close)>midline;
def f = midline<average(close);

def Chg      =   If(a, 1, If(b, -1, 0));
def Hold     =   CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
def Chg_a      =   If((c1 or e), 1, If((d or f), -1, 0));
def Hold_a     =   CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
def LBUp     =   if fill and Hold[0] == 1 then lowerBand else nan;
def UBUp     =   if fill and Hold[0] == 1 then upperband else nan;
def LBDn     =   if fill and Hold[0] == -1 then lowerband else nan;
def UBDn     =   if fill and Hold[0] == -1 then upperband else nan;
def MBUP     =   if fill and Hold[0] == 1 then midline else nan;
def MBDn     =   if fill and Hold[0] == -1 then Midline else nan;

DefineGlobalColor("Cloud Up", Color.red);
DefineGlobalColor("Cloud_Up", Color.downtick);
DefineGlobalColor("Cloud_Dn", Color.light_green);
DefineGlobalColor("Cloud Dn", Color.cyan);
AddCloud(LBUp, UBUp, GlobalColor("Cloud Up"), GlobalColor("Cloud Dn"));
AddCloud(LBDn, UBDn, GlobalColor("Cloud Dn"), GlobalColor("Cloud Up"));
AddCloud(MBUp, UBUp, GlobalColor("Cloud_Up"), GlobalColor("Cloud_Dn"));
AddCloud(MBDn, UBDn, GlobalColor("Cloud_Dn"), GlobalColor("Cloud_Up"));
 
A lower study with Heikin-Ashi candles, JNSAR-DP and BLSH.

Ruby:
#Heiken_Ashi based on Sylvan Verboort's Trading with HA Candlestick Oscillator
#Bon Bon _last update Jan 17th 2021
# © deepphalke
#https://www.tradingview.com/script/lEuCw5DS-JNSAR-DP/
#https://usethinkscript.com/threads/heikin-ashi-candles-in-lower-section.10428/
#// beardcrack
#study(title="Modified DC for BLSH", shorttitle="BLSH Price Table", overlay=true)
#https://www.tradingview.com/script/MkrCvQ22-BLSH/
declare lower;
input period = 1;
input hideCandles = no;
input candleSmoothing = {default Valcu, Vervoort};
input show_bubble_labels = yes;
input bubbles = yes;
input arrows = yes;
def src = hl2;
input displace = 0;
def len = 6;
def w = 4;
def h = high;
def l = low;
def c = close;
input movingAverageType = {default  TEMA, Exponential, Hull };
def length = 25;
def profit = 5;
def openMA;
def closeMA;
def highMA;
def lowMA;
def LOW25 = lowest(low, length);
def GTT = LOW25*1.05;
def TARGET = GTT*1.05;
switch (movingAverageType) {
case Exponential:
    openMA = CompoundValue(1, ExpAverage(open, period), open);
    closeMA = CompoundValue(1, ExpAverage(close, period), close);
    highMA = CompoundValue(1, ExpAverage(high, period), high);
    lowMA = CompoundValue(1, ExpAverage(low, period), low);
case Hull:
    openMA = CompoundValue(1, HullMovingAvg(open, period), open);
    closeMA = CompoundValue(1,  HullMovingAvg(close, period), close);
    highMA = CompoundValue(1,  HullMovingAvg(high, period), high);
    lowMA = CompoundValue(1,  HullMovingAvg(low, period), low);
case TEMA:
    openMA = CompoundValue(1, TEMA(open, period), open);
    closeMA = CompoundValue(1, TEMA(close, period), close);
    highMA = CompoundValue(1, TEMA(high, period), high);
    lowMA = CompoundValue(1, TEMA(low, period), low);

}


HidePricePlot(hideCandles);

def haOpen;
def haClose;

switch (candleSmoothing){
case Valcu:
    haOpen = CompoundValue(1, ( (haOpen[1] + (openMA[1] + highMA[1] + lowMA[1] + closeMA[1]) / 4.0) / 2.0), open);
    haClose = ((((openMA + highMA + lowMA + closeMA) / 4.0) + haOpen + Max(highMA, haOpen) + Min(lowMA, haOpen)) / 4.0);
case Vervoort:
    haOpen = CompoundValue(1, ( (haOpen[1] + (openMA[1] + highMA[1] + lowMA[1] + closeMA[1]) / 4.0 ) / 2.0), open);
    haClose = ((((openMA + highMA + lowMA + closeMA) / 4.0) + haOpen + Max(highMA, haOpen) + Min(lowMA, haOpen)) / 4.0);

}

plot o = haOpen;
o.AssignValueColor(if o > o[1] then Color.cyan else if o < o[1] then Color.magenta else color.gray);
o.SetLineWeight (5);
o.Hide();

def haLow =  Min(lowMA, haOpen);
def haHigh = Max(highMA, haOpen);

def avg = 34;
def TMA1 = reference TEMA(haClose, avg); # triple exponential moving average (TEMA) of 34 bars
def TMA2 =  reference TEMA(TMA1, avg);
def Diff = TMA1 - TMA2;
def ZlHa = TMA1 + Diff; #Zero-lagging TEMA average on closing prices - medium term uptrend;


def TMA1_ = reference TEMA((high + low) / 2, avg);
def Diff2 = TMA1_ - TMA2;
def ZlCl = TMA1_ + Diff2; #Zero-lagging TEMA average on closing prices - medium term doenwardtrend;

def ZlDif = ZlCl - ZlHa; # Zero-Lag close - Zero-Lag HA(green candle) Uptrend when ZlDif is equal to or greater than zero

def keep1 = if (haClose >= haOpen and haClose[1] >= haOpen[1]) then 1 else 0;
def keep2 = if ZlDif >= 0 then 1 else 0;
def keep3 = if (AbsValue(close - open) < ((high - low) * 0.35)) and high >= low[1] then 1 else 0;
def keeping = if (keep1 or keep2) then 1 else 0;
def keepall = if keeping or (keeping[1]) and close >= open or close >= (close[1]) then 1 else 0;

def utr = if keepall or (keepall[1]) and keep3 then 1 else 0;


def keep1_ = if (haClose < haOpen and haClose[1] < haOpen[1]) then 1 else 0;
def keep2_ = if ZlDif < 0 then 1 else 0;
def keep3_ = if (AbsValue(close - open) < ((high - low) * 0.35)) and low <= high[1] then 1 else 0;
def keeping_ = if (keep1_ or keep2_) then 1 else 0;
def dkeepall_ = if keeping_ or (keeping_[1]) and close < open or close < (close[1]) then 1 else 0;

def dtr = if dkeepall_ or (dkeepall_[1] - 1) and keep3_ == 1 then 1 else 0;  #downtrend
def upw = if dtr and (dtr[1]) and utr then 1 else 0;
def dnw = if !utr and (utr[1] ) and dtr then 1 else 0;

def results = if upw then 1 else if dnw then 0 else results[1];


input charttype = ChartType.CANDLE;

def haopen_ = if haClose <= haOpen
              then haOpen + 0
             else Double.NaN;

def HAhi   = if haClose <= haOpen
              then haHigh
              else Double.NaN;

def HAlo =   if haClose <= haOpen
              then haLow
              else Double.NaN;


AddChart(growColor = Color.red, neutralColor = Color.CURRENT, high = HAhi, low = HAlo, open = haopen_, close = haClose, type = ChartType.CANDLE);

def HAclose1 = ohlc4;
def HAopen1  = if haClose >= haOpen
               then CompoundValue(1, (haOpen[1] + haClose[1]) / 2, (open[1] + close[1]) / 2)
               else Double.NaN;

def haopen_1 = if haOpen <= haClose
               then HAopen1 + 0  else Double.NaN;

def HAhigh1  = haHigh;
def HAlow1   = haLow;


AddChart(growColor = Color.green, neutralColor = Color.CURRENT,  high = HAhigh1, low = HAlow1, open = haopen_1, close = haClose, type = ChartType.CANDLE);

def LinReg = Inertia(src[-displace], len);

def LinReg1 = Inertia(h, 5);
def LinReg2 = Inertia(l, 5);
def LinReg3 = Inertia(c, 5);
def avg1 = (LinReg1+ LinReg2 + LinReg3 + Inertia(h[1], 5)+ Inertia(l[1], 5)+ Inertia(c[1], 5)+ Inertia(h[2], 5)+ Inertia(l[2], 5)+ Inertia(c[2], 5)+ Inertia(h[3], 5)+ Inertia(l[3], 5)+ Inertia(c[3], 5)+ Inertia(h[4], 5)+ Inertia(l[4], 5)+ Inertia(c[4], 5))/15;

plot Upperband = LinReg1;
Upperband.DefineColor("UpTrend", Color.GREEN);
Upperband.DefineColor("DownTrend", Color.RED);
Upperband.SetLineWeight(1);
Upperband.SetPaintingStrategy(PaintingStrategy.LINE);
Upperband.SetStyle(Curve.FIRM);
Upperband.AssignValueColor(if Upperband > Upperband [1] then Upperband.Color("UpTrend") else Upperband.Color("DownTrend"));
plot lowerband = LinReg2;
lowerband.DefineColor("UpTrend", Color.GREEN);
lowerband.DefineColor("DownTrend", Color.RED);
lowerband.SetLineWeight(1);
lowerband.SetPaintingStrategy(PaintingStrategy.LINE);
lowerband.SetStyle(Curve.FIRM);
lowerband.AssignValueColor(if lowerband  > lowerband  [1] then lowerband.Color("UpTrend") else lowerband.Color("DownTrend"));
Plot midline = LinReg3;
midline.DefineColor("UpTrend", Color.GREEN);
midline.DefineColor("DownTrend", Color.RED);
midline.SetLineWeight(1);
midline.SetPaintingStrategy(PaintingStrategy.LINE);
midline.SetStyle(Curve.FIRM);
midline.AssignValueColor(if midline >midline [1] then midline.Color("UpTrend") else midline.Color("DownTrend"));
input fill = yes;
def nan  =  Double.NaN;
plot LineAvg = avg1;
LineAvg.DefineColor("UpTrend", Color.GREEN);
LineAvg.DefineColor("DownTrend", Color.RED);
LineAvg.SetLineWeight(3);
LineAvg.SetPaintingStrategy(PaintingStrategy.LINE);
LineAvg.SetStyle(Curve.FIRM);
LineAvg.AssignValueColor(if LineAvg  > LineAvg [1] then LineAvg.Color("UpTrend") else LineAvg.Color("DownTrend"));

def a = (UpperBand > UpperBand[1] and Midline > Midline[1]);
def b = (UpperBand < UpperBand[1] and LowerBand < LowerBand[1]);
def c1 = (UpperBand > UpperBand[1] and Midline > Midline[1]);
def d = (UpperBand < UpperBand[1] and midline < midline[1]);
def e = average(close)>midline;
def f = midline<average(close);

def Chg      =   If(a, 1, If(b, -1, 0));
def Hold     =   CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
def Chg_a      =   If((c1 or e), 1, If((d or f), -1, 0));
def Hold_a     =   CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
def LBUp     =   if fill and Hold[0] == 1 then lowerBand else nan;
def UBUp     =   if fill and Hold[0] == 1 then upperband else nan;
def LBDn     =   if fill and Hold[0] == -1 then lowerband else nan;
def UBDn     =   if fill and Hold[0] == -1 then upperband else nan;
def MBUP     =   if fill and Hold[0] == 1 then midline else nan;
def MBDn     =   if fill and Hold[0] == -1 then Midline else nan;

DefineGlobalColor("Cloud Up", Color.red);
DefineGlobalColor("Cloud_Up", Color.downtick);
DefineGlobalColor("Cloud_Dn", Color.light_green);
DefineGlobalColor("Cloud Dn", Color.cyan);
AddCloud(LBUp, UBUp, GlobalColor("Cloud Up"), GlobalColor("Cloud Dn"));
AddCloud(LBDn, UBDn, GlobalColor("Cloud Dn"), GlobalColor("Cloud Up"));
AddCloud(MBUp, UBUp, GlobalColor("Cloud_Up"), GlobalColor("Cloud_Dn"));
AddCloud(MBDn, UBDn, GlobalColor("Cloud_Dn"), GlobalColor("Cloud_Up"));


plot lineGTT = GTT;
lineGTT.AssignValueColor(if lineGTT> lineGTT[1] then Color.GREEN else if lineGTT <lineGTT[1] then Color.MAGENTA else color.light_gray);
lineGTT.SetLineWeight(3);
plot LineLowe25 = LOW25;
LineLowe25.AssignValueColor(if LineLowe25> LineLowe25[1] then Color.light_GREEN else if LineLowe25 <LineLowe25[1] then Color.light_red else color.yellow);
LineLowe25.SetLineWeight(3);
plot LineTarget = TARGET;
LineTarget.AssignValueColor(if LineTarget> LineTarget[1] then Color.dark_GREEN else if LineTarget<LineTarget[1] then Color.red else color.white);
LineTarget.SetLineWeight(4);
 
mod note:
The use of multiple trend indicators is analogous of putting multiple thermometers outside and getting excited when they all report the same / similar temperature. This phenomon is called
multi-collinarity

A lower study with Heikin-Ashi candles, JNSAR-DP, BLSH and double supertrend ATR.


Ruby:
#Heiken_Ashi based on Sylvan Verboort's Trading with HA Candlestick Oscillator
#Bon Bon _last update Jan 17th 2021
# © deepphalke
#https://www.tradingview.com/script/lEuCw5DS-JNSAR-DP/
#https://usethinkscript.com/threads/heikin-ashi-candles-in-lower-section.10428/
#// beardcrack
#study(title="Modified DC for BLSH", shorttitle="BLSH Price Table", overlay=true)
#https://www.tradingview.com/script/MkrCvQ22-BLSH/
#https://usethinkscript.com/threads/double-supertrend-atr-for-thinkorswim.10986/
declare lower;
input period = 1;
input hideCandles = no;
input candleSmoothing = {default Valcu, Vervoort};
input show_bubble_labels = yes;
input bubbles = yes;
input arrows = yes;
def src = hl2;
input displace = 0;
def len = 6;
def w = 4;
def h = high;
def l = low;
def c = close;
def srca = close;
def la = 6;
def std = no;
def bc = no;
def k = 1.0 / l;
def Factor = 3;
def ATR = 12;

def src1 = hl2;
def aa = 0.07;
def fr = no;
def ebc = no;
def hr = no;
input movingAverageType = {default  TEMA, Exponential, Hull };
def length = 25;
def profit = 5;
def openMA;
def closeMA;
def highMA;
def lowMA;
def LOW25 = lowest(low, length);
def GTT = LOW25*1.05;
def TARGET = GTT*1.05;
switch (movingAverageType) {
case Exponential:
    openMA = CompoundValue(1, ExpAverage(open, period), open);
    closeMA = CompoundValue(1, ExpAverage(close, period), close);
    highMA = CompoundValue(1, ExpAverage(high, period), high);
    lowMA = CompoundValue(1, ExpAverage(low, period), low);
case Hull:
    openMA = CompoundValue(1, HullMovingAvg(open, period), open);
    closeMA = CompoundValue(1,  HullMovingAvg(close, period), close);
    highMA = CompoundValue(1,  HullMovingAvg(high, period), high);
    lowMA = CompoundValue(1,  HullMovingAvg(low, period), low);
case TEMA:
    openMA = CompoundValue(1, TEMA(open, period), open);
    closeMA = CompoundValue(1, TEMA(close, period), close);
    highMA = CompoundValue(1, TEMA(high, period), high);
    lowMA = CompoundValue(1, TEMA(low, period), low);

}


HidePricePlot(hideCandles);

def haOpen;
def haClose;

switch (candleSmoothing){
case Valcu:
    haOpen = CompoundValue(1, ( (haOpen[1] + (openMA[1] + highMA[1] + lowMA[1] + closeMA[1]) / 4.0) / 2.0), open);
    haClose = ((((openMA + highMA + lowMA + closeMA) / 4.0) + haOpen + Max(highMA, haOpen) + Min(lowMA, haOpen)) / 4.0);
case Vervoort:
    haOpen = CompoundValue(1, ( (haOpen[1] + (openMA[1] + highMA[1] + lowMA[1] + closeMA[1]) / 4.0 ) / 2.0), open);
    haClose = ((((openMA + highMA + lowMA + closeMA) / 4.0) + haOpen + Max(highMA, haOpen) + Min(lowMA, haOpen)) / 4.0);

}

plot o = haOpen;
o.AssignValueColor(if o > o[1] then Color.cyan else if o < o[1] then Color.magenta else color.gray);
o.SetLineWeight (5);
o.Hide();

def haLow =  Min(lowMA, haOpen);
def haHigh = Max(highMA, haOpen);

def avg = 34;
def TMA1 = reference TEMA(haClose, avg); # triple exponential moving average (TEMA) of 34 bars
def TMA2 =  reference TEMA(TMA1, avg);
def Diff = TMA1 - TMA2;
def ZlHa = TMA1 + Diff; #Zero-lagging TEMA average on closing prices - medium term uptrend;


def TMA1_ = reference TEMA((high + low) / 2, avg);
def Diff2 = TMA1_ - TMA2;
def ZlCl = TMA1_ + Diff2; #Zero-lagging TEMA average on closing prices - medium term doenwardtrend;

def ZlDif = ZlCl - ZlHa; # Zero-Lag close - Zero-Lag HA(green candle) Uptrend when ZlDif is equal to or greater than zero

def keep1 = if (haClose >= haOpen and haClose[1] >= haOpen[1]) then 1 else 0;
def keep2 = if ZlDif >= 0 then 1 else 0;
def keep3 = if (AbsValue(close - open) < ((high - low) * 0.35)) and high >= low[1] then 1 else 0;
def keeping = if (keep1 or keep2) then 1 else 0;
def keepall = if keeping or (keeping[1]) and close >= open or close >= (close[1]) then 1 else 0;

def utr = if keepall or (keepall[1]) and keep3 then 1 else 0;


def keep1_ = if (haClose < haOpen and haClose[1] < haOpen[1]) then 1 else 0;
def keep2_ = if ZlDif < 0 then 1 else 0;
def keep3_ = if (AbsValue(close - open) < ((high - low) * 0.35)) and low <= high[1] then 1 else 0;
def keeping_ = if (keep1_ or keep2_) then 1 else 0;
def dkeepall_ = if keeping_ or (keeping_[1]) and close < open or close < (close[1]) then 1 else 0;

def dtr = if dkeepall_ or (dkeepall_[1] - 1) and keep3_ == 1 then 1 else 0;  #downtrend
def upw = if dtr and (dtr[1]) and utr then 1 else 0;
def dnw = if !utr and (utr[1] ) and dtr then 1 else 0;

def results = if upw then 1 else if dnw then 0 else results[1];


input charttype = ChartType.CANDLE;

def haopen_ = if haClose <= haOpen
              then haOpen + 0
             else Double.NaN;

def HAhi   = if haClose <= haOpen
              then haHigh
              else Double.NaN;

def HAlo =   if haClose <= haOpen
              then haLow
              else Double.NaN;


AddChart(growColor = Color.red, neutralColor = Color.CURRENT, high = HAhi, low = HAlo, open = haopen_, close = haClose, type = ChartType.CANDLE);

def HAclose1 = ohlc4;
def HAopen1  = if haClose >= haOpen
               then CompoundValue(1, (haOpen[1] + haClose[1]) / 2, (open[1] + close[1]) / 2)
               else Double.NaN;

def haopen_1 = if haOpen <= haClose
               then HAopen1 + 0  else Double.NaN;

def HAhigh1  = haHigh;
def HAlow1   = haLow;


AddChart(growColor = Color.green, neutralColor = Color.CURRENT,  high = HAhigh1, low = HAlow1, open = haopen_1, close = haClose, type = ChartType.CANDLE);

def LinReg = Inertia(src[-displace], len);

def LinReg1 = Inertia(h, 5);
def LinReg2 = Inertia(l, 5);
def LinReg3 = Inertia(c, 5);
def avg1 = (LinReg1+ LinReg2 + LinReg3 + Inertia(h[1], 5)+ Inertia(l[1], 5)+ Inertia(c[1], 5)+ Inertia(h[2], 5)+ Inertia(l[2], 5)+ Inertia(c[2], 5)+ Inertia(h[3], 5)+ Inertia(l[3], 5)+ Inertia(c[3], 5)+ Inertia(h[4], 5)+ Inertia(l[4], 5)+ Inertia(c[4], 5))/15;

plot Upperband = LinReg1;
Upperband.DefineColor("UpTrend", Color.GREEN);
Upperband.DefineColor("DownTrend", Color.RED);
Upperband.SetLineWeight(1);
Upperband.SetPaintingStrategy(PaintingStrategy.LINE);
Upperband.SetStyle(Curve.FIRM);
Upperband.AssignValueColor(if Upperband > Upperband [1] then Upperband.Color("UpTrend") else Upperband.Color("DownTrend"));
plot lowerband = LinReg2;
lowerband.DefineColor("UpTrend", Color.GREEN);
lowerband.DefineColor("DownTrend", Color.RED);
lowerband.SetLineWeight(1);
lowerband.SetPaintingStrategy(PaintingStrategy.LINE);
lowerband.SetStyle(Curve.FIRM);
lowerband.AssignValueColor(if lowerband  > lowerband  [1] then lowerband.Color("UpTrend") else lowerband.Color("DownTrend"));
Plot midline = LinReg3;
midline.DefineColor("UpTrend", Color.GREEN);
midline.DefineColor("DownTrend", Color.RED);
midline.SetLineWeight(1);
midline.SetPaintingStrategy(PaintingStrategy.LINE);
midline.SetStyle(Curve.FIRM);
midline.AssignValueColor(if midline >midline [1] then midline.Color("UpTrend") else midline.Color("DownTrend"));
input fill = yes;
def nan  =  Double.NaN;
plot LineAvg = avg1;
LineAvg.DefineColor("UpTrend", Color.GREEN);
LineAvg.DefineColor("DownTrend", Color.RED);
LineAvg.SetLineWeight(3);
LineAvg.SetPaintingStrategy(PaintingStrategy.LINE);
LineAvg.SetStyle(Curve.FIRM);
LineAvg.AssignValueColor(if LineAvg  > LineAvg [1] then LineAvg.Color("UpTrend") else LineAvg.Color("DownTrend"));

def a = (UpperBand > UpperBand[1] and Midline > Midline[1]);
def b = (UpperBand < UpperBand[1] and LowerBand < LowerBand[1]);
def c1 = (UpperBand > UpperBand[1] and Midline > Midline[1]);
def d = (UpperBand < UpperBand[1] and midline < midline[1]);
def e = average(close)>midline;
def f = midline<average(close);

def Chg      =   If(a, 1, If(b, -1, 0));
def Hold     =   CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
def Chg_a      =   If((c1 or e), 1, If((d or f), -1, 0));
def Hold_a     =   CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
def LBUp     =   if fill and Hold[0] == 1 then lowerBand else nan;
def UBUp     =   if fill and Hold[0] == 1 then upperband else nan;
def LBDn     =   if fill and Hold[0] == -1 then lowerband else nan;
def UBDn     =   if fill and Hold[0] == -1 then upperband else nan;
def MBUP     =   if fill and Hold[0] == 1 then midline else nan;
def MBDn     =   if fill and Hold[0] == -1 then Midline else nan;

DefineGlobalColor("Cloud Up", Color.red);
DefineGlobalColor("Cloud_Up", Color.downtick);
DefineGlobalColor("Cloud_Dn", Color.light_green);
DefineGlobalColor("Cloud Dn", Color.cyan);
AddCloud(LBUp, UBUp, GlobalColor("Cloud Up"), GlobalColor("Cloud Dn"));
AddCloud(LBDn, UBDn, GlobalColor("Cloud Dn"), GlobalColor("Cloud Up"));
AddCloud(MBUp, UBUp, GlobalColor("Cloud_Up"), GlobalColor("Cloud_Dn"));
AddCloud(MBDn, UBDn, GlobalColor("Cloud_Dn"), GlobalColor("Cloud_Up"));


plot lineGTT = GTT;
lineGTT.AssignValueColor(if lineGTT> lineGTT[1] then Color.GREEN else if lineGTT <lineGTT[1] then Color.MAGENTA else color.light_gray);
lineGTT.SetLineWeight(3);
plot LineLowe25 = LOW25;
LineLowe25.AssignValueColor(if LineLowe25> LineLowe25[1] then Color.light_GREEN else if LineLowe25 <LineLowe25[1] then Color.light_red else color.yellow);
LineLowe25.SetLineWeight(3);
plot LineTarget = TARGET;
LineTarget.AssignValueColor(if LineTarget> LineTarget[1] then Color.dark_GREEN else if LineTarget<LineTarget[1] then Color.red else color.white);
LineTarget.SetLineWeight(4);


script nz {
    input data = 0;
    def ret_val = if IsNaN(data) then 0 else data;
    plot return = ret_val;
}
def pdm = Max((srca - srca[1]), 0);
def mdm = Max((srca[1] - srca), 0);
def pdmS = ((1 - k) * nz(pdmS[1]) + k * pdm);
def mdmS = ((1 - k) * nz(mdmS[1]) + k * mdm);
def s = pdmS + mdmS;
def pdi = pdmS / s;
def mdi = mdmS / s;
def pdiS = ((1 - k) * nz(pdiS[1]) + k * pdi);
def mdiS = ((1 - k) * nz(mdiS[1]) + k * mdi);
def da = AbsValue(pdiS - mdiS);
def s1 = pdiS + mdiS;
def iS = ((1 - k) * nz(iS[1]) + k * da / s1);
def hhv = Highest(iS, la);
def llv = Lowest(iS, la);
def d1 = hhv - llv;
def vI = (iS - llv) / d1;
def vma = (1 - k * vI) * nz(vma[1]) + k * vI * src;
def line = vma;
#line.AssignValueColor(if line> line[1] then Color.GREEN else if line <line[1] then Color.MAGENTA else color.gray);
#line.SetLineWeight(2);

script nz {
input data = 0;
input data2 = 0;
def ret_val = if IsNaN(data) then data2 else data;
plot return = ret_val;
}



def it = (aa - ((aa * aa) / 4.0)) * src1 + 0.5 * aa * aa * src1[1] - (aa - 0.75 * aa * aa) * src1[2] + 2 * (1 - aa ) * nz(it[1], ((src1 + 2 * src1[1] + src1[2]) / 4.0)) - (1 - aa ) * (1 - aa ) * nz(it[2], ((src1 + 2 * src1[1] + src1[2]) / 4.0));

def lag = 2.0 * it - nz(it[2]);
plot dl = if fr and hr == no then if it > lag then lag else it else Double.NaN;
plot itl = if hr then Double.NaN else it;
plot ll = if hr then Double.NaN else lag;
AddCloud (ll, itl, Color.light_green, Color.light_RED);

script MTF_ATR {
    input Length = 12;
    input TF = AggregationPeriod.HOUR;
    input averageType = AverageType.WILDERS;
    plot ATR =
        MovingAverage(
            averageType,
            TrueRange(
                high(period = TF),
                close(period = TF),
                low(period = TF)
            ),
            Length
        )
    ;
}
def Up = hl2 - (Factor * ATR(ATR));
def Dn = hl2 + (Factor * ATR(ATR));

def TUp = if close[1] > TUp[1] then Max(Up, TUp[1]) else Up;
def TDown = if close[1] < TDown[1] then Min(Dn, TDown[1]) else Dn;

def Trend = if close > TDown[1] then 1 else if close < TUp[1] then -1 else nz(Trend[1],1);

def Tsl1 = if Trend == 1 then TUp else TDown;
def Tsl2 = if Trend == 1 then TDown else TUp;

plot p1 = Tsl1;
plot p2 = Tsl2;
p1.AssignValueColor(if p1 < p2  then Color.green else Color.magenta);
p1.SetLineWeight(1);
p2.AssignValueColor(if p1 < p2  then Color.green else Color.magenta);
p2.SetLineWeight(1);

AddCloud(p1,   p2,   Color.light_RED,   Color.light_GREEN);
 
Last edited by a moderator:
A lower study with Heikin-Ashi candles, JNSAR-DP, BLSH and double supertrend ATR.
Ruby:
#Heiken_Ashi based on Sylvan Verboort's Trading with HA Candlestick Oscillator
#Bon Bon _last update Jan 17th 2021
# © deepphalke
#https://www.tradingview.com/script/lEuCw5DS-JNSAR-DP/
#https://usethinkscript.com/threads/heikin-ashi-candles-in-lower-section.10428/
#// beardcrack
#study(title="Modified DC for BLSH", shorttitle="BLSH Price Table", overlay=true)
#https://www.tradingview.com/script/MkrCvQ22-BLSH/
#https://usethinkscript.com/threads/double-supertrend-atr-for-thinkorswim.10986/
#https://www.tradingview.com/script/6Ix0E5Yr-Variable-Moving-Average-LazyBear/
declare lower;

def srca = close;
def la = 6;
def std = no;
def bc = no;
def k = 1.0 / la;
def Factor = 3;
def ATR = 12;
input period = 1;
input hideCandles = no;
input candleSmoothing = {default Valcu, Vervoort};
input show_bubble_labels = yes;
input bubbles = yes;
input arrows = yes;
def src = hl2;
input displace = 0;
def len = 6;
def w = 4;
def h = high;
def l = low;
def c = close;
input movingAverageType = {default  TEMA, Exponential, Hull };
def length = 25;
def profit = 5;
def openMA;
def closeMA;
def highMA;
def lowMA;
def LOW25 = lowest(low, length);
def GTT = LOW25*1.05;
def TARGET = GTT*1.05;
switch (movingAverageType) {
case Exponential:
    openMA = CompoundValue(1, ExpAverage(open, period), open);
    closeMA = CompoundValue(1, ExpAverage(close, period), close);
    highMA = CompoundValue(1, ExpAverage(high, period), high);
    lowMA = CompoundValue(1, ExpAverage(low, period), low);
case Hull:
    openMA = CompoundValue(1, HullMovingAvg(open, period), open);
    closeMA = CompoundValue(1,  HullMovingAvg(close, period), close);
    highMA = CompoundValue(1,  HullMovingAvg(high, period), high);
    lowMA = CompoundValue(1,  HullMovingAvg(low, period), low);
case TEMA:
    openMA = CompoundValue(1, TEMA(open, period), open);
    closeMA = CompoundValue(1, TEMA(close, period), close);
    highMA = CompoundValue(1, TEMA(high, period), high);
    lowMA = CompoundValue(1, TEMA(low, period), low);

}


HidePricePlot(hideCandles);

def haOpen;
def haClose;

switch (candleSmoothing){
case Valcu:
    haOpen = CompoundValue(1, ( (haOpen[1] + (openMA[1] + highMA[1] + lowMA[1] + closeMA[1]) / 4.0) / 2.0), open);
    haClose = ((((openMA + highMA + lowMA + closeMA) / 4.0) + haOpen + Max(highMA, haOpen) + Min(lowMA, haOpen)) / 4.0);
case Vervoort:
    haOpen = CompoundValue(1, ( (haOpen[1] + (openMA[1] + highMA[1] + lowMA[1] + closeMA[1]) / 4.0 ) / 2.0), open);
    haClose = ((((openMA + highMA + lowMA + closeMA) / 4.0) + haOpen + Max(highMA, haOpen) + Min(lowMA, haOpen)) / 4.0);

}

plot o = haOpen;
o.AssignValueColor(if o > o[1] then Color.cyan else if o < o[1] then Color.magenta else color.gray);
o.SetLineWeight (5);
o.Hide();

def haLow =  Min(lowMA, haOpen);
def haHigh = Max(highMA, haOpen);

def avg = 34;
def TMA1 = reference TEMA(haClose, avg); # triple exponential moving average (TEMA) of 34 bars
def TMA2 =  reference TEMA(TMA1, avg);
def Diff = TMA1 - TMA2;
def ZlHa = TMA1 + Diff; #Zero-lagging TEMA average on closing prices - medium term uptrend;


def TMA1_ = reference TEMA((high + low) / 2, avg);
def Diff2 = TMA1_ - TMA2;
def ZlCl = TMA1_ + Diff2; #Zero-lagging TEMA average on closing prices - medium term doenwardtrend;

def ZlDif = ZlCl - ZlHa; # Zero-Lag close - Zero-Lag HA(green candle) Uptrend when ZlDif is equal to or greater than zero

def keep1 = if (haClose >= haOpen and haClose[1] >= haOpen[1]) then 1 else 0;
def keep2 = if ZlDif >= 0 then 1 else 0;
def keep3 = if (AbsValue(close - open) < ((high - low) * 0.35)) and high >= low[1] then 1 else 0;
def keeping = if (keep1 or keep2) then 1 else 0;
def keepall = if keeping or (keeping[1]) and close >= open or close >= (close[1]) then 1 else 0;

def utr = if keepall or (keepall[1]) and keep3 then 1 else 0;


def keep1_ = if (haClose < haOpen and haClose[1] < haOpen[1]) then 1 else 0;
def keep2_ = if ZlDif < 0 then 1 else 0;
def keep3_ = if (AbsValue(close - open) < ((high - low) * 0.35)) and low <= high[1] then 1 else 0;
def keeping_ = if (keep1_ or keep2_) then 1 else 0;
def dkeepall_ = if keeping_ or (keeping_[1]) and close < open or close < (close[1]) then 1 else 0;

def dtr = if dkeepall_ or (dkeepall_[1] - 1) and keep3_ == 1 then 1 else 0;  #downtrend
def upw = if dtr and (dtr[1]) and utr then 1 else 0;
def dnw = if !utr and (utr[1] ) and dtr then 1 else 0;

def results = if upw then 1 else if dnw then 0 else results[1];


input charttype = ChartType.CANDLE;

def haopen_ = if haClose <= haOpen
              then haOpen + 0
             else Double.NaN;

def HAhi   = if haClose <= haOpen
              then haHigh
              else Double.NaN;

def HAlo =   if haClose <= haOpen
              then haLow
              else Double.NaN;


AddChart(growColor = Color.red, neutralColor = Color.CURRENT, high = HAhi, low = HAlo, open = haopen_, close = haClose, type = ChartType.CANDLE);

def HAclose1 = ohlc4;
def HAopen1  = if haClose >= haOpen
               then CompoundValue(1, (haOpen[1] + haClose[1]) / 2, (open[1] + close[1]) / 2)
               else Double.NaN;

def haopen_1 = if haOpen <= haClose
               then HAopen1 + 0  else Double.NaN;

def HAhigh1  = haHigh;
def HAlow1   = haLow;


AddChart(growColor = Color.green, neutralColor = Color.CURRENT,  high = HAhigh1, low = HAlow1, open = haopen_1, close = haClose, type = ChartType.CANDLE);

def LinReg = Inertia(src[-displace], len);

def LinReg1 = Inertia(h, 5);
def LinReg2 = Inertia(l, 5);
def LinReg3 = Inertia(c, 5);
def avg1 = (LinReg1+ LinReg2 + LinReg3 + Inertia(h[1], 5)+ Inertia(l[1], 5)+ Inertia(c[1], 5)+ Inertia(h[2], 5)+ Inertia(l[2], 5)+ Inertia(c[2], 5)+ Inertia(h[3], 5)+ Inertia(l[3], 5)+ Inertia(c[3], 5)+ Inertia(h[4], 5)+ Inertia(l[4], 5)+ Inertia(c[4], 5))/15;

plot Upperband = LinReg1;
Upperband.DefineColor("UpTrend", Color.GREEN);
Upperband.DefineColor("DownTrend", Color.RED);
Upperband.SetLineWeight(1);
Upperband.SetPaintingStrategy(PaintingStrategy.LINE);
Upperband.SetStyle(Curve.FIRM);
Upperband.AssignValueColor(if Upperband > Upperband [1] then Upperband.Color("UpTrend") else Upperband.Color("DownTrend"));
plot lowerband = LinReg2;
lowerband.DefineColor("UpTrend", Color.GREEN);
lowerband.DefineColor("DownTrend", Color.RED);
lowerband.SetLineWeight(1);
lowerband.SetPaintingStrategy(PaintingStrategy.LINE);
lowerband.SetStyle(Curve.FIRM);
lowerband.AssignValueColor(if lowerband  > lowerband  [1] then lowerband.Color("UpTrend") else lowerband.Color("DownTrend"));
Plot midline = LinReg3;
midline.DefineColor("UpTrend", Color.GREEN);
midline.DefineColor("DownTrend", Color.RED);
midline.SetLineWeight(1);
midline.SetPaintingStrategy(PaintingStrategy.LINE);
midline.SetStyle(Curve.FIRM);
midline.AssignValueColor(if midline >midline [1] then midline.Color("UpTrend") else midline.Color("DownTrend"));
input fill = yes;
def nan  =  Double.NaN;
plot LineAvg = avg1;
LineAvg.DefineColor("UpTrend", Color.GREEN);
LineAvg.DefineColor("DownTrend", Color.RED);
LineAvg.SetLineWeight(3);
LineAvg.SetPaintingStrategy(PaintingStrategy.LINE);
LineAvg.SetStyle(Curve.FIRM);
LineAvg.AssignValueColor(if LineAvg  > LineAvg [1] then LineAvg.Color("UpTrend") else LineAvg.Color("DownTrend"));

def a = (UpperBand > UpperBand[1] and Midline > Midline[1]);
def b = (UpperBand < UpperBand[1] and LowerBand < LowerBand[1]);
def c1 = (UpperBand > UpperBand[1] and Midline > Midline[1]);
def d = (UpperBand < UpperBand[1] and midline < midline[1]);
def e = average(close)>midline;
def f = midline<average(close);

def Chg      =   If(a, 1, If(b, -1, 0));
def Hold     =   CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
def Chg_a      =   If((c1 or e), 1, If((d or f), -1, 0));
def Hold_a     =   CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
def LBUp     =   if fill and Hold[0] == 1 then lowerBand else nan;
def UBUp     =   if fill and Hold[0] == 1 then upperband else nan;
def LBDn     =   if fill and Hold[0] == -1 then lowerband else nan;
def UBDn     =   if fill and Hold[0] == -1 then upperband else nan;
def MBUP     =   if fill and Hold[0] == 1 then midline else nan;
def MBDn     =   if fill and Hold[0] == -1 then Midline else nan;

DefineGlobalColor("Cloud Up", Color.red);
DefineGlobalColor("Cloud_Up", Color.downtick);
DefineGlobalColor("Cloud_Dn", Color.light_green);
DefineGlobalColor("Cloud Dn", Color.cyan);
AddCloud(LBUp, UBUp, GlobalColor("Cloud Up"), GlobalColor("Cloud Dn"));
AddCloud(LBDn, UBDn, GlobalColor("Cloud Dn"), GlobalColor("Cloud Up"));
AddCloud(MBUp, UBUp, GlobalColor("Cloud_Up"), GlobalColor("Cloud_Dn"));
AddCloud(MBDn, UBDn, GlobalColor("Cloud_Dn"), GlobalColor("Cloud_Up"));


plot lineGTT = GTT;
lineGTT.AssignValueColor(if lineGTT> lineGTT[1] then Color.GREEN else if lineGTT <lineGTT[1] then Color.MAGENTA else color.light_gray);
lineGTT.SetLineWeight(3);
plot LineLowe25 = LOW25;
LineLowe25.AssignValueColor(if LineLowe25> LineLowe25[1] then Color.light_GREEN else if LineLowe25 <LineLowe25[1] then Color.light_red else color.yellow);
LineLowe25.SetLineWeight(3);
plot LineTarget = TARGET;
LineTarget.AssignValueColor(if LineTarget> LineTarget[1] then Color.dark_GREEN else if LineTarget<LineTarget[1] then Color.red else color.white);
LineTarget.SetLineWeight(4);


script nz {
    input data = 0;
    def ret_val = if IsNaN(data) then 0 else data;
    plot return = ret_val;
}
def pdm = Max((srca - srca[1]), 0);
def mdm = Max((srca[1] - srca), 0);
def pdmS = ((1 - k) * nz(pdmS[1]) + k * pdm);
def mdmS = ((1 - k) * nz(mdmS[1]) + k * mdm);
def s = pdmS + mdmS;
def pdi = pdmS / s;
def mdi = mdmS / s;
def pdiS = ((1 - k) * nz(pdiS[1]) + k * pdi);
def mdiS = ((1 - k) * nz(mdiS[1]) + k * mdi);
def da = AbsValue(pdiS - mdiS);
def s1 = pdiS + mdiS;
def iS = ((1 - k) * nz(iS[1]) + k * da / s1);
def hhv = Highest(iS, la);
def llv = Lowest(iS, la);
def d1 = hhv - llv;
def vI = (iS - llv) / d1;
def vma = (1 - k * vI) * nz(vma[1]) + k * vI * src;
plot line = vma;
line.AssignValueColor(if line> line[1] then Color.GREEN else if line <line[1] then Color.MAGENTA else color.gray);
line.SetLineWeight(4);


script nz {
input data = 0;
input data2 = 0;
def ret_val = if IsNaN(data) then data2 else data;
plot return = ret_val;
}

script MTF_ATR {
    input Length = 12;
    input TF = AggregationPeriod.HOUR;
    input averageType = AverageType.WILDERS;
    plot ATR =
        MovingAverage(
            averageType,
            TrueRange(
                high(period = TF),
                close(period = TF),
                low(period = TF)
            ),
            Length
        )
    ;
}
def Up = hl2 - (Factor * ATR(ATR));
def Dn = hl2 + (Factor * ATR(ATR));

def TUp = if close[1] > TUp[1] then Max(Up, TUp[1]) else Up;
def TDown = if close[1] < TDown[1] then Min(Dn, TDown[1]) else Dn;

def Trend = if close > TDown[1] then 1 else if close < TUp[1] then -1 else nz(Trend[1],1);

def Tsl1 = if Trend == 1 then TUp else TDown;
def Tsl2 = if Trend == 1 then TDown else TUp;

plot p1 = Tsl1;
plot p2 = Tsl2;
p1.AssignValueColor(if p1 < p2  then Color.green else Color.magenta);
p1.SetLineWeight(1);
p2.AssignValueColor(if p1 < p2  then Color.green else Color.magenta);
p2.SetLineWeight(1);

AddCloud(p1,   p2,   Color.light_RED,   Color.light_GREEN);
 
Last edited:
Code:
def e = average(close)>midline;
def f = midline<average(close);

Should there be a length associated with the average? or can we just use a simple Close?
 
We do not need that. I tried it, and nothing changed.
Code:
def a = (UpperBand > UpperBand[1] and Midline > Midline[1]);
def b = (UpperBand < UpperBand[1] and LowerBand < LowerBand[1]);
def c1 = (UpperBand > UpperBand[1] and Midline > Midline[1]);
def d = (UpperBand < UpperBand[1] and midline < midline[1]);
def e = average(close)>midline;
def f = midline<average(close);

def Chg      =   If(a, 1, If(b, -1, 0));

In the present code "def a is the same as def c1"

shouldn't def A = (UpperBand > UpperBand[1] and LowerBand > LowerBand[1]);


the logic for def Chg a should be the opposite of B
 
Thank you very much for your reminder. I did that. But nothing changes.
I also made following changes, but nothing changes.
def c1 = (lowerBand < lowerBand[1] and Midline < Midline[1]);
def c1 = (lowerBand > lowerBand[1] and Midline > Midline[1]);




Ruby:
#Heiken_Ashi based on Sylvan Verboort's Trading with HA Candlestick Oscillator
#Bon Bon _last update Jan 17th 2021
# © deepphalke
#https://www.tradingview.com/script/lEuCw5DS-JNSAR-DP/
#https://usethinkscript.com/threads/heikin-ashi-candles-in-lower-section.10428/
#// beardcrack
#study(title="Modified DC for BLSH", shorttitle="BLSH Price Table", overlay=true)
#https://www.tradingview.com/script/MkrCvQ22-BLSH/
#https://usethinkscript.com/threads/double-supertrend-atr-for-thinkorswim.10986/
#https://www.tradingview.com/script/6Ix0E5Yr-Variable-Moving-Average-LazyBear/
declare lower;

def srca = close;
def la = 6;
def std = no;
def bc = no;
def k = 1.0 / la;
def Factor = 3;
def ATR = 12;
input period = 1;
input hideCandles = no;
input candleSmoothing = {default Valcu, Vervoort};
input show_bubble_labels = yes;
input bubbles = yes;
input arrows = yes;
def src = hl2;
input displace = 0;
def len = 6;
def w = 4;
def h = high;
def l = low;
def c = close;
input movingAverageType = {default  TEMA, Exponential, Hull };
def length = 25;
def profit = 5;
def openMA;
def closeMA;
def highMA;
def lowMA;
def LOW25 = lowest(low, length);
def GTT = LOW25*1.05;
def TARGET = GTT*1.05;
switch (movingAverageType) {
case Exponential:
    openMA = CompoundValue(1, ExpAverage(open, period), open);
    closeMA = CompoundValue(1, ExpAverage(close, period), close);
    highMA = CompoundValue(1, ExpAverage(high, period), high);
    lowMA = CompoundValue(1, ExpAverage(low, period), low);
case Hull:
    openMA = CompoundValue(1, HullMovingAvg(open, period), open);
    closeMA = CompoundValue(1,  HullMovingAvg(close, period), close);
    highMA = CompoundValue(1,  HullMovingAvg(high, period), high);
    lowMA = CompoundValue(1,  HullMovingAvg(low, period), low);
case TEMA:
    openMA = CompoundValue(1, TEMA(open, period), open);
    closeMA = CompoundValue(1, TEMA(close, period), close);
    highMA = CompoundValue(1, TEMA(high, period), high);
    lowMA = CompoundValue(1, TEMA(low, period), low);

}


HidePricePlot(hideCandles);

def haOpen;
def haClose;

switch (candleSmoothing){
case Valcu:
    haOpen = CompoundValue(1, ( (haOpen[1] + (openMA[1] + highMA[1] + lowMA[1] + closeMA[1]) / 4.0) / 2.0), open);
    haClose = ((((openMA + highMA + lowMA + closeMA) / 4.0) + haOpen + Max(highMA, haOpen) + Min(lowMA, haOpen)) / 4.0);
case Vervoort:
    haOpen = CompoundValue(1, ( (haOpen[1] + (openMA[1] + highMA[1] + lowMA[1] + closeMA[1]) / 4.0 ) / 2.0), open);
    haClose = ((((openMA + highMA + lowMA + closeMA) / 4.0) + haOpen + Max(highMA, haOpen) + Min(lowMA, haOpen)) / 4.0);

}

plot o = haOpen;
o.AssignValueColor(if o > o[1] then Color.cyan else if o < o[1] then Color.magenta else color.gray);
o.SetLineWeight (5);
o.Hide();

def haLow =  Min(lowMA, haOpen);
def haHigh = Max(highMA, haOpen);

def avg = 34;
def TMA1 = reference TEMA(haClose, avg); # triple exponential moving average (TEMA) of 34 bars
def TMA2 =  reference TEMA(TMA1, avg);
def Diff = TMA1 - TMA2;
def ZlHa = TMA1 + Diff; #Zero-lagging TEMA average on closing prices - medium term uptrend;


def TMA1_ = reference TEMA((high + low) / 2, avg);
def Diff2 = TMA1_ - TMA2;
def ZlCl = TMA1_ + Diff2; #Zero-lagging TEMA average on closing prices - medium term doenwardtrend;

def ZlDif = ZlCl - ZlHa; # Zero-Lag close - Zero-Lag HA(green candle) Uptrend when ZlDif is equal to or greater than zero

def keep1 = if (haClose >= haOpen and haClose[1] >= haOpen[1]) then 1 else 0;
def keep2 = if ZlDif >= 0 then 1 else 0;
def keep3 = if (AbsValue(close - open) < ((high - low) * 0.35)) and high >= low[1] then 1 else 0;
def keeping = if (keep1 or keep2) then 1 else 0;
def keepall = if keeping or (keeping[1]) and close >= open or close >= (close[1]) then 1 else 0;

def utr = if keepall or (keepall[1]) and keep3 then 1 else 0;


def keep1_ = if (haClose < haOpen and haClose[1] < haOpen[1]) then 1 else 0;
def keep2_ = if ZlDif < 0 then 1 else 0;
def keep3_ = if (AbsValue(close - open) < ((high - low) * 0.35)) and low <= high[1] then 1 else 0;
def keeping_ = if (keep1_ or keep2_) then 1 else 0;
def dkeepall_ = if keeping_ or (keeping_[1]) and close < open or close < (close[1]) then 1 else 0;

def dtr = if dkeepall_ or (dkeepall_[1] - 1) and keep3_ == 1 then 1 else 0;  #downtrend
def upw = if dtr and (dtr[1]) and utr then 1 else 0;
def dnw = if !utr and (utr[1] ) and dtr then 1 else 0;

def results = if upw then 1 else if dnw then 0 else results[1];


input charttype = ChartType.CANDLE;

def haopen_ = if haClose <= haOpen
              then haOpen + 0
             else Double.NaN;

def HAhi   = if haClose <= haOpen
              then haHigh
              else Double.NaN;

def HAlo =   if haClose <= haOpen
              then haLow
              else Double.NaN;


AddChart(growColor = Color.red, neutralColor = Color.CURRENT, high = HAhi, low = HAlo, open = haopen_, close = haClose, type = ChartType.CANDLE);

def HAclose1 = ohlc4;
def HAopen1  = if haClose >= haOpen
               then CompoundValue(1, (haOpen[1] + haClose[1]) / 2, (open[1] + close[1]) / 2)
               else Double.NaN;

def haopen_1 = if haOpen <= haClose
               then HAopen1 + 0  else Double.NaN;

def HAhigh1  = haHigh;
def HAlow1   = haLow;


AddChart(growColor = Color.green, neutralColor = Color.CURRENT,  high = HAhigh1, low = HAlow1, open = haopen_1, close = haClose, type = ChartType.CANDLE);

def LinReg = Inertia(src[-displace], len);

def LinReg1 = Inertia(h, 5);
def LinReg2 = Inertia(l, 5);
def LinReg3 = Inertia(c, 5);
def avg1 = (LinReg1+ LinReg2 + LinReg3 + Inertia(h[1], 5)+ Inertia(l[1], 5)+ Inertia(c[1], 5)+ Inertia(h[2], 5)+ Inertia(l[2], 5)+ Inertia(c[2], 5)+ Inertia(h[3], 5)+ Inertia(l[3], 5)+ Inertia(c[3], 5)+ Inertia(h[4], 5)+ Inertia(l[4], 5)+ Inertia(c[4], 5))/15;

plot Upperband = LinReg1;
Upperband.DefineColor("UpTrend", Color.GREEN);
Upperband.DefineColor("DownTrend", Color.RED);
Upperband.SetLineWeight(1);
Upperband.SetPaintingStrategy(PaintingStrategy.LINE);
Upperband.SetStyle(Curve.FIRM);
Upperband.AssignValueColor(if Upperband > Upperband [1] then Upperband.Color("UpTrend") else Upperband.Color("DownTrend"));
plot lowerband = LinReg2;
lowerband.DefineColor("UpTrend", Color.GREEN);
lowerband.DefineColor("DownTrend", Color.RED);
lowerband.SetLineWeight(1);
lowerband.SetPaintingStrategy(PaintingStrategy.LINE);
lowerband.SetStyle(Curve.FIRM);
lowerband.AssignValueColor(if lowerband  > lowerband  [1] then lowerband.Color("UpTrend") else lowerband.Color("DownTrend"));
Plot midline = LinReg3;
midline.DefineColor("UpTrend", Color.GREEN);
midline.DefineColor("DownTrend", Color.RED);
midline.SetLineWeight(1);
midline.SetPaintingStrategy(PaintingStrategy.LINE);
midline.SetStyle(Curve.FIRM);
midline.AssignValueColor(if midline >midline [1] then midline.Color("UpTrend") else midline.Color("DownTrend"));
input fill = yes;
def nan  =  Double.NaN;
plot LineAvg = avg1;
LineAvg.DefineColor("UpTrend", Color.GREEN);
LineAvg.DefineColor("DownTrend", Color.RED);
LineAvg.SetLineWeight(3);
LineAvg.SetPaintingStrategy(PaintingStrategy.LINE);
LineAvg.SetStyle(Curve.FIRM);
LineAvg.AssignValueColor(if LineAvg  > LineAvg [1] then LineAvg.Color("UpTrend") else LineAvg.Color("DownTrend"));

def a = (UpperBand > UpperBand[1] and Midline > Midline[1]);
def b = (UpperBand < UpperBand[1] and LowerBand < LowerBand[1]);
def c1 = (UpperBand > UpperBand[1] and Midline < Midline[1]);
def d = (UpperBand < UpperBand[1] and midline < midline[1]);
def e = average(close)>midline;
def f = midline<average(close);

def Chg      =   If(a, 1, If(b, -1, 0));
def Hold     =   CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
def Chg_a      =   If((c1 or e), 1, If((d or f), -1, 0));
def Hold_a     =   CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
def LBUp     =   if fill and Hold[0] == 1 then lowerBand else nan;
def UBUp     =   if fill and Hold[0] == 1 then upperband else nan;
def LBDn     =   if fill and Hold[0] == -1 then lowerband else nan;
def UBDn     =   if fill and Hold[0] == -1 then upperband else nan;
def MBUP     =   if fill and Hold[0] == 1 then midline else nan;
def MBDn     =   if fill and Hold[0] == -1 then Midline else nan;

DefineGlobalColor("Cloud Up", Color.red);
DefineGlobalColor("Cloud_Up", Color.downtick);
DefineGlobalColor("Cloud_Dn", Color.light_green);
DefineGlobalColor("Cloud Dn", Color.cyan);
AddCloud(LBUp, UBUp, GlobalColor("Cloud Up"), GlobalColor("Cloud Dn"));
AddCloud(LBDn, UBDn, GlobalColor("Cloud Dn"), GlobalColor("Cloud Up"));
AddCloud(MBUp, UBUp, GlobalColor("Cloud_Up"), GlobalColor("Cloud_Dn"));
AddCloud(MBDn, UBDn, GlobalColor("Cloud_Dn"), GlobalColor("Cloud_Up"));


plot lineGTT = GTT;
lineGTT.AssignValueColor(if lineGTT> lineGTT[1] then Color.GREEN else if lineGTT <lineGTT[1] then Color.MAGENTA else color.light_gray);
lineGTT.SetLineWeight(3);
plot LineLowe25 = LOW25;
LineLowe25.AssignValueColor(if LineLowe25> LineLowe25[1] then Color.light_GREEN else if LineLowe25 <LineLowe25[1] then Color.light_red else color.yellow);
LineLowe25.SetLineWeight(3);
plot LineTarget = TARGET;
LineTarget.AssignValueColor(if LineTarget> LineTarget[1] then Color.dark_GREEN else if LineTarget<LineTarget[1] then Color.red else color.white);
LineTarget.SetLineWeight(4);


script nz {
    input data = 0;
    def ret_val = if IsNaN(data) then 0 else data;
    plot return = ret_val;
}
def pdm = Max((srca - srca[1]), 0);
def mdm = Max((srca[1] - srca), 0);
def pdmS = ((1 - k) * nz(pdmS[1]) + k * pdm);
def mdmS = ((1 - k) * nz(mdmS[1]) + k * mdm);
def s = pdmS + mdmS;
def pdi = pdmS / s;
def mdi = mdmS / s;
def pdiS = ((1 - k) * nz(pdiS[1]) + k * pdi);
def mdiS = ((1 - k) * nz(mdiS[1]) + k * mdi);
def da = AbsValue(pdiS - mdiS);
def s1 = pdiS + mdiS;
def iS = ((1 - k) * nz(iS[1]) + k * da / s1);
def hhv = Highest(iS, la);
def llv = Lowest(iS, la);
def d1 = hhv - llv;
def vI = (iS - llv) / d1;
def vma = (1 - k * vI) * nz(vma[1]) + k * vI * src;
plot line = vma;
line.AssignValueColor(if line> line[1] then Color.GREEN else if line <line[1] then Color.MAGENTA else color.gray);
line.SetLineWeight(4);


script nz {
input data = 0;
input data2 = 0;
def ret_val = if IsNaN(data) then data2 else data;
plot return = ret_val;
}

script MTF_ATR {
    input Length = 12;
    input TF = AggregationPeriod.HOUR;
    input averageType = AverageType.WILDERS;
    plot ATR =
        MovingAverage(
            averageType,
            TrueRange(
                high(period = TF),
                close(period = TF),
                low(period = TF)
            ),
            Length
        )
    ;
}
def Up = hl2 - (Factor * ATR(ATR));
def Dn = hl2 + (Factor * ATR(ATR));

def TUp = if close[1] > TUp[1] then Max(Up, TUp[1]) else Up;
def TDown = if close[1] < TDown[1] then Min(Dn, TDown[1]) else Dn;

def Trend = if close > TDown[1] then 1 else if close < TUp[1] then -1 else nz(Trend[1],1);

def Tsl1 = if Trend == 1 then TUp else TDown;
def Tsl2 = if Trend == 1 then TDown else TUp;

plot p1 = Tsl1;
plot p2 = Tsl2;
p1.AssignValueColor(if p1 < p2  then Color.green else Color.magenta);
p1.SetLineWeight(1);
p2.AssignValueColor(if p1 < p2  then Color.green else Color.magenta);
p2.SetLineWeight(1);

AddCloud(p1,   p2,   Color.light_RED,   Color.light_GREEN);
 
Last edited:
In the present code "def a is the same as def c1"

shouldn't def A = (UpperBand > UpperBand[1] and LowerBand > LowerBand[1]);


the logic for def Chg a should be the opposite of B
One last question
Code:
def Chg      =   If(a, 1, If(b, -1, 0));
def Hold     =   CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
def Chg_a      =   If((c1 or e), 1, If((d or f), -1, 0));
def Hold_a     =   CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);

your def of Chg_a and Hold_a are not factored in since they are not mentioned again



def Chg = If((A or c1 or e), 1, If((B or d or f), -1, 0));
def Hold = CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
 
One last question
Code:
def Chg      =   If(a, 1, If(b, -1, 0));
def Hold     =   CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
def Chg_a      =   If((c1 or e), 1, If((d or f), -1, 0));
def Hold_a     =   CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);

your def of Chg_a and Hold_a are not factored in since they are not mentioned again



def Chg = If((A or c1 or e), 1, If((B or d or f), -1, 0));
def Hold = CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
I used your code to replace my code. The trend colors disappeared. The uptrend and downtrend show the same band color. At this stage, my present code functions well to show right color changes to follow the trend changes. Thank you very much for your suggestion.
 
Last edited:
I used your code to replace my code. The trend colors disappeared. The uptrend and downtrend show the same band color. At this stage, my present code functions well to show right color changes to follow the trend changes. Thank you very much for your suggestion.
did you comment out the following Lines ?

#def Chg_a = If((c1 or e), 1, If((d or f), -1, 0));
#def Hold_a = CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
 
JNSAR_DP_Buttered
Code:
def h = high;
def l = low;
def c = close;
def R1h = high[1];
def R1l = low[1];
def R1c = close[1];
def R2h = high[2];
def R2l = low[2];
def R2c = close[2];
def R3h = high[3];
def R3l = low[3];
def R3c = close[3];
def R4h = high[4];
def R4l = low[4];
def R4c = close[4];
def a1A = exp(-1.414 * 3.14159 / 5);
def b1A = 2 * a1A * Cos(1.414 * 3.14159 / 5);
def coef2A =b1A;
def coef3A = -a1A * a1A;
def coef1A = (1 – b1A + a1A * a1A) / 4;
rec BAH = if barNumber() < 3 then h else coef1A * (h + 2 * h[1] + h[2]) + coef2A * BAH[1] + coef3A * BAH[2];
rec BAL = if barNumber() < 3 then l else coef1A * (l + 2 * l[1] + l[2]) + coef2A * BAL[1] + coef3A * BAL[2];
rec BAC = if barNumber() < 3 then c else coef1A * (c + 2 * c[1] + c[2]) + coef2A * BAC[1] + coef3A * BAC[2];
rec BAR1H = if barNumber() < 3 then R1h else coef1A * (R1h + 2 * R1h[1] + R1h[2]) + coef2A * BAR1H[1] + coef3A * BAR1H[2];
rec BAR1L = if barNumber() < 3 then R1l else coef1A * (R1l + 2 * R1l[1] + R1l[2]) + coef2A * BAR1L[1] + coef3A * BAR1L[2];
rec BAR1C = if barNumber() < 3 then R1c else coef1A * (R1c + 2 * R1c[1] + R1c[2]) + coef2A * BAR1C[1] + coef3A * BAR1C[2];
rec BAR2H = if barNumber() < 3 then R2h else coef1A * (R2h + 2 * R2h[1] + R2h[2]) + coef2A * BAR2H[1] + coef3A * BAR2H[2];
rec BAR2L = if barNumber() < 3 then R2l else coef1A * (R2l + 2 * R2l[1] + R2l[2]) + coef2A * BAR2L[1] + coef3A * BAR2L[2];
rec BAR2C = if barNumber() < 3 then R2c else coef1A * (R2c + 2 * R2c[1] + R2c[2]) + coef2A * BAR2C[1] + coef3A * BAR2C[2];
rec BAR3H = if barNumber() < 3 then R3h else coef1A * (R3h + 2 * R3h[1] + R3h[2]) + coef2A * BAR3H[1] + coef3A * BAR1H[2];
rec BAR3L = if barNumber() < 3 then R3l else coef1A * (R3l + 2 * R3l[1] + R3l[2]) + coef2A * BAR3L[1] + coef3A * BAR1L[2];
rec BAR3C = if barNumber() < 3 then R3c else coef1A * (R3c + 2 * R3c[1] + R3c[2]) + coef2A * BAR3C[1] + coef3A * BAR3C[2];
rec BAR4H = if barNumber() < 3 then R4h else coef1A * (R4h + 2 * R4h[1] + R4h[2]) + coef2A * BAR4H[1] + coef3A * BAR4H[2];
rec BAR4L = if barNumber() < 3 then R4l else coef1A * (R4l + 2 * R4l[1] + R4l[2]) + coef2A * BAR4L[1] + coef3A * BAR4L[2];
rec BAR4C = if barNumber() < 3 then R4c else coef1A * (R4c + 2 * R4c[1] + R4c[2]) + coef2A * BAR4C[1] + coef3A * BAR4C[2];
def BAVG = (BAH +BAL +BAC +BAR1H +BAR1L +BAR1C + BAR2H +BAR2L +BAR2C + BAR3H +BAR3L +BAR3C + BAR4H +BAR4L +BAR4C )/15;
plot Upperband = BAH;
Upperband.DefineColor("UpTrend", Color.GREEN);
Upperband.DefineColor("DownTrend", Color.RED);
Upperband.SetLineWeight(1);
Upperband.SetPaintingStrategy(PaintingStrategy.LINE);
Upperband.SetStyle(Curve.FIRM);
Upperband.AssignValueColor(if Upperband > Upperband [1] then Upperband.Color("UpTrend") else Upperband.Color("DownTrend"));
plot lowerband = BAL;
lowerband.DefineColor("UpTrend", Color.GREEN);
lowerband.DefineColor("DownTrend", Color.RED);
lowerband.SetLineWeight(1);
lowerband.SetPaintingStrategy(PaintingStrategy.LINE);
lowerband.SetStyle(Curve.FIRM);
lowerband.AssignValueColor(if lowerband  > lowerband  [1] then lowerband.Color("UpTrend") else lowerband.Color("DownTrend"));
Plot midline = BAC;
midline.DefineColor("UpTrend", Color.GREEN);
midline.DefineColor("DownTrend", Color.RED);
midline.SetLineWeight(1);
midline.SetPaintingStrategy(PaintingStrategy.LINE);
midline.SetStyle(Curve.FIRM);
midline.AssignValueColor(if midline >midline [1] then midline.Color("UpTrend") else midline.Color("DownTrend"));
input fill = yes;
def nan  =  Double.NaN;
plot LineAvg = BAVG;
LineAvg.DefineColor("UpTrend", Color.GREEN);
LineAvg.DefineColor("DownTrend", Color.RED);
LineAvg.SetLineWeight(3);
LineAvg.SetPaintingStrategy(PaintingStrategy.LINE);
LineAvg.SetStyle(Curve.FIRM);
LineAvg.AssignValueColor(if LineAvg  > LineAvg [1] then LineAvg.Color("UpTrend") else LineAvg.Color("DownTrend"));

def a = (UpperBand > UpperBand[1] and LowerBand > LowerBand[1]);
def b = (UpperBand < UpperBand[1] and LowerBand < LowerBand[1]);
def c1 = (UpperBand > UpperBand[1] and Midline > Midline[1]);
def d = (UpperBand < UpperBand[1] and Midline < Midline[1]);
def e = C>Midline;
def f = Midline<C;

def Chg      =   If(a or c1 or e, 1, If(b or D or F, -1, 0));
def Hold     =   CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
#def Chg_a      =   If((c1 or e), 1, If((d or f), -1, 0));
#def Hold_a     =   CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
def LBUp     =   if fill and Hold[0] == 1 then lowerBand else nan;
def UBUp     =   if fill and Hold[0] == 1 then upperband else nan;
def LBDn     =   if fill and Hold[0] == -1 then lowerband else nan;
def UBDn     =   if fill and Hold[0] == -1 then upperband else nan;
def MBUP     =   if fill and Hold[0] == 1 then midline else nan;
def MBDn     =   if fill and Hold[0] == -1 then Midline else nan;

DefineGlobalColor("Cloud Up", Color.red);
DefineGlobalColor("Cloud_Up", Color.downtick);
DefineGlobalColor("Cloud_Dn", Color.light_green);
DefineGlobalColor("Cloud Dn", Color.cyan);
AddCloud(LBUp, UBUp, GlobalColor("Cloud Up"), GlobalColor("Cloud Dn"));
AddCloud(LBDn, UBDn, GlobalColor("Cloud Dn"), GlobalColor("Cloud Up"));
AddCloud(MBUp, UBUp, GlobalColor("Cloud_Up"), GlobalColor("Cloud_Dn"));
AddCloud(MBDn, UBDn, GlobalColor("Cloud_Dn"), GlobalColor("Cloud_Up"));

using a 2 pole Butterworth Filter
 
JNSAR_DP_Buttered
Code:
def h = high;
def l = low;
def c = close;
def R1h = high[1];
def R1l = low[1];
def R1c = close[1];
def R2h = high[2];
def R2l = low[2];
def R2c = close[2];
def R3h = high[3];
def R3l = low[3];
def R3c = close[3];
def R4h = high[4];
def R4l = low[4];
def R4c = close[4];
def a1A = exp(-1.414 * 3.14159 / 5);
def b1A = 2 * a1A * Cos(1.414 * 3.14159 / 5);
def coef2A =b1A;
def coef3A = -a1A * a1A;
def coef1A = (1 – b1A + a1A * a1A) / 4;
rec BAH = if barNumber() < 3 then h else coef1A * (h + 2 * h[1] + h[2]) + coef2A * BAH[1] + coef3A * BAH[2];
rec BAL = if barNumber() < 3 then l else coef1A * (l + 2 * l[1] + l[2]) + coef2A * BAL[1] + coef3A * BAL[2];
rec BAC = if barNumber() < 3 then c else coef1A * (c + 2 * c[1] + c[2]) + coef2A * BAC[1] + coef3A * BAC[2];
rec BAR1H = if barNumber() < 3 then R1h else coef1A * (R1h + 2 * R1h[1] + R1h[2]) + coef2A * BAR1H[1] + coef3A * BAR1H[2];
rec BAR1L = if barNumber() < 3 then R1l else coef1A * (R1l + 2 * R1l[1] + R1l[2]) + coef2A * BAR1L[1] + coef3A * BAR1L[2];
rec BAR1C = if barNumber() < 3 then R1c else coef1A * (R1c + 2 * R1c[1] + R1c[2]) + coef2A * BAR1C[1] + coef3A * BAR1C[2];
rec BAR2H = if barNumber() < 3 then R2h else coef1A * (R2h + 2 * R2h[1] + R2h[2]) + coef2A * BAR2H[1] + coef3A * BAR2H[2];
rec BAR2L = if barNumber() < 3 then R2l else coef1A * (R2l + 2 * R2l[1] + R2l[2]) + coef2A * BAR2L[1] + coef3A * BAR2L[2];
rec BAR2C = if barNumber() < 3 then R2c else coef1A * (R2c + 2 * R2c[1] + R2c[2]) + coef2A * BAR2C[1] + coef3A * BAR2C[2];
rec BAR3H = if barNumber() < 3 then R3h else coef1A * (R3h + 2 * R3h[1] + R3h[2]) + coef2A * BAR3H[1] + coef3A * BAR1H[2];
rec BAR3L = if barNumber() < 3 then R3l else coef1A * (R3l + 2 * R3l[1] + R3l[2]) + coef2A * BAR3L[1] + coef3A * BAR1L[2];
rec BAR3C = if barNumber() < 3 then R3c else coef1A * (R3c + 2 * R3c[1] + R3c[2]) + coef2A * BAR3C[1] + coef3A * BAR3C[2];
rec BAR4H = if barNumber() < 3 then R4h else coef1A * (R4h + 2 * R4h[1] + R4h[2]) + coef2A * BAR4H[1] + coef3A * BAR4H[2];
rec BAR4L = if barNumber() < 3 then R4l else coef1A * (R4l + 2 * R4l[1] + R4l[2]) + coef2A * BAR4L[1] + coef3A * BAR4L[2];
rec BAR4C = if barNumber() < 3 then R4c else coef1A * (R4c + 2 * R4c[1] + R4c[2]) + coef2A * BAR4C[1] + coef3A * BAR4C[2];
def BAVG = (BAH +BAL +BAC +BAR1H +BAR1L +BAR1C + BAR2H +BAR2L +BAR2C + BAR3H +BAR3L +BAR3C + BAR4H +BAR4L +BAR4C )/15;
plot Upperband = BAH;
Upperband.DefineColor("UpTrend", Color.GREEN);
Upperband.DefineColor("DownTrend", Color.RED);
Upperband.SetLineWeight(1);
Upperband.SetPaintingStrategy(PaintingStrategy.LINE);
Upperband.SetStyle(Curve.FIRM);
Upperband.AssignValueColor(if Upperband > Upperband [1] then Upperband.Color("UpTrend") else Upperband.Color("DownTrend"));
plot lowerband = BAL;
lowerband.DefineColor("UpTrend", Color.GREEN);
lowerband.DefineColor("DownTrend", Color.RED);
lowerband.SetLineWeight(1);
lowerband.SetPaintingStrategy(PaintingStrategy.LINE);
lowerband.SetStyle(Curve.FIRM);
lowerband.AssignValueColor(if lowerband  > lowerband  [1] then lowerband.Color("UpTrend") else lowerband.Color("DownTrend"));
Plot midline = BAC;
midline.DefineColor("UpTrend", Color.GREEN);
midline.DefineColor("DownTrend", Color.RED);
midline.SetLineWeight(1);
midline.SetPaintingStrategy(PaintingStrategy.LINE);
midline.SetStyle(Curve.FIRM);
midline.AssignValueColor(if midline >midline [1] then midline.Color("UpTrend") else midline.Color("DownTrend"));
input fill = yes;
def nan  =  Double.NaN;
plot LineAvg = BAVG;
LineAvg.DefineColor("UpTrend", Color.GREEN);
LineAvg.DefineColor("DownTrend", Color.RED);
LineAvg.SetLineWeight(3);
LineAvg.SetPaintingStrategy(PaintingStrategy.LINE);
LineAvg.SetStyle(Curve.FIRM);
LineAvg.AssignValueColor(if LineAvg  > LineAvg [1] then LineAvg.Color("UpTrend") else LineAvg.Color("DownTrend"));

def a = (UpperBand > UpperBand[1] and LowerBand > LowerBand[1]);
def b = (UpperBand < UpperBand[1] and LowerBand < LowerBand[1]);
def c1 = (UpperBand > UpperBand[1] and Midline > Midline[1]);
def d = (UpperBand < UpperBand[1] and Midline < Midline[1]);
def e = C>Midline;
def f = Midline<C;

def Chg      =   If(a or c1 or e, 1, If(b or D or F, -1, 0));
def Hold     =   CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
#def Chg_a      =   If((c1 or e), 1, If((d or f), -1, 0));
#def Hold_a     =   CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
def LBUp     =   if fill and Hold[0] == 1 then lowerBand else nan;
def UBUp     =   if fill and Hold[0] == 1 then upperband else nan;
def LBDn     =   if fill and Hold[0] == -1 then lowerband else nan;
def UBDn     =   if fill and Hold[0] == -1 then upperband else nan;
def MBUP     =   if fill and Hold[0] == 1 then midline else nan;
def MBDn     =   if fill and Hold[0] == -1 then Midline else nan;

DefineGlobalColor("Cloud Up", Color.red);
DefineGlobalColor("Cloud_Up", Color.downtick);
DefineGlobalColor("Cloud_Dn", Color.light_green);
DefineGlobalColor("Cloud Dn", Color.cyan);
AddCloud(LBUp, UBUp, GlobalColor("Cloud Up"), GlobalColor("Cloud Dn"));
AddCloud(LBDn, UBDn, GlobalColor("Cloud Dn"), GlobalColor("Cloud Up"));
AddCloud(MBUp, UBUp, GlobalColor("Cloud_Up"), GlobalColor("Cloud_Dn"));
AddCloud(MBDn, UBDn, GlobalColor("Cloud_Dn"), GlobalColor("Cloud_Up"));

using a 2 pole Butterworth Filter
henry1224, Thank you very much for providing an alternative approach. It seems that your method is more sensitive to the price changes. Therefore, it sometime generates false buy signals in downtrends for swing trades before the market reaches the bottom.
 
Last edited by a moderator:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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