Maximum Price Gap over 30 days

Hi guys,
I am learning how to do explorations in AFL.

I cannot get my head around how to generate the largest Close to Close gap in the last 30 days.

I have found the GapDown, GapUp functions but they only give you a true/false not a % change.
Can you help???
Hope it is not too much asking.
Regards
Laurent

I am not sure that I understand what you mean by "Gap". But if you are looking for the largest change over one trading day then try something like this.

Change = ROC(Close, 1);

Filter=1;
SetSortColumns(-3);
AddColumn(change, "Percent Change", 1.2);

You can alter the parameter "periods" to look back as many days as you please (you mention 30 which I interpret you to mean one month which usually only has approximately 20-22 trading days)

Output run on today SPY over the past month looks like this,

1 Like

Hi portfoliobuider, much appreciated for your help.
I am trying to assess the stocks that gaps from close to open the next day.
So “gap” means the %change from PreviousClose to Open.
And I want to find out the max of these gaps over 30 days…
Not sure the ROC does this?
Laurent

Ah, previous Close to Open (not Close to Close)



Change = (Close- Open);
ChangePercent = ((Close- Open)/Close )*100;
LargestOneDayChange = HHV(Change, 22); // in points
LargestPercentChange = HHV(ChangePercent, 22);

Filter=1;
AddColumn(LargestOneDayChange, "Largest Change"); // in points
AddColumn(LargestPercentChange, "Largest % Change"); 

2 Likes

Or another way of looking over the past month is to set the dates in the Analysis window and run this type of Exploration.

ChangePercent = ((Close- Open)/Close )*100;

LargestPercentChange = HHV(ChangePercent, 22);

Filter=1;
SetSortColumns(-3);
AddColumn(ChangePercent, "Percent Change", 1.2);

Or run that Exploration against a watch list, in this example I am using the Dow Jones Industrials.

1 Like

Thanks Mate, much appreciated

So now all I have to do is run 30 iterations of this and get the maximum of them!

I will look into this

thanks a lot for your support
Laurent

I realize that I made a simple mistake in my haste to type out an answer. I was comparing the Close and Open of the same bar!

You need today’s Open compared to Yesterday’s Close.
Here is I think the correct calculation and a few extra columns to help proof read the idea.

ChangePercent = ( Open - Ref( Close, -1 ) ) / Ref( Close, -1 ) * 100;

// largest change in past 22 days
LargestPercentChange = HHV( ChangePercent, 22 ); 

Filter = 1;
//SetSortColumns(-3);
AddColumn( Open, "Open" );
AddColumn( C, "Close" );
AddColumn( Ref( C, -1 ), "yesterdays Close" );
AddColumn( ( Open - Ref( Close, -1 ) ), "raw Change", 1.2 );
AddColumn( ChangePercent, "Percent Change", 1.2 );
AddColumn( LargestPercentChange, "LargestPercentChange", 1.2 );
2 Likes

Mate you are a legend. Thanks to your hep this is the follwing code that seems to be working:

chgpc = ROC(Close,1);
largestchgpc = HHV(chgpc, 90);
lowestchgpc = LLV(chgpc, 90);
u = abs(largestchgpc);
d = abs(lowestchgpc);
maxgp = IIf( u > d, largestchgpc, lowestchgpc );
2 Likes