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/
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: