3 consecutive green/red bars with a dot on the first candle

hovno

New member
Hello,

Can someone please help me to build a simple tool that will plot a dot or an arrow every time three consecutive higher green or lower red candles appear? Basically a legstart of the swing. The problem is, I would like to plot an arrow/dot on that first candle (beginning of the legstart), not the last candle nor the all candles...but the first candle..(of course the dot will appear after all candles are completed so after 3 candles).

This is what i came up with so far:

def candle = open < close;
def leg =((candle > candle[1]) and (candle[1] > candle[2]) and (candle[2] > candle[3]));

plot LegStart = if leg then Lowest(leg) else Double.NaN;
LegStart.setpaintingStrategy(paintingStrategy.POINTS);
LegStart.setLineWeight(3);
LegStart .setdefaultColor(Color.WHITE);

Solution
Hello,

Can someone please help me to build a simple tool that will plot a dot or an arrow every time three consecutive higher green or lower red candles appear? Basically a legstart of the swing. The problem is, I would like to plot an arrow/dot on that first candle (beginning of the legstart), not the last candle nor the all candles...but the first candle..(of course the dot will appear after all candles are completed so after 3 candles).

This is what i came up with so far:

def candle = open < close;
def leg =((candle > candle[1]) and (candle[1] > candle[2]) and (candle[2] > candle[3]));

plot LegStart = if leg then Lowest(leg) else Double.NaN;
LegStart.setpaintingStrategy(paintingStrategy.POINTS);
LegStart.setLineWeight(3)...
Hello,

Can someone please help me to build a simple tool that will plot a dot or an arrow every time three consecutive higher green or lower red candles appear? Basically a legstart of the swing. The problem is, I would like to plot an arrow/dot on that first candle (beginning of the legstart), not the last candle nor the all candles...but the first candle..(of course the dot will appear after all candles are completed so after 3 candles).

This is what i came up with so far:

def candle = open < close;
def leg =((candle > candle[1]) and (candle[1] > candle[2]) and (candle[2] > candle[3]));

plot LegStart = if leg then Lowest(leg) else Double.NaN;
LegStart.setpaintingStrategy(paintingStrategy.POINTS);
LegStart.setLineWeight(3);
LegStart .setdefaultColor(Color.WHITE);

See if this works as you want

Ruby:
``````def legup    = Sum(open < close, 3) == 3;
def legdn    = Sum(open > close, 3) == 3;

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);``````

This is amazing! nice work thank you very much.

Is it possible to change this for 2 consecutive bars instead of 3? I tried editing the code (don't know much) but its not coming out right.

Is it possible to change this for 2 consecutive bars instead of 3? I tried editing the code (don't know much) but its not coming out right.

Sure, try this

Ruby:
``````def legup    = Sum(open < close, 2) == 2;
def legdn    = Sum(open > close, 2) == 2;

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

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

Not the exact question you're looking for?

87k+ Posts
359 Online

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?