Count MoBo Band Bars Watchlist

clickchamps

New member
Can any assist me in writing a CustomScript to put in a watchlist that would count the number of bars the Mobo Band has turn Green or Red. Right now I can get a count if stays outside the bands but once it goes inside it goes to 0 and restarts when it goes outside in the direction of the trend, other it goes to count as expect on the breakout on the other side but reset to 0 on a visit back into the band.


Its a lot of extra code from a Mobo Study I found here
https://usethinkscript.com/threads/momentum-bollinger-band-channels-for-thinkorswim.5977/

---------------------------------------------------------------------------------------

#Momentum Bollinger band channel v1.0 by XeoNoX via usethinkscript.com
#Request 03-16-2021
#Based of Pensar's Keltner channel Momentum bands via usethinkscript.com
#which is based on FW-MOBO-Advanced https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/E-F/FW-MOBO-Advanced
#Inputs
input factor = 1;
input price = close;
input type = AverageType.simple;
input pricecolor = yes;
input fill = yes;
input arrows = yes;
input alerts = yes;
input sound = {default "Ding", "Bell", "Chimes", "NoSound", "Ring"};
input displace = 0;
input length = 13;
input Num_Dev_Dn = -.8;
input Num_Dev_up = .8;
input averageType = AverageType.simple;



def sDev = StDev(data = price[-displace], length = length);

#Variables
def nan = Double.NaN;
def shift = factor * MovingAverage(type, TrueRange(high, close, low), length);
plot avg = MovingAverage(averageType, data = price[-displace], length = length);
def line1 = avg + Num_Dev_Dn * sDev;
def line2 = avg + Num_Dev_up * sDev;
def Chg = If(close > line2, 1, If(close < line1, -1, 0));
def Hold = CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
def ArUp = if !arrows or Hold[0] == Hold[1] then nan else if Hold[0] == 1 then line1 else nan;
def ArDn = if !arrows or Hold[0] == Hold[1] then nan else if Hold[0] == -1 then line2 else nan;
def LBUp = if fill and Hold[0] == 1 then line2 else nan;
def UBUp = if fill and Hold[0] == 1 then line1 else nan;
def LBDn = if fill and Hold[0] == -1 then line2 else nan;
def UBDn = if fill and Hold[0] == -1 then line1 else nan;
def AlertUp = alerts and Hold[1] == 1 and (Hold[1] <> Hold[2]);
def AlertDn = alerts and Hold[1] == -1 and (Hold[1] <> Hold[2]);

#Colors
DefineGlobalColor("Cloud Up", Color.DARK_GREEN);
DefineGlobalColor("Cloud Dn", Color.DARK_RED);
DefineGlobalColor("Channel Up", Color.Dark_Gray);
DefineGlobalColor("Channel Down", Color.dark_gray);
DefineGlobalColor("Price Up", Color.GREEN);
DefineGlobalColor("Price Neutral", Color.GRAY);
DefineGlobalColor("Price Down", Color.RED);


#Clouds
AddCloud(LBUp, UBUp, GlobalColor("Cloud Up"), GlobalColor("Cloud Dn"));
AddCloud(LBDn, UBDn, GlobalColor("Cloud Dn"), GlobalColor("Cloud Up"));

#Price Color
AssignPriceColor(if pricecolor then if close > line2 and close > open then GlobalColor("Price Up")
else if close > line2 and close < open then color.dark_green
else if close < line1 and close < open then GlobalColor("Price Down")
else if Close < line1 and close > open then color.dark_RED
else if close > open then color.white
else GlobalColor ("Price Neutral")
else Color.CURRENT);

#Alerts
Alert(AlertUp, "BREAKOUT!", Alert.BAR, Sound);
Alert(AlertDn, "BREAKDOWN!", Alert.BAR, Sound);


def barUp = chg==1;
def barDown = chg==-1;
def barUpCount = CompoundValue(1, if barUp then barUpCount[1] + 1 else 0, 0);
def pBarUpCount = if barUpCount > 0 then barUpCount else nan;
def barDownCount = CompoundValue(1, if bardown then barDownCount[1] - 1 else 0, 0);
def pBarDownCount = if barDownCount < 0 then barDownCount else nan;

