• LIMITED TIME ONLY: Take $40 off VIP with code: BTD40.

Help - Coding A 3Bar SetUp


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:


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:


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

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

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;

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