Help - Coding A 3Bar SetUp

hinkognito

New member
Hi Team,

Thank you to everyone in the community. I have been lurking here for a while and wanted to ask for a little help.
I am trying to create a signal for a 3 bar pattern. I am running into an issue with doji candles and I don't know how to address it.

Here is the pattern I am attempting to indicate:

kkxF6zz.jpg


It is a candle sandwiched between an inside candle on each side. Wicks are ignored.

Disclaimer - I am a thinkscript novice so let me apologize in advance for my attempt.

plot X = if close[2]>open[2] and close[2]<=open[1] and open[2]>=close[1] and open[1]>=close and close[1]<=open then low else double.nan;

Many Thanks in advance.
 
Last edited by a moderator:

tomsk

Well-known member
VIP
@hinkognito The general condition you've described is typically called an inside bar and can simply be coded as the following

Code:
def insideBar = high < high[1] and low > low[1];

As I understand it from the picture you posted, it appears you have 2 consecutive inside bar conditions - the previous one with a bearish close and the current one with a bullish close. Essentially a comparison of the relationship of the last 3 bars. If that is indeed the situation as envisioned, the condition can be coded as follows. It plots a DOT at HL2 of the candle being identified that satisfies these conditions

Code:
def isUp = close > open;
def isDown = close < open;
def insideBar = high < high[1] and low > low[1];

plot condition = if insideBar[1] and isDown[1] and insideBar and isUp then HL2 else Double.NaN;
conditionBar.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
conditionBar.SetDefaultColor(Color.YELLOW);
conditionBar.setLineWeight(3);


That condition may not show up too often and may be restrictive so feel free to adjust the parameters as needed.
This is typically I would approach this.
 
Last edited:

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