AddLabel(yes, (Round(barDownCount + barUpCount, 1)), if barUpCount > 1 then Color.GREEN else if barDownCount < -1 then Color.RED else color.blue);

#AssignBackgroundColor( if BarUp and barUpCount >= 2 then Color.dark_GRAY else if bardownCount #<= -2 then Color.plum else if BarUp and barUpCount < 2 then Color.dark_Green else if BarDown #and barDownCount > -2 then Color.Red else color.black);

AssignBackgroundColor( if Close < Line1 then Color.plum else if close > line1 and close < avg then color.magenta else if Close > Line2 then color.dark_green else if close < line2 and close > avg then color.lime else color.dark_gray)
 

Attachments

  • Mobo.jpg
    Mobo.jpg
    66.3 KB · Views: 209
  • Mobo.jpg
    Mobo.jpg
    66.3 KB · Views: 206
Last edited by a moderator:
Solution
@halcyonguy

You did jarr something and I did get to count corrently, for the Barcount I changed the counting varable to Hold[0] == 1.

Thank you for your help! I could not have done it without you code.


#Momentum Bollinger band channel v1.0 by XeoNoX via usethinkscript.com
#Request 03-16-2021
#Based of Pensar's Keltner channel Momentum bands via usethinkscript.com
#which is based on FW-MOBO-Advanced https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/E-F/FW-MOBO-Advanced
#Inputs
input factor = 1;
input price = close;
input type = AverageType.simple;
input pricecolor = yes;
input fill = yes;
input arrows = yes;
input alerts =...
Can any assist me in writing a CustomScript to put in a watchlist that would count the number of bars the Mobo Band has turn Green or Red. Right now I can get a count if stays outside the bands but once it goes inside it goes to 0 and restarts when it goes outside in the direction of the trend, other it goes to count as expect on the breakout on the other side but reset to 0 on a visit back into the band.


Its a lot of extra code from a Mobo Study I found here
https://usethinkscript.com/threads/momentum-bollinger-band-channels-for-thinkorswim.5977/

---------------------------------------------------------------------------------------

#Momentum Bollinger band channel v1.0 by XeoNoX via usethinkscript.com
#Request 03-16-2021
#Based of Pensar's Keltner channel Momentum bands via usethinkscript.com
#which is based on FW-MOBO-Advanced https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/E-F/FW-MOBO-Advanced
#Inputs
input factor = 1;
input price = close;
input type = AverageType.simple;
input pricecolor = yes;
input fill = yes;
input arrows = yes;
input alerts = yes;
input sound = {default "Ding", "Bell", "Chimes", "NoSound", "Ring"};
input displace = 0;
input length = 13;
input Num_Dev_Dn = -.8;
input Num_Dev_up = .8;
input averageType = AverageType.simple;



def sDev = StDev(data = price[-displace], length = length);

#Variables
def nan = Double.NaN;
def shift = factor * MovingAverage(type, TrueRange(high, close, low), length);
plot avg = MovingAverage(averageType, data = price[-displace], length = length);
def line1 = avg + Num_Dev_Dn * sDev;
def line2 = avg + Num_Dev_up * sDev;
def Chg = If(close > line2, 1, If(close < line1, -1, 0));
def Hold = CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
def ArUp = if !arrows or Hold[0] == Hold[1] then nan else if Hold[0] == 1 then line1 else nan;
def ArDn = if !arrows or Hold[0] == Hold[1] then nan else if Hold[0] == -1 then line2 else nan;
def LBUp = if fill and Hold[0] == 1 then line2 else nan;
def UBUp = if fill and Hold[0] == 1 then line1 else nan;
def LBDn = if fill and Hold[0] == -1 then line2 else nan;
def UBDn = if fill and Hold[0] == -1 then line1 else nan;
def AlertUp = alerts and Hold[1] == 1 and (Hold[1] <> Hold[2]);
def AlertDn = alerts and Hold[1] == -1 and (Hold[1] <> Hold[2]);

