Scan for SQUEEZE (John Carter)

This is the place to discuss EdgeRater Chart Script

Moderator: Chris White

Post Reply
canucck
Posts: 19
Joined: Sun Dec 18, 2011 9:00 am

Scan for SQUEEZE (John Carter)

Post by canucck »

Hi,

I am trying to create a scan for stocks that are in a "squeeze"; as defined by John Carter, this occurs when the Bolinger Bands are so narrow that they are within the Keltner Channel bands. The idea being that a lot of energy is building in these stocks, and a good move could follow.

Here is the code that I have so far. I copied the BB code from another scan, but could not find a similar one for Keltner Channels so I used the code for Keltner Channels that is used to draw it on a graph, however, this creates some errors related to FACTOR and LENGTH not existing in that context.

Shift := FACTOR * ATR(Length);
Avg := EMA(C, Length);
KC_Upper := Avg + Shift;
KC_Lower := Avg - Shift;
BB_LOWER:= "BB(N,P)[LOWER]";
BB_UPPER:= "BB(N,P)[LOWER]";
Cond1:= BB_UPPER < KC_UPPER;
Cond2:= BB_LOWER > KC_LOWER;

Event: Cond1 & Cond2;


Can you help me with this code, please? Thanks! :shock:
canucck
Posts: 19
Joined: Sun Dec 18, 2011 9:00 am

Re: Scan for SQUEEZE (John Carter)

Post by canucck »

I am getting very close - this is a working script, and I only need to find out how to calculate a few more variations on the closing price:

1) (High + Low) / 2.

2) (High + Low + Close) / 3

3) (High + Low + Open + Close) / 4


Here is the script that works using just the closing price:

FACTOR:= 1.5;
Length:=20;
Shift := FACTOR * ATR(Length);
Avg := EMA(C, Length);
KC_Upper := Avg + Shift;
KC_Lower := Avg - Shift;
BB_LOWER:= "BB(N,P)[LOWER]";
BB_UPPER:= "BB(N,P)[LOWER]";
Cond1:= BB_UPPER < KC_UPPER;
Cond2:= BB_LOWER > KC_LOWER;

Event: Cond1 & Cond2;


At a minimum, this tells you that consolidation is occurring and a move is coming. It does not line up 100% with Carter's method, which is why I need to figure out how to do those other calculates, so that I can do a little more testing.
Chris White
Posts: 201
Joined: Mon Nov 29, 2010 9:21 pm

Re: Scan for SQUEEZE (John Carter)

Post by Chris White »

I think you figured this part out already but for others who are wondering, the reason for the FACTOR and LENGTH error message is that you need to add these parameters to the script via the Parameters tab:
Adding FACTOR and LENGTH parameters to the script
Adding FACTOR and LENGTH parameters to the script
canucck_1.png (26.52 KiB) Viewed 23661 times
You can also add those variables directly in the script like you have done, but then the values are fixed for each run of the script and not editable via the script properties.

I just updated the v5 documentation and the new quick-start section on chart script explains the steps:

http://www.edgerater.com/documentation/ ... kstart.htm

To incorporate your other variations you would just need to add lines to calculate those values and then substitute the name of that line instead of the closing price. The following script shows how you might go about doing that:

Code: Select all

MyVal1:= (H + L) / 2;
MyVal2:= (H + L + C) /3;
MyVal3:= (H + L + O + C) /4;

Shift:= FACTOR * ATR(LENGTH);
Avg:= EMA(MyVal1, LENGTH);
KC_Upper:= Avg + Shift;
KC_Lower:= Avg - Shift;
BB_LOWER:= "BB(20,2)[LOWER]";
BB_UPPER:= "BB(20,2)[UPPER]";
Cond1:= BB_UPPER < KC_UPPER;
Cond2:= BB_LOWER > KC_LOWER;

Event: Cond1 & Cond2;
See that I substituted MyVal1 instead of the Closing price for the calculation of Avg. You can follow this pattern for the other values too.
canucck
Posts: 19
Joined: Sun Dec 18, 2011 9:00 am

Re: Scan for SQUEEZE (John Carter)

Post by canucck »

Great stuff, thanks!
dan2fl
Posts: 7
Joined: Thu Oct 02, 2014 1:00 pm

Re: Scan for SQUEEZE (John Carter)

Post by dan2fl »

I am trying to create a scan in Edgerater that is based on the TTM Squeeze with a modification.
I want to be able to set the number of days that the squeeze has to be valid before a trading signal is sent when there is no longer a squeeze.
The approach I am planning to take is to use the width of the Bollinger Band and the width of the Keltner Channel to establish the squeeze conditions.
I envisage the code as something along the lines of
BBW: = P * STDP(CLOSE,N) * 2; BBW is the Bollinger Band width
KCW: = FACTOR * ATR(Length) * 2; KCW is the Keltner Channel width
InBand: = (KCW-BBW) ; InBand is the difference between the two widths
Cond1: = BBW > KCW; Valid when BBW is greater than KCW. This is today's signal
Cond2: = ??????? ; Not sure how to code. Want this to be valid when the Keltner width has been greater than the Bollinger width over the last N days starting from 1 day ago. Set up InBand so that code can use InBand > 0

Event: = Cond1 & Cond2
henry1224
Posts: 457
Joined: Wed Feb 24, 2016 12:04 pm

Re: Scan for SQUEEZE (John Carter)

Post by henry1224 »

Can MyVal1 thru MyVal3 be selected thru the parameter tab?
Chris White
Posts: 201
Joined: Mon Nov 29, 2010 9:21 pm

Re: Scan for SQUEEZE (John Carter)

Post by Chris White »

MyVal1, MyVal2, MyVal3 are variables that hold the results of the calculation and so they do not belong in the parameters tab. The parameters tab is for defining input variables. Anything in the parameters tab will be available for changing in the user interface of the charts and also the entries and exits tab.
parameterstab.png
parameterstab.png (34.28 KiB) Viewed 21030 times
Post Reply