CM_TotalConsecutive_Up_Down_V2 For ThinkOrSwim

CashMoney

Member
VIP
Hi!
Anyone able to convert this into Lower study TOS indicator? Bull vs Bear- Whos in control. @samer800 You have helped convert something similar before, wondering if you can do the same with this one. Thank you!
 
Last edited by a moderator:
Hi!
Anyone able to convert this into Lower study TOS indicator? Bull vs Bear- Whos in control. @samer800 You have helped convert something similar before, wondering if you can do the same with this one. Thank you!

Here is the link:

Code:
https://www.tradingview.com/script/S2KaPr43-Custom-Indicator-Clearly-Shows-If-Bulls-or-Bears-are-in-Control/

study(title="CM_TotalConsecutive_Up_Down_V2", shorttitle="CM_TotalConsec_Up_Down_V2", overlay=false)
dopm = input(true, title="Check = Use Midpoint, UnCheck = Use Prev Close")
dohbM = input(false, title="Highest Bar Look Back Period - Using Midpoint?")
dohbC = input(false, title="Highest Bar Look Back Period - Using Close?")
dostM = input(false, title="Standard Dev - Using Midpoint?")
dostC = input(false, title="Standard Dev - Using Close?")
domaM = input(false, title="Moving Average - Using Midpoint?")
domaC = input(false, title="Moving Average - Using Close?")
hlength = input(4, minval=1, title="Horizontal Line")
length2 = input(50, minval=1, title="Highest Bar Look Back Period")
length4 = input(50, minval=1, title="Standard Dev Length")
length5 = input(2, minval=1, title="Standard Dev Multiple")
length3 = input(20, minval=1, title="Moving Average length")

down_BarC = close > close[1]
up_BarC = close < close[1]
down_BarM = close > hl2[1]
up_BarM = close < hl2[1]
//percentrank = percentrank(barssince(down_Bar), 50)/10
avg_Down = sma(barssince(down_BarM), length3)
avg_Up = sma(barssince(up_BarM), length3)
avg_DownC = sma(barssince(down_BarC), length3)
avg_UpC = sma(barssince(up_BarC), length3)
stdevdm = stdev(barssince(down_BarM), length4)*length5
stdevum = stdev(barssince(up_BarM), length4)*length5
stdevdC = stdev(barssince(down_BarC), length4)*length5
stdevuC = stdev(barssince(up_BarC), length4)*length5
plot(dopm and barssince(down_BarM) ? barssince(down_BarM) : barssince(down_BarC), title="Price Down Based On Midpoint or Close", color=red, style=histogram, linewidth=3)
plot(dopm and barssince(up_BarM) ? barssince(up_BarM) : barssince(up_BarC), title="Price Up Based On Midpoint or Close", color=lime, style=histogram, linewidth=3)
plot(dohbM and highest(barssince(down_BarM), length2) ? highest(barssince(down_BarM), length2) : na, title="Highest Down Bar Lookback - Midpoint", color=red, linewidth=4)
plot(dohbM and highest(barssince(up_BarM), length2) ? highest(barssince(up_BarM), length2) : na, title="Highest Up Bar Lookback - Midpoint",color=lime, linewidth=4)
plot(dohbC and highest(barssince(down_BarC), length2) ? highest(barssince(down_BarC), length2) : na, title="Highest Down Bar Lookback - Close",color=red, linewidth=4)
plot(dohbC and highest(barssince(up_BarC), length2) ? highest(barssince(up_BarC), length2) : na, title="Highest Up Bar Lookback - Close",color=lime, linewidth=4)
plot(dostM and stdevdm ? stdevdm : na, title="StdDev of Down Bars - Midpoint",color=red, linewidth=4)
plot(dostM and stdevum ? stdevum : na, title="StdDev of Up Bars - Midpoint",color=lime, linewidth=4)
plot(dostC and stdevdC ? stdevdC : na, title="StdDev of Down Bars - Close",color=red, linewidth=4)
plot(dostC and stdevuC ? stdevuC : na, title="StdDev of Up Bars - Close",color=lime, linewidth=4)
plot(domaM and avg_Down ? avg_Down : na, title="MA of Down Bars - Midpoint",color=red, linewidth=4)
plot(domaM and avg_Up ? avg_Up :na, title="MA of Up Bars - Midpoint",color=lime, linewidth=4)
plot(domaC and avg_DownC ? avg_DownC : na, title="MA of Down Bars - Close",color=red, linewidth=4)
plot(domaC and avg_UpC ? avg_UpC :na, title="MA of Up Bars - Close",color=lime, linewidth=4)
hline(hlength, title="Horizontal Line", linestyle=dashed, linewidth=4, color=yellow)
check the below.