#Colors
DefineGlobalColor("Cloud Up", Color.DARK_GREEN);
DefineGlobalColor("Cloud Dn", Color.DARK_RED);
DefineGlobalColor("Channel Up", Color.Dark_Gray);
DefineGlobalColor("Channel Down", Color.dark_gray);
DefineGlobalColor("Price Up", Color.GREEN);
DefineGlobalColor("Price Neutral", Color.GRAY);
DefineGlobalColor("Price Down", Color.RED);


#Clouds
AddCloud(LBUp, UBUp, GlobalColor("Cloud Up"), GlobalColor("Cloud Dn"));
AddCloud(LBDn, UBDn, GlobalColor("Cloud Dn"), GlobalColor("Cloud Up"));

#Price Color
AssignPriceColor(if pricecolor then if close > line2 and close > open then GlobalColor("Price Up")
else if close > line2 and close < open then color.dark_green
else if close < line1 and close < open then GlobalColor("Price Down")
else if Close < line1 and close > open then color.dark_RED
else if close > open then color.white
else GlobalColor ("Price Neutral")
else Color.CURRENT);

#Alerts
Alert(AlertUp, "BREAKOUT!", Alert.BAR, Sound);
Alert(AlertDn, "BREAKDOWN!", Alert.BAR, Sound);


def barUp = chg==1;
def barDown = chg==-1;
def barUpCount = CompoundValue(1, if barUp then barUpCount[1] + 1 else 0, 0);
def pBarUpCount = if barUpCount > 0 then barUpCount else nan;
def barDownCount = CompoundValue(1, if bardown then barDownCount[1] - 1 else 0, 0);
def pBarDownCount = if barDownCount < 0 then barDownCount else nan;

AddLabel(yes, (Round(barDownCount + barUpCount, 1)), if barUpCount > 1 then Color.GREEN else if barDownCount < -1 then Color.RED else color.blue);

#AssignBackgroundColor( if BarUp and barUpCount >= 2 then Color.dark_GRAY else if bardownCount #<= -2 then Color.plum else if BarUp and barUpCount < 2 then Color.dark_Green else if BarDown #and barDownCount > -2 then Color.Red else color.black);

AssignBackgroundColor( if Close < Line1 then Color.plum else if close > line1 and close < avg then color.magenta else if Close > Line2 then color.dark_green else if close < line2 and close > avg then color.lime else color.dark_gray)


i made this upper study first, for testing.
i started with the code in post #1.

then modified it to be the 2nd study, a watchlist study.

test code
upper study

Code:
#count_mobo_colored_band_bars_0

#https://usethinkscript.com/threads/count-mobo-band-bars-watchlist.16855/
#Count MoBo Band Bars Watchlist
#clickchamps  10/4

#Can any assist me in writing a CustomScript to put in a watchlist that would count the number of bars the Mobo Band has turn Green or Red. Right now I can get a count if stays outside the bands but once it goes inside it goes to 0 and restarts when it goes outside in the direction of the trend, other it goes to count as expect on the breakout on the other side but reset to 0 on a visit back into the band.


#Its a lot of extra code from a Mobo Study I found here
#https://usethinkscript.com/threads/momentum-bollinger-band-channels-for-thinkorswim.5977/

#---------------------------------------------------------------------------------------

#Momentum Bollinger band channel v1.0 by XeoNoX via usethinkscript.com
#Request 03-16-2021
#Based of Pensar's Keltner channel Momentum bands via usethinkscript.com
#which is based on FW-MOBO-Advanced https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/E-F/FW-MOBO-Advanced
#Inputs
input factor = 1;
input price = close;
input type = AverageType.simple;
input pricecolor = yes;
input fill = yes;
input arrows = yes;
input alerts = yes;
input sound = {default "Ding", "Bell", "Chimes", "NoSound", "Ring"};
input displace = 0;
input length = 13;
input Num_Dev_Dn = -.8;
input Num_Dev_up = .8;
input averageType = AverageType.simple;

input color_background = no;



def sDev = StDev(data = price[-displace], length = length);

