3 Bar Play - Pattern Scan?

C

ccrkk

New member
VIP
Hello everyone - new member here getting started in the world of trading. I very much enjoy backtesting and forward testing to assemble a foundation for strategy. I was wondering if someone would be able to help me out coding a scanner for something I wish to test. It's a momentum strategy that involves an inside bar pause and then carries in the direction of the trend. The idea is listed below:

First Bar:
  1. The "high" of the bar has to set a new 20 day high (or high of the previous 20 candles for intra day scans)
  2. Range of the bar has to be greater than the previous 14 day ATR range
Second Bar:
  1. The "high" of the bar has to be 'less than or equal to' to high of the previous bar.
  2. The "low" of the bar has to be in the upper 50% range of the first bar.

The idea can also be reversed where the first bar is trending downward and sets a new 20 day low and the second bar low is less than or equal to the first bar low and is within the lower 50% range of the first bar. Any help would be greatly appreciated and I look forward to interacting more on this forum! If you have any questions just let me know and thank you!

Below is an example of what I'm looking for. Ignore the third bar for scanning purposes as that's the bar I'll be attempting to get an entry on.


 
Last edited by a moderator:
C

ccrkk

New member
VIP
I appreciate the response Ben! (great show by the way) That's definitely a great starting point for what I'm looking for. It seems to have everything I'm looking or except for the first bar setting a new 20 day high/low and having a range greater than the recent ATR. Do you have any suggestions as to how to add this? I spent time looking at the TOS tutorial but couldn't piece anything together. Again, appreciate the help!
 
M

mashume

Active member
VIP
I took a stab at your scanner, though it doesn't produce any results today. I can't say if that's the state of the day or something wrong with the scanner. Here's code to play with though:

Code:
def h = high;
def l = low;
def tr = ATR(14);
def hh = highest(high, 20);

def first_bar = if h[1] >= hh and h[1] - l[1] >= tr[-1] then 1 else double.nan;

def second_bar = if h <= h[1] and l >= l[1] + ((h[1] - l[1]) * 0.5) then 1 else double.nan;

plot signal = if first_bar == 1 and second_bar == 1 then 1 else double.nan;
Hope that sets you on the right track, or in the right direction at least.

Happy Trading,
Mashume
 
N

nrok2118

New member
I don't know how to write a script, so I'm looking for some help.

Ideally, I'm simply looking to scan for (in an intraday scan)
1) An "igniting bar" 2X+ the size of the average sized bar over the last "X" amount of bars
2) An "inside bar" with the low greater than 50% of the igniting bar (for the bullish case)
3) These bars being newly formed
4) Bonus points for the volume on the igniting bar greater than 2X the average volume on "X" amount of bars



Thanks in advance for any help!
 
Last edited by a moderator:
S

StudyTimeIsOver

New member
Hey ya'll,

This is my first post. I want to start by saying I love the site. Love tinkering with ThinkScript and you guys are doing some amazing things.

I watched a video from Jared @ Live Traders on YouTube about 3 and 4 Bar Plays. The concept seems simple:
  • Igniter Bar (2 bars ago)- Long bar with a volume spike (I'm using a hard-coded 1.5x previous bar volume, but would like it to be an input value)
  • Pause Bar (1 bar ago) - (open or close) > Igniter bar open + 1/2 bodyweight(). I probably need to define some additional rules here but it's a start
  • Signal Bar - close > open and open + $0.10 > Igniter bar open + 1/2 bodyweight().


I really liked the strategy and created a study for it. It's a work in progress. I would like to refine it to make it a better indicator. I have some work to do including:
  • Include a rule for the Igniter bar body length
In my screenshot below, I have 2 indicators A and B. Both meet my rules but B is clearly more in-line with my expectations, although had I acted on A, I would be better off. Ultimately I would like to:
  • Get this to send me alerts when I get stronger 3 bar plays indicators like higher volume, maybe volume compared to average volume
  • Create a scanner for different timeframes
  • Make this semi-automatic where I receive an alert, review, and submit an order. I have a day job, so I can't spend every last minute glued to my screen but I have some flexibility.



Code:
def igniteBarLen = absvalue(close from 2 bars ago - open from 2 bars ago);
def pauseBarLen = absvalue(close from 1 bars ago - open from 1 bars ago);

def preIgniteBarQual = (open from 2 bars ago between
    open from 3 bars ago and close from 3 bars ago);
def pauseBarQual = open from 1 bars ago is greater than open from 2 bars ago + igniteBarLen;
def signalBarQual = close >= open and
    open + 0.10 is greater than open from 2 bars ago + (igniteBarLen * 0.5);

def preIgniteBarVolQual = volume from 3 bars ago >= 10000;
def igniteBarVolQual = volume from 2 bars ago is greater than volume from 3 bars ago * 1.5;
def signalBarVolQual = volume is greater than volume from 1 bars ago;

plot isThreeBarQualifier = igniteBarLen > (pauseBarLen * 2) and
    preIgniteBarQual and
    igniteBarVolQual and
    pauseBarQual and
    signalBarQual;
Scanner:

Code:
# IgniteBarLen > PauseBarLen
absvalue(close from 2 bars ago - open from 2 bars ago) > (absvalue(close from 1 bars ago - open from 1 bars ago) * 2)

and

# preIgniteBarQual
(open from 2 bars ago between
    open from 3 bars ago and close from 3 bars ago)

and

#igniteBarVolQual

volume from 3 bars ago >= 10000

and

#pauseBarQual

open from 1 bars ago is greater than open from 2 bars ago + absvalue(close from 2 bars ago - open from 2 bars ago)

and

#signalBarQual

close >= open and
    open + 0.10 is greater than open from 2 bars ago + (absValue(open[2] - close[2]) * 0.5)
 
Last edited:
N

nrok2118

New member
Thanks Study!!! I used your code and modified it to my basic parameters and got something working!

This is for a basic bullish 3 bar play setup (only looking for an igniting bar and pause bar, ill manually enter on the third). Key points:
-Igniting bar is greater than 2X the average sized bar over last 10 candles
-Pause bar does not exceed the igniting bar high and it's low is within 50%
-Igniting bar's close is within 75% of the high (I got some hits with extreme top wicks, I don't want much selling pressure)

Now I need work work on volume, not sure how VolumeAvg works, but I'll be looking to compare the igniting bar volume to the average volume over the previous candles.

*EDIT

I learned a few things to tidy the code up, and also added volume! This now includes the volume of the igniting bar 2X greater than the previous bars (which i turned into a input)

Code:
input barsback = 10;

def igniteBarLen = absvalue(high[1] - low[1]);

def pauseBarLen = absvalue(high - low);

def pauseBarQual = high <= high[1]
    and
    igniteBarLen > (pauseBarLen*2) ;

def setupbarlen = (average(high[1],barsback) - average(low[1],barsback));

def ignitebarbull =  close[1] > open[1]
    and
    (close[1] - low[1]) > (high[1] - low[1]) *.75;

def IgniteBarVolQual = volume[1] > (average(volume[2], barsback))*2 ;


plot isThreeBarQualifier = 
    pauseBarQual
and
    ignitebarbull
and
    IgniteBarVolQual
and
    igniteBarLen > (setupbarlen*2);
 
Last edited:

Top