Support / Resistance using VAP

I am exploring the idea of getting support/resistance from volume (not really new one, I do agree).

Inspired from Volume at Price --> Explore Possible? and I ended up with this code which:
compute VAP for the last 63 days,
extract the 4 biggest volume peak
get the associated price
plot the price corresponding to the volume peak for each and every day.

Being new to AFL, I am not sure about the strategy I used. Feedback on improvement would be appreciated.
Thanks in advance.

priceH = IIf( H == L, H+1e-5, H); // to avoid error if H = L , ref

lookback = 63;

for ( i = lookback; i < BarCount; i++ )
	//Compute VAP
	mx = PriceVolDistribution( priceH, L, V, bins = 100, true, i-lookback, i );
	row_size = 100; 
	//Get Volume & Price Distribution
	vol_distrib = MxGetBlock(mx, 0, row_size-1, 1,1,True);
	price_distrib = MxGetBlock(mx, 0, row_size-1, 0,0,True);
	//Find Volume peaks using PEAK function
	pk = Peak(vol_distrib, 30, 1);
	pk = IIf(IsNull(pk), 0, pk);
	pos = Ref(pk,-1) != pk;
	//Create a matrix with volume 0 if no peak
	mx_peak = Matrix( row_size, 2, 0 );
	mx_peak = MxSetBlock(mx_peak, 0, row_size-1, 0,0,price_distrib);
	volume_peak = vol_distrib * pos;
	mx_peak = MxSetBlock(mx_peak, 0, row_size-1, 1,1,volume_peak);
	//Sort Matrix to access corresponding price values
	mx_peak_sorted = MxSortRows(mx_peak, False, 1);
	//Extract the first 4 biggest volume
 Plot(sl_1, "sl_1", colorRed, styleLine | styleThick);
 Plot(sl_2, "sl_1", colorBlue, styleLine | styleThick);
 Plot(sl_3, "sl_1", colorGreen, styleLine | styleThick);
 //Plot(sl_4, "sl_1", colorBlack, styleLine | styleThick);
1 Like

Hello @JeanChristophe

I've created a new AFL on my PC with your code, and it takes ~3sec for the screen to refresh!, and when I look at "Code check & Profile", there are no errors, however, there are ~18,000 executions of Peak() on ~18,000 EoD bars (S&P 500 Index since 1950):


In your post:

I suspect that the starting point of the for() loop needs modification:

sl_1	= sl_2	= sl_3	= sl_4	= Null ;

cnsStartBar	= Max(0, BarCount - lookback) ;   // Protection against an array out of bounds error

//for ( i = lookback; i < BarCount; i++ )
for ( i = cnsStartBar; i < BarCount; i++ )

After the mod, it now completes in ~6 millisec:


You might want to limit the calcs to the visible bars.

As to whether it provides an edge, I'm still evaluating.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.