#Variables
def nan = Double.NaN;
def shift = factor * MovingAverage(type, TrueRange(high, close, low), length);
plot avg = MovingAverage(averageType, data = price[-displace], length = length);
def line1 = avg + Num_Dev_Dn * sDev;
def line2 = avg + Num_Dev_up * sDev;
def Chg = If(close > line2, 1, If(close < line1, -1, 0));
def Hold = CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
def ArUp = if !arrows or Hold[0] == Hold[1] then nan else if Hold[0] == 1 then line1 else nan;
def ArDn = if !arrows or Hold[0] == Hold[1] then nan else if Hold[0] == -1 then line2 else nan;
def LBUp = if fill and Hold[0] == 1 then line2 else nan;
def UBUp = if fill and Hold[0] == 1 then line1 else nan;
def LBDn = if fill and Hold[0] == -1 then line2 else nan;
def UBDn = if fill and Hold[0] == -1 then line1 else nan;
def AlertUp = alerts and Hold[1] == 1 and (Hold[1] <> Hold[2]);
def AlertDn = alerts and Hold[1] == -1 and (Hold[1] <> Hold[2]);

#Colors
DefineGlobalColor("Cloud Up", Color.DARK_GREEN);
DefineGlobalColor("Cloud Dn", Color.DARK_RED);
DefineGlobalColor("Channel Up", Color.Dark_Gray);
DefineGlobalColor("Channel Down", Color.dark_gray);
DefineGlobalColor("Price Up", Color.GREEN);
DefineGlobalColor("Price Neutral", Color.GRAY);
DefineGlobalColor("Price Down", Color.RED);


#Clouds
AddCloud(LBUp, UBUp, GlobalColor("Cloud Up"), GlobalColor("Cloud Dn"));
AddCloud(LBDn, UBDn, GlobalColor("Cloud Dn"), GlobalColor("Cloud Up"));

#Price Color
AssignPriceColor(if pricecolor then if close > line2 and close > open then GlobalColor("Price Up")
else if close > line2 and close < open then color.dark_green
else if close < line1 and close < open then GlobalColor("Price Down")
else if Close < line1 and close > open then color.dark_RED
else if close > open then color.white
else GlobalColor ("Price Neutral")
else Color.CURRENT);

#Alerts
Alert(AlertUp, "BREAKOUT!", Alert.BAR, Sound);
Alert(AlertDn, "BREAKDOWN!", Alert.BAR, Sound);


def barUp = chg == 1;
def barDown = chg == -1;
def barUpCount = CompoundValue(1, if barUp then barUpCount[1] + 1 else 0, 0);
def pBarUpCount = if barUpCount > 0 then barUpCount else nan;
def barDownCount = CompoundValue(1, if bardown then barDownCount[1] - 1 else 0, 0);
def pBarDownCount = if barDownCount < 0 then barDownCount else nan;

AddLabel(yes, (Round(barDownCount + barUpCount, 1)), if barUpCount > 1 then Color.GREEN else if barDownCount < -1 then Color.RED else color.blue);

#AssignBackgroundColor( if BarUp and barUpCount >= 2 then Color.dark_GRAY else if bardownCount #<= -2 then Color.plum else if BarUp and barUpCount < 2 then Color.dark_Green else if BarDown #and barDownCount > -2 then Color.Red else color.black);

AssignBackgroundColor(if !color_background then color.current else
 if Close < Line1 then Color.plum else if close > line1 and close < avg then color.magenta else if Close > Line2 then color.dark_green else if close < line2 and close > avg then color.lime else color.dark_gray);


# count cloud color changes

#def na = double.nan;
#def bn = barnumber();

def grncnt = if isnan(lbup[1]) and !isnan(lbup) then grncnt[1] + 1
 else grncnt[1];


def redcnt = if isnan(lbdn[1]) and !isnan(lbdn) then redcnt[1] + 1
 else redcnt[1];

addlabel(1, "  ", color.black);
addlabel(1, grncnt + " green clouds", color.green);
addlabel(1, redcnt + " red clouds", color.red);


