# 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);
``````

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

``````

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);
``````

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( Ref( C, -1 ), "yesterdays Close" );
AddColumn( ( Open - Ref( Close, -1 ) ), "raw Change", 1.2 );
AddColumn( ChangePercent, "Percent Change", 1.2 );
``````chgpc = ROC(Close,1);