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;

Thank you in advance!
 
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;

Thank you in advance!

Try this

Screenshot 2023-05-31 095651.png
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;

Thank you in advance!

Try this

Screenshot 2023-05-31 095651.png
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);
 
Solution

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

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?
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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