input test1 = no;
addchartbubble(test1, low*0.995,
lbup + "\n" +
lbdn + "\n" +
grncnt + " G\n" +
redcnt + " R"
, color.yellow, no);

#


-------------------------

modified the upper study to become this column study.


watchlist column study
zcnt_mobo
http://tos.mx/36HV3cQ
5min 5days


Code:
# zcnt_mobo
#count_mobo_colored_band_bars_0

#https://usethinkscript.com/threads/count-mobo-band-bars-watchlist.16855/
#Count MoBo Band Bars Watchlist
#clickchamps  10/4

#Can any assist me in writing a CustomScript to put in a watchlist that would count the number of bars the Mobo Band has turn Green or Red. Right now I can get a count if stays outside the bands but once it goes inside it goes to 0 and restarts when it goes outside in the direction of the trend, other it goes to count as expect on the breakout on the other side but reset to 0 on a visit back into the band.


#Its a lot of extra code from a Mobo Study I found here
#https://usethinkscript.com/threads/momentum-bollinger-band-channels-for-thinkorswim.5977/

#---------------------------------------------------------------------------------------

#Momentum Bollinger band channel v1.0 by XeoNoX via usethinkscript.com
#Request 03-16-2021
#Based of Pensar's Keltner channel Momentum bands via usethinkscript.com
#which is based on FW-MOBO-Advanced https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/E-F/FW-MOBO-Advanced
#Inputs
input factor = 1;
input price = close;
input type = AverageType.simple;
input pricecolor = yes;
input fill = yes;
input arrows = yes;
input alerts = yes;
input sound = {default "Ding", "Bell", "Chimes", "NoSound", "Ring"};
input displace = 0;
input length = 13;
input Num_Dev_Dn = -.8;
input Num_Dev_up = .8;
input averageType = AverageType.simple;

input color_background = yes;



def sDev = StDev(data = price[-displace], length = length);

#Variables
def nan = Double.NaN;
def shift = factor * MovingAverage(type, TrueRange(high, close, low), length);

#plot avg = MovingAverage(averageType, data = price[-displace], length = length);
def avg = MovingAverage(averageType, data = price[-displace], length = length);

def line1 = avg + Num_Dev_Dn * sDev;
def line2 = avg + Num_Dev_up * sDev;
def Chg = If(close > line2, 1, If(close < line1, -1, 0));
def Hold = CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
def ArUp = if !arrows or Hold[0] == Hold[1] then nan else if Hold[0] == 1 then line1 else nan;
def ArDn = if !arrows or Hold[0] == Hold[1] then nan else if Hold[0] == -1 then line2 else nan;
def LBUp = if fill and Hold[0] == 1 then line2 else nan;
def UBUp = if fill and Hold[0] == 1 then line1 else nan;
def LBDn = if fill and Hold[0] == -1 then line2 else nan;
def UBDn = if fill and Hold[0] == -1 then line1 else nan;
def AlertUp = alerts and Hold[1] == 1 and (Hold[1] <> Hold[2]);
def AlertDn = alerts and Hold[1] == -1 and (Hold[1] <> Hold[2]);

#Colors
DefineGlobalColor("Cloud Up", Color.DARK_GREEN);
DefineGlobalColor("Cloud Dn", Color.DARK_RED);
DefineGlobalColor("Channel Up", Color.Dark_Gray);
DefineGlobalColor("Channel Down", Color.dark_gray);
DefineGlobalColor("Price Up", Color.GREEN);
DefineGlobalColor("Price Neutral", Color.GRAY);
DefineGlobalColor("Price Down", Color.RED);


#Clouds
#AddCloud(LBUp, UBUp, GlobalColor("Cloud Up"), GlobalColor("Cloud Dn"));
#AddCloud(LBDn, UBDn, GlobalColor("Cloud Dn"), GlobalColor("Cloud Up"));

#Price Color
#AssignPriceColor(if pricecolor then if close > line2 and close > open then GlobalColor("Price Up")
#else if close > line2 and close < open then color.dark_green
#else if close < line1 and close < open then GlobalColor("Price Down")
#else if Close < line1 and close > open then color.dark_RED
#else if close > open then color.white
#else GlobalColor ("Price Neutral")
#else Color.CURRENT);

#Alerts
#Alert(AlertUp, "BREAKOUT!", Alert.BAR, Sound);
#Alert(AlertDn, "BREAKDOWN!", Alert.BAR, Sound);


def barUp = chg == 1;
def barDown = chg == -1;
def barUpCount = CompoundValue(1, if barUp then barUpCount[1] + 1 else 0, 0);
def pBarUpCount = if barUpCount > 0 then barUpCount else nan;
def barDownCount = CompoundValue(1, if bardown then barDownCount[1] - 1 else 0, 0);
def pBarDownCount = if barDownCount < 0 then barDownCount else nan;

#AddLabel(yes, (Round(barDownCount + barUpCount, 1)), if barUpCount > 1 then Color.GREEN else if barDownCount < -1 then Color.RED else color.blue);

#AssignBackgroundColor( if BarUp and barUpCount >= 2 then Color.dark_GRAY else if bardownCount #<= -2 then Color.plum else if BarUp and barUpCount < 2 then Color.dark_Green else if BarDown #and barDownCount > -2 then Color.Red else color.black);

AssignBackgroundColor(if !color_background then color.current else
 if Close < Line1 then Color.plum else if close > line1 and close < avg then color.magenta else if Close > Line2 then color.dark_green else if close < line2 and close > avg then color.lime else color.dark_gray);


# count cloud color changes

#def na = double.nan;
#def bn = barnumber();

def grncnt = if isnan(lbup[1]) and !isnan(lbup) then grncnt[1] + 1
 else grncnt[1];


def redcnt = if isnan(lbdn[1]) and !isnan(lbdn) then redcnt[1] + 1
 else redcnt[1];

#addlabel(1, "  ", color.black);
#addlabel(1, grncnt + " green clouds", color.green);
#addlabel(1, redcnt + " red clouds", color.red);
plot z1 = grncnt;
z1. setdefaultcolor(color.black);


input test1 = no;
addchartbubble(test1, low*0.995,
lbup + "\n" +
lbdn + "\n" +
grncnt + " G\n" +
redcnt + " R"
, color.yellow, no);
#
 

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

@halcyonguy

You did jarr something and I did get to count corrently, for the Barcount I changed the counting varable to Hold[0] == 1.

Thank you for your help! I could not have done it without you code.


#Momentum Bollinger band channel v1.0 by XeoNoX via usethinkscript.com
#Request 03-16-2021
#Based of Pensar's Keltner channel Momentum bands via usethinkscript.com
#which is based on FW-MOBO-Advanced https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/E-F/FW-MOBO-Advanced
#Inputs
input factor = 1;
input price = close;
input type = AverageType.simple;
input pricecolor = yes;
input fill = yes;
input arrows = yes;
input alerts = yes;
input sound = {default "Ding", "Bell", "Chimes", "NoSound", "Ring"};
input displace = 0;
input length = 13;
input Num_Dev_Dn = -.8;
input Num_Dev_up = .8;
input averageType = AverageType.simple;



def sDev = StDev(data = price[-displace], length = length);

#Variables
def nan = Double.NaN;
def shift = factor * MovingAverage(type, TrueRange(high, close, low), length);
plot avg = MovingAverage(averageType, data = price[-displace], length = length);
def line1 = avg + Num_Dev_Dn * sDev;
def line2 = avg + Num_Dev_up * sDev;
def Chg = If(close > line2, 1, If(close < line1, -1, 0));
def Hold = CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
def ArUp = if !arrows or Hold[0] == Hold[1] then nan else if Hold[0] == 1 then line1 else nan;
def ArDn = if !arrows or Hold[0] == Hold[1] then nan else if Hold[0] == -1 then line2 else nan;
def LBUp = if fill and Hold[0] == 1 then line2 else nan;
def UBUp = if fill and Hold[0] == 1 then line1 else nan;
def LBDn = if fill and Hold[0] == -1 then line2 else nan;
def UBDn = if fill and Hold[0] == -1 then line1 else nan;
def AlertUp = alerts and Hold[1] == 1 and (Hold[1] <> Hold[2]);
def AlertDn = alerts and Hold[1] == -1 and (Hold[1] <> Hold[2]);

#Colors
DefineGlobalColor("Cloud Up", Color.DARK_GREEN);
DefineGlobalColor("Cloud Dn", Color.DARK_RED);
DefineGlobalColor("Channel Up", Color.Dark_Gray);
DefineGlobalColor("Channel Down", Color.dark_gray);
DefineGlobalColor("Price Up", Color.GREEN);
DefineGlobalColor("Price Neutral", Color.GRAY);
DefineGlobalColor("Price Down", Color.RED);




#Plots
#plot UB = line1;
##UB.AssignValueColor(if Hold[0] == 1 then GlobalColor("Channel Up")
# else GlobalColor("Channel Down"));
#plot LB = line2;
#LB.SetLineWeight(1);
#LB.AssignValueColor(if Hold[0] == 1 then GlobalColor("Channel Up")
#else GlobalColor("Channel Down"));
#plot BOA = ArUp;
#(PaintingStrategy.ARROW_UP);
#BOA.SetDefaultColor(Color.GREEN);
#BOA.SetLineWeight(2);
#plot BDA = ArDn;
#BDA.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
#BDA.SetDefaultColor(Color.RED);
#BDA.SetLineWeight(2);

#Clouds
AddCloud(LBUp, UBUp, GlobalColor("Cloud Up"), GlobalColor("Cloud Dn"));
AddCloud(LBDn, UBDn, GlobalColor("Cloud Dn"), GlobalColor("Cloud Up"));

#Price Color
AssignPriceColor(if pricecolor then if close > line2 and close > open then GlobalColor("Price Up")
else if close > line2 and close < open then color.dark_green
else if close < line1 and close < open then GlobalColor("Price Down")
else if Close < line1 and close > open then color.dark_RED
else if close > open then color.white
else GlobalColor ("Price Neutral")
else Color.CURRENT);

#Alerts
Alert(AlertUp, "BREAKOUT!", Alert.BAR, Sound);
Alert(AlertDn, "BREAKDOWN!", Alert.BAR, Sound);


#Addlabel(yes, if AlertUp or Alertup[1] or alertup[2] or alertup[3] or alertup[4]or alertup[5] #or alertup[6] then "^" else if AlertDn or AlertDn[1] or AlertDn[2] or AlertDn[3] or AlertDn[4]
#or AlertDn[5] or AlertDn[6] then "v" else " ", color.black);

#Assignbackgroundcolor(if close > line2 then color.dark_green else if close < line1 then #color.dark_red else color.black);

#def nan = Double.NaN;
#def barUp = close > line2 or Close > line1 ;
#def barDown = close < line1 or close < line2 ;
def barUp = chg==1;
def barDown = chg==-1;
def barUpCount = CompoundValue(1, if hold[0] == 1 then barUpCount[1] + 1 else 0, 0);
def pBarUpCount = if barUpCount > 0 then barUpCount else nan;
def barDownCount = CompoundValue(1, if hold[0] == -1 then barDownCount[1] - 1 else 0, 0);
def pBarDownCount = if barDownCount < 0 then barDownCount else nan;

AddLabel(yes, (Round(barDownCount + barUpCount, 1)), if barUpCount > 1 then Color.GREEN else if barDownCount < -1 then Color.RED else color.blue);

#AssignBackgroundColor( if BarUp and barUpCount >= 2 then Color.dark_GRAY else if bardownCount #<= -2 then Color.plum else if BarUp and barUpCount < 2 then Color.dark_Green else if BarDown #and barDownCount > -2 then Color.Red else color.black);

AssignBackgroundColor( if Close < Line1 then Color.plum else if close > line1 and close < avg then color.magenta else if Close > Line2 then color.dark_green else if close < line2 and close > avg then color.lime else color.dark_gray);






# --- End code ---
 
Last edited:
Solution

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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