CSS:
#@ChrisMoody
#study(title="CM_TotalConsecutive_Up_Down_V2", shorttitle="CM_TotalConsec_Up_Down_V2"
# Converted by Sam4Cok@Samer800 - 01/2023 - Request from UseThinkScript.com member
declare lower;
declare Zerobase;
input UseMidpoint = yes;#, title="Check = Use Midpoint, UnCheck = Use Prev Close")
input dohbM = no;#, title="Highest Bar Look Back Period - Using Midpoint?")
input dohbC = no;#(false, title="Highest Bar Look Back Period - Using Close?")
input dostM = no;#(false, title="Standard Dev - Using Midpoint?")
input dostC = no;#(false, title="Standard Dev - Using Close?")
input domaM = no;#(false, title="Moving Average - Using Midpoint?")
input domaC = no;#(false, title="Moving Average - Using Close?")
input hlength = 4;#, minval=1, title="Horizontal Line")
input length2 = 50;#, minval=1, title="Highest Bar Look Back Period")
input length4 = 50;#, minval=1, title="Standard Dev Length")
input length5 = 2;#, minval=1, title="Standard Dev Multiple")
input length3 = 20;#, minval=1, title="Moving Average length")

def na = Double.NaN;
#barssince(Condition) =>
script barssince {
input Condition = 0;
def barssince = if Condition then 0 else barssince[1] + 1;
plot return = barssince;
}

def down_BarC = close > close[1];
def up_BarC = close < close[1];

def down_BarM = close > hl2[1];
def up_BarM = close < hl2[1];

#//percentrank = percentrank(barssince(down_Bar), 50)/10

def downBarM = barssince(down_BarM) ;
def downBarC = barssince(down_BarC) ;
def upBarM   = barssince(up_BarM) ;
def upBarC   = barssince(up_BarC) ;

def HdownBarM = highest(downBarM, length2);
def HdownBarC = highest(downBarC, length2);
def HupBarM   = highest(upBarM, length2);
def HupBarC   = highest(upBarC, length2);

def avg_Down  = Average(downBarM, length3);
def avg_Up    = Average(upBarM, length3);
def avg_DownC = Average(downBarC, length3);
def avg_UpC   = Average(upBarC, length3);

def stdevdm = StDev(downBarM, length4) * length5;
def stdevum = StDev(upBarM, length4) * length5;
def stdevdC = StDev(downBarC, length4) * length5;
def stdevuC = StDev(upBarC, length4) * length5;

plot HorLine = if isNaN(Close) then na else hlength;           # "Horizontal Line",
HorLine.SetStyle(Curve.SHORT_DASH);
HorLine.SetDefaultColor(Color.YELLOW);

plot CloMaUp  = if domaC and avg_UpC then avg_UpC else na;     # "MA of Up Bars - Close"
CloMaUp.SetDefaultColor(Color.CYAN);
plot CloMaDn  = if domaC and avg_DownC then avg_DownC else na; # "MA of Down Bars - Close"
CloMaDn.SetDefaultColor(Color.MAGENTA);

