# Add this into the condition?

#### Trigun1127

##### Member
This isnt plotting right. Im trying to a get a dot to plot when 3 bull bars or 3 bears bars occur and there is a gap (bull open>close[1]) or (bear open<close[1] anywhere in those 3 bars.
Code:
def legup    = Sum(open < close, 3) == 3 and open [0] > close[1] and close > open and close[1] > open[1];
def legdn    = Sum(open > close, 3) == 3 and open [0] < close[1] and close < open and close[1] < open[1];

plot LegupStart = if !legup and !legup[-1] and legup[-2] then low else Double.NaN;
LegupStart.SetPaintingStrategy(PaintingStrategy.POINTS);
LegupStart.SetLineWeight(5);
LegupStart .SetDefaultColor(Color.WHITE);

plot LegdnStart = if !legdn and !legdn[-1] and legdn[-2] then high else Double.NaN;
LegdnStart.SetPaintingStrategy(PaintingStrategy.POINTS);
LegdnStart.SetLineWeight(5);
LegdnStart .SetDefaultColor(Color.YELLOW);

Solution
You've got the >'s and <'s flipped, try this:

def legup = Sum(Close > Open,3) == 3 and Sum(Open > Close[1],2);
def legdn = Sum(Close < Open,3) == 3 and Sum(Open < Close[1],2);

plot LegupStart = if !legup and !legup[-1] and legup[-2] then low else Double.NaN;
LegupStart.SetPaintingStrategy(PaintingStrategy.POINTS);
LegupStart.SetLineWeight(5);
LegupStart .SetDefaultColor(Color.WHITE);

plot LegdnStart = if !legdn and !legdn[-1] and legdn[-2] then high else Double.NaN;
LegdnStart.SetPaintingStrategy(PaintingStrategy.POINTS);
LegdnStart.SetLineWeight(5);
LegdnStart .SetDefaultColor(Color.YELLOW);

#### Trigun1127

##### Member
Any clue why this wouldn't plot?

def ReqStrngCloLong = Sum(close > open and close >= low + (.74 * (high - low)), 3) >= 1;
def ReqStrngCloShort = Sum(close < open and close <= low + (.74 * (high - low)), 3) >= 1;
def Mchannelup = Sum(low >= low[1], 3 - 1) == 3 - 1; #inSequence
def Mchanneldn = Sum (high <= high[1], 3 - 1) == 3 - 1; #inSequence
def ReqMgapup = Sum(close > open, 3) == 3 and low > high[2] >= 1;
def ReqMgapdn = Sum(close < open, 3) == 3 and high < low[2] >= 1;
def legup = Sum(close > open, 3) == 3 and ReqMgapup and Mchannelup and ReqStrngCloLong;
def legdn = Sum(close < open, 3) == 3 and ReqMgapdn and Mchanneldn and ReqStrngCloShort;

plot LegupStart = if !legup and !legup[-1] and legup[-2] then low else Double.NaN;
LegupStart.SetPaintingStrategy(PaintingStrategy.POINTS);
LegupStart.SetLineWeight(5);
LegupStart .SetDefaultColor(Color.WHITE);

plot LegdnStart = if !legdn and !legdn[-1] and legdn[-2] then high else Double.NaN;
LegdnStart.SetPaintingStrategy(PaintingStrategy.POINTS);
LegdnStart.SetLineWeight(5);
LegdnStart .SetDefaultColor(Color.YELLOW);

/MES - 1hr Chart - Extended hours off - Aggregate at Open
for some reason the indicator did not plot on three candles. Here are their OHLC.

1st Candle:

Open: 3996.5
High: 4024.25
Low: 3986.25
Close: 4022

2nd Candle:

Open: 4022.25
High: 4051
Low: 4020.5
Close: 4038.5

3rd Candle:

Open: 4038.5
High: 4046
Low: 4033.25
Close: 4040.50

#### Joshua

##### Well-known member
VIP
This happens if you add the following code:

plot test = legup or legup[1];
test.setpaintingStrategy(paintingStrategy.BOOLEAN_ARROW_UP);

The leg things are overlapping.

This line is telling it not to plot any dots where those arrows are:

if !legdn and !legdn[-1] and legdn[-2] then high else Double.NaN;

#### Trigun1127

##### Member
Yeah it seems that the majority of the issues is when they consecutively happen. All I need is Point at where the ? mark would be to show that those are a separate 3 consecutive bull bars. Like the first set, the point is at the first candle.

#### halcyonguy

##### Well-known member
VIP
Lifetime
Any clue why this wouldn't plot?

/MES - 1hr Chart - Extended hours off - Aggregate at Open
for some reason the indicator did not plot on three candles. Here are their OHLC.

1st Candle:

Open: 3996.5
High: 4024.25
Low: 3986.25
Close: 4022

2nd Candle:

Open: 4022.25
High: 4051
Low: 4020.5
Close: 4038.5

3rd Candle:

Open: 4038.5
High: 4046
Low: 4033.25
Close: 4040.50

if things don't plot as intended, add a bubble to display some variables, to see what is going on.

i like to add an if then to change the bubble color.
this bubble changes color based on the 2 plot variables, to make it easier to see when 1 of them has a value.

Code:
# trigun_legup_01

#https://usethinkscript.com/threads/add-this-into-the-condition.13272/page-4#post-117479
#post61
# Trigun1127

def ReqStrngCloLong = Sum(close > open and close >= low + (.74 * (high - low)), 3) >= 1;
def ReqStrngCloShort = Sum(close < open and close <= low + (.74 * (high - low)), 3) >= 1;
def Mchannelup = Sum(low >= low[1], 3 - 1) == 3 - 1; #inSequence
def Mchanneldn = Sum (high <= high[1], 3 - 1) == 3 - 1; #inSequence
def ReqMgapup = Sum(close > open, 3) == 3 and low > high[2] >= 1;
def ReqMgapdn = Sum(close < open, 3) == 3 and high < low[2] >= 1;
def legup = Sum(close > open, 3) == 3 and ReqMgapup and Mchannelup and ReqStrngCloLong;
def legdn = Sum(close < open, 3) == 3 and ReqMgapdn and Mchanneldn and ReqStrngCloShort;

plot LegupStart = if !legup and !legup[-1] and legup[-2] then low else Double.NaN;
LegupStart.SetPaintingStrategy(PaintingStrategy.POINTS);
LegupStart.SetLineWeight(5);
LegupStart .SetDefaultColor(Color.WHITE);

plot LegdnStart = if !legdn and !legdn[-1] and legdn[-2] then high else Double.NaN;
LegdnStart.SetPaintingStrategy(PaintingStrategy.POINTS);
LegdnStart.SetLineWeight(5);
LegdnStart .SetDefaultColor(Color.YELLOW);

addchartbubble(1, low*0.995,
ReqStrngCloLong + "\n" +
ReqStrngCloShort  + "\n" +
Mchannelup + "\n" +
Mchanneldn  + "\n" +
ReqMgapup  + "\n" +
ReqMgapdn  + "\n" +
legup  + "\n" +
legdn  + "\n\n" +

LegupStart  + "\n" +
LegdnStart
, ( if !isnan(LegupStart) then color.green else if !isnan(LegdnStart) then color.red else color.gray), no);

#

#### Trigun1127

##### Member
if things don't plot as intended, add a bubble to display some variables, to see what is going on.

i like to add an if then to change the bubble color.
this bubble changes color based on the 2 plot variables, to make it easier to see when 1 of them has a value.

Code:
# trigun_legup_01

#https://usethinkscript.com/threads/add-this-into-the-condition.13272/page-4#post-117479
#post61
# Trigun1127

def ReqStrngCloLong = Sum(close > open and close >= low + (.74 * (high - low)), 3) >= 1;
def ReqStrngCloShort = Sum(close < open and close <= low + (.74 * (high - low)), 3) >= 1;
def Mchannelup = Sum(low >= low[1], 3 - 1) == 3 - 1; #inSequence
def Mchanneldn = Sum (high <= high[1], 3 - 1) == 3 - 1; #inSequence
def ReqMgapup = Sum(close > open, 3) == 3 and low > high[2] >= 1;
def ReqMgapdn = Sum(close < open, 3) == 3 and high < low[2] >= 1;
def legup = Sum(close > open, 3) == 3 and ReqMgapup and Mchannelup and ReqStrngCloLong;
def legdn = Sum(close < open, 3) == 3 and ReqMgapdn and Mchanneldn and ReqStrngCloShort;

plot LegupStart = if !legup and !legup[-1] and legup[-2] then low else Double.NaN;
LegupStart.SetPaintingStrategy(PaintingStrategy.POINTS);
LegupStart.SetLineWeight(5);
LegupStart .SetDefaultColor(Color.WHITE);

plot LegdnStart = if !legdn and !legdn[-1] and legdn[-2] then high else Double.NaN;
LegdnStart.SetPaintingStrategy(PaintingStrategy.POINTS);
LegdnStart.SetLineWeight(5);
LegdnStart .SetDefaultColor(Color.YELLOW);

addchartbubble(1, low*0.995,
ReqStrngCloLong + "\n" +
ReqStrngCloShort  + "\n" +
Mchannelup + "\n" +
Mchanneldn  + "\n" +
ReqMgapup  + "\n" +
ReqMgapdn  + "\n" +
legup  + "\n" +
legdn  + "\n\n" +

LegupStart  + "\n" +
LegdnStart
, ( if !isnan(LegupStart) then color.green else if !isnan(LegdnStart) then color.red else color.gray), no);

#

Great Tip I will def uses bubbles more often.

#### Joshua

##### Well-known member
VIP
Try testing this out

def x = if legUp[-2] and x[1] >= 3 then 1 else x[1] + 1;
plot test = legup[-2] and x[1] >= 3;
test.setpaintingStrategy(paintingStrategy.BOOLEAN_ARROW_UP);

plot xx = x;
xx.setpaintingStrategy(paintingStrategy.VALUES_ABOVE);
xx.setdefaultColor(color.white);

## 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.