Hello,
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 https://forum.amibroker.com/t/volume-at-price-explore-possible/8910/2
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
sl_1[i]=mx_peak_sorted[0][0];
sl_2[i]=mx_peak_sorted[1][0];;
sl_3[i]=mx_peak_sorted[2][0];;
sl_4[i]=mx_peak_sorted[3][0];;
}
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);