Gap Up Formulas
The MetaStock formulas to calculate these percentages are shown below. The
first input is the minimum gap (e.g., 1%), and the second input is the gap
increment (e.g., 1%, which would give you a range of 1-2%). To calculate
gaps down, change the percentage to a negative.
Formula to determine whether the closing price is equal to or exceeds the
opening price on a gap day:
MinGap := Input("Minimum gap to consider (%)",-10000,10000,1);
GapIncrement := Input("Gap Increment (%)",0,100,1);
LookingForGapUp := MinGap >= 0; LookingForGapDown := MinGap < 0;
{ Gap percentage }
Gap := (OPEN - Ref(CLOSE,-1))/Ref(CLOSE,-1)*100;
NumGaps := If(LookingForGapUp, Cum(Gap >= MinGap AND Gap < MinGap +
GapIncrement), If(LookingForGapDown, Cum(Gap <= MinGap AND Gap > MinGap -
GapIncrement),0));
If(LookingForGapUp, Cum(If(Gap >= MinGap AND Gap < MinGap + GapIncrement,
If(CLOSE >= OPEN, +1,0),0)),
If(LookingForGapDown, Cum(If(Gap <= MinGap AND Gap > MinGap - GapIncrement,
If(CLOSE <= OPEN, +1, 0),0)), 0))/NumGaps*100;
Formula to determine whether the daily range crosses the previous day’s
close on a gap day:
MinGap := Input("Minimum gap to consider (%)",-10000,10000,1);
GapIncrement := Input("Gap Increment (%)",0,100,1);
LookingForGapUp := MinGap >= 0; LookingForGapDown := MinGap < 0;
{ Gap percentage }
Gap := (OPEN - Ref(CLOSE,-1))/Ref(CLOSE,-1)*100;
NumGaps := If(LookingForGapUp, Cum(Gap >= MinGap AND Gap < MinGap +
GapIncrement), If(LookingForGapDown, Cum(Gap <= MinGap AND Gap > MinGap -
GapIncrement),0));
If(LookingForGapUp, Cum(If(Gap >= MinGap AND Gap < MinGap + GapIncrement,
If(LOW <= Ref(CLOSE,-1), +1,0),0)),
If(LookingForGapDown, Cum(If(Gap <= MinGap AND Gap > MinGap - GapIncrement,
If(HIGH >= Ref(CLOSE,-1), +1, 0),0)), 0))/NumGaps*100;
Formula to determine whether the following day’s open continues the gap
trend:
MinGap := Input("Minimum gap to consider (%)",-10000,10000,1);
GapIncrement := Input("Gap Increment (%)",0,100,1);
LookingForGapUp := MinGap >= 0; LookingForGapDown := MinGap < 0;
GapYesterday := (Ref(OPEN,-1) - Ref(CLOSE,-2))/Ref(CLOSE,-2)*100;
NumGapsthruYesterday := If(LookingForGapUp, Cum(GapYesterday >= MinGap AND
GapYesterday < MinGap + GapIncrement), If(LookingForGapDown,
Cum(GapYesterday <= MinGap AND GapYesterday > MinGap - GapIncrement),0));
If(LookingForGapUp, Cum(If(GapYesterday >= MinGap AND GapYesterday < MinGap
+ GapIncrement, If(OPEN > Ref(CLOSE,-1), +1,0),0)),
If(LookingForGapDown, Cum(If(GapYesterday <= MinGap AND GapYesterday >
MinGap - GapIncrement, If(OPEN < Ref(CLOSE,-1), +1, 0),0)),
0))/NumGapsthruYesterday*100;