# Candle sandwich code

#### SJP07

##### Member
I'm trying to write a code that points an arrow when there's a green candle between two red candles and a red candle between two green candles. Below is a screenshot example.

Here's what I have so far:

def Red_Bar = open > close;
def Green_Bar = close > open;

def Bullish_Order_Block = Red_Bar[3] is true && Green_Bar[2] is true && Red_Bar[1] is true;
Plot Bullish_OB = if Bullish_Order_Block is true then high[1] else double.nan;

Solution
I'm trying to write a code that points an arrow when there's a green candle between two red candles and a red candle between two green candles. Below is a screenshot example.

Here's what I have so far:

def Red_Bar = open > close;
def Green_Bar = close > open;

def Bullish_Order_Block = Red_Bar[3] is true && Green_Bar[2] is true && Red_Bar[1] is true;
Plot Bullish_OB = if Bullish_Order_Block is true then high[1] else double.nan;

Try this

Code:
``````def Red_Bar   = open > close;
def Green_Bar = close > open;

def Bullish_Order_Block = if Green_Bar then if Red_Bar[1] && Red_Bar[-1] then 1 else 0 else Double.NaN;
plot Bullish_OB = if Bullish_Order_Block is true then low else...``````
I'm trying to write a code that points an arrow when there's a green candle between two red candles and a red candle between two green candles. Below is a screenshot example.

Here's what I have so far:

def Red_Bar = open > close;
def Green_Bar = close > open;

def Bullish_Order_Block = Red_Bar[3] is true && Green_Bar[2] is true && Red_Bar[1] is true;
Plot Bullish_OB = if Bullish_Order_Block is true then high[1] else double.nan;

Try this

Code:
``````def Red_Bar   = open > close;
def Green_Bar = close > open;

def Bullish_Order_Block = if Green_Bar then if Red_Bar[1] && Red_Bar[-1] then 1 else 0 else Double.NaN;
plot Bullish_OB = if Bullish_Order_Block is true then low else Double.NaN;
Bullish_OB.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

def Bearish_Order_Block = if Red_Bar then if Green_Bar[1] && Green_Bar[-1] then 1 else 0 else Double.NaN;
plot Bearish_OB = if Bearish_Order_Block is true then high else Double.NaN;
Bearish_OB.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);``````

This is great! Thanks as always! Would it be possible only to have these signals show if they occur three bars [or a certain amount of bars] away from the low?

This is great! Thanks as always! Would it be possible only to have these signals show if they occur three bars [or a certain amount of bars] away from the low?

How are you defining "the low"? ... a pivot ... of the day ... etc
Do you want definition to apply to both bullish and bearish? Or some other method?
Do you have a chart mock up of what you want to include with your response?

87k+ Posts
275 Online

## The Market Trading Game Changer

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?