plot MidMaUp  = if domaM and avg_Up then avg_Up else na;       # "MA of Up Bars - Midpoint"
MidMaUp.SetDefaultColor(Color.CYAN);
plot MidMaDn  = if domaM and avg_Down then avg_Down else na;   # "MA of Down Bars - Midpoint"
MidMaDn.SetDefaultColor(Color.MAGENTA);

plot CloStdUp = if dostC and stdevuC then stdevuC else na;     # "StdDev of Up Bars - Close"
CloStdUp.SetDefaultColor(Color.CYAN);
plot CloStdDn = if dostC and stdevdC then stdevdC else na;     # "StdDev of Down Bars - Close"
CloStdDn.SetDefaultColor(Color.MAGENTA);

plot MidStdUp = if dostM and stdevum then stdevum else na;     # "StdDev of Up Bars - Midpoint"
MidStdUp.SetDefaultColor(Color.CYAN);
plot MidStdDn = if dostM and stdevdm then stdevdm else na;     # "StdDev of Down Bars - Midpoint"
MidStdDn.SetDefaultColor(Color.MAGENTA);

plot CloHiUp = if dohbC and HupBarC then HupBarC else na;      # "Highest Up Bar Lookback - Close"
CloHiUp.SetDefaultColor(Color.CYAN);
plot CloHiDn = if dohbC and HdownBarC then HdownBarC else na;  # "Highest Down Bar Lookback - Close"
CloHiDn.SetDefaultColor(Color.MAGENTA);

plot MidHiUp = if dohbM and HupBarM then HupBarM else na;      # "Highest Up Bar Lookback - Midpoint"
MidHiUp.SetDefaultColor(Color.CYAN);
plot MidHiDn = if dohbM and HdownBarM then HdownBarM else na;  # "Highest Down Bar Lookback - Midpoint"
MidHiDn.SetDefaultColor(Color.MAGENTA);

plot PriceUp = if UseMidpoint and upBarM then upBarM else upBarC;     # "Price Up Based On Midpoint or Close"
PriceUp.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
PriceUp.SetLineWeight(3);
PriceUp.SetDefaultColor(Color.GREEN);
plot PriceDown = if UseMidpoint and downBarM then downBarM else downBarC;  # "Price Down Based On Midpoint or Close"
PriceDown.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
PriceDown.SetLineWeight(3);
PriceDown.SetDefaultColor(Color.RED);


#--- END CODE
 
check the below.

CSS:
#@ChrisMoody
#study(title="CM_TotalConsecutive_Up_Down_V2", shorttitle="CM_TotalConsec_Up_Down_V2"
# Converted by Sam4Cok@Samer800 - 01/2023 - Request from UseThinkScript.com member
declare lower;
declare Zerobase;
input UseMidpoint = yes;#, title="Check = Use Midpoint, UnCheck = Use Prev Close")
input dohbM = no;#, title="Highest Bar Look Back Period - Using Midpoint?")
input dohbC = no;#(false, title="Highest Bar Look Back Period - Using Close?")
input dostM = no;#(false, title="Standard Dev - Using Midpoint?")
input dostC = no;#(false, title="Standard Dev - Using Close?")
input domaM = no;#(false, title="Moving Average - Using Midpoint?")
input domaC = no;#(false, title="Moving Average - Using Close?")
input hlength = 4;#, minval=1, title="Horizontal Line")
input length2 = 50;#, minval=1, title="Highest Bar Look Back Period")
input length4 = 50;#, minval=1, title="Standard Dev Length")
input length5 = 2;#, minval=1, title="Standard Dev Multiple")
input length3 = 20;#, minval=1, title="Moving Average length")

def na = Double.NaN;
#barssince(Condition) =>
script barssince {
input Condition = 0;
def barssince = if Condition then 0 else barssince[1] + 1;
plot return = barssince;
}

def down_BarC = close > close[1];
def up_BarC = close < close[1];

def down_BarM = close > hl2[1];
def up_BarM = close < hl2[1];

#//percentrank = percentrank(barssince(down_Bar), 50)/10

def downBarM = barssince(down_BarM) ;
def downBarC = barssince(down_BarC) ;
def upBarM   = barssince(up_BarM) ;
def upBarC   = barssince(up_BarC) ;

def HdownBarM = highest(downBarM, length2);
def HdownBarC = highest(downBarC, length2);
def HupBarM   = highest(upBarM, length2);
def HupBarC   = highest(upBarC, length2);

def avg_Down  = Average(downBarM, length3);
def avg_Up    = Average(upBarM, length3);
def avg_DownC = Average(downBarC, length3);
def avg_UpC   = Average(upBarC, length3);

def stdevdm = StDev(downBarM, length4) * length5;
def stdevum = StDev(upBarM, length4) * length5;
def stdevdC = StDev(downBarC, length4) * length5;
def stdevuC = StDev(upBarC, length4) * length5;

plot HorLine = if isNaN(Close) then na else hlength;           # "Horizontal Line",
HorLine.SetStyle(Curve.SHORT_DASH);
HorLine.SetDefaultColor(Color.YELLOW);

plot CloMaUp  = if domaC and avg_UpC then avg_UpC else na;     # "MA of Up Bars - Close"
CloMaUp.SetDefaultColor(Color.CYAN);
plot CloMaDn  = if domaC and avg_DownC then avg_DownC else na; # "MA of Down Bars - Close"
CloMaDn.SetDefaultColor(Color.MAGENTA);

plot MidMaUp  = if domaM and avg_Up then avg_Up else na;       # "MA of Up Bars - Midpoint"
MidMaUp.SetDefaultColor(Color.CYAN);
plot MidMaDn  = if domaM and avg_Down then avg_Down else na;   # "MA of Down Bars - Midpoint"
MidMaDn.SetDefaultColor(Color.MAGENTA);

plot CloStdUp = if dostC and stdevuC then stdevuC else na;     # "StdDev of Up Bars - Close"
CloStdUp.SetDefaultColor(Color.CYAN);
plot CloStdDn = if dostC and stdevdC then stdevdC else na;     # "StdDev of Down Bars - Close"
CloStdDn.SetDefaultColor(Color.MAGENTA);

plot MidStdUp = if dostM and stdevum then stdevum else na;     # "StdDev of Up Bars - Midpoint"
MidStdUp.SetDefaultColor(Color.CYAN);
plot MidStdDn = if dostM and stdevdm then stdevdm else na;     # "StdDev of Down Bars - Midpoint"
MidStdDn.SetDefaultColor(Color.MAGENTA);

plot CloHiUp = if dohbC and HupBarC then HupBarC else na;      # "Highest Up Bar Lookback - Close"
CloHiUp.SetDefaultColor(Color.CYAN);
plot CloHiDn = if dohbC and HdownBarC then HdownBarC else na;  # "Highest Down Bar Lookback - Close"
CloHiDn.SetDefaultColor(Color.MAGENTA);

plot MidHiUp = if dohbM and HupBarM then HupBarM else na;      # "Highest Up Bar Lookback - Midpoint"
MidHiUp.SetDefaultColor(Color.CYAN);
plot MidHiDn = if dohbM and HdownBarM then HdownBarM else na;  # "Highest Down Bar Lookback - Midpoint"
MidHiDn.SetDefaultColor(Color.MAGENTA);

plot PriceUp = if UseMidpoint and upBarM then upBarM else upBarC;     # "Price Up Based On Midpoint or Close"
PriceUp.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
PriceUp.SetLineWeight(3);
PriceUp.SetDefaultColor(Color.GREEN);
plot PriceDown = if UseMidpoint and downBarM then downBarM else downBarC;  # "Price Down Based On Midpoint or Close"
PriceDown.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
PriceDown.SetLineWeight(3);
PriceDown.SetDefaultColor(Color.RED);


#--- END CODE
thank you so much!!! Thank u!!! it I took the study and made two indicator out of it... one for bull and one for bear and made the " hlength" to 1. This way i can see who is in control.
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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