Volume at Price --> Explore Possible?

Dear Friends fo Amibroker,
i think the Volume at Price is a very powerful indicator, so my dream is to explore all sp500 stocks for a volume price at price, which is the highest value of the last 260 trading days.

so often at these level a nice bottom is found.

at first, here is the indicator i found in internet. instead of the year --> we need 260 bars.
is that possible? becaus in january we only have a few days to watch....

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();
 
_SECTION_BEGIN("VAP");
segments = IIf( Interval() < inDaily, Hour(), year() );
segments = segments != Ref( segments , -1 );
 
PlotVAPOverlayA( segments , Param("Lines", 300, 10, 1000, 1 ), Param("Width", 80, 1, 100, 1 ), ParamColor("Color", colorGold ), ParamToggle("Side", "Left|Right" ) | 2 * ParamToggle("Style", "Fill|Lines", 0) | 4*ParamToggle("Z-order", "On top|Behind", 1 ) );
Plot(segments, "", colorDarkGrey, styleHistogram | styleOwnScale );
_SECTION_END();

then here is mey try to code that, buy it doesnt work very well....

can you make it better please?

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();

_SECTION_BEGIN("VAP");
segments = IIf( Interval() < inDaily, Day(), Year() );
segments = segments != Ref( segments , -1 );

_SECTION_END();

c1 = HHV(segments, 260);
c2 = segments =c1;
 
Filter= c2;

for example check the ticker mkc, here on the highest vap values a nice bottom was formed then the rallye began... thats i wanna find.

scren1 scren2

thanks for your great help

1 Like

There is a "new" function in town called PriceVolDistribution.

/// exploring POC (point of control) value
/// @link https://forum.amibroker.com/t/volume-at-price-explore-possible/8910/2
/// by fxshrat@gmail.com
/// derived from example of AB manual
/// @link https://www.amibroker.com/guide/afl/pricevoldistribution.html
bi = BarIndex();
fbr = Status( "firstbarinrange" );
lbr = Status( "lastbarinrange" );
fbi = LastValue(ValueWhen(fbr, bi));
lbi = LastValue(ValueWhen(lbr, bi));

mat = PriceVolDistribution( H, L, V, bins = 100, 0, fbi, lbi );

maxv = 0;
bins = MxGetSize( mat, 0 );
for ( i = 0; i < bins; i++ ) {
	price = mat[ i ][ 0 ]; // price level
	relvolume = mat[ i ][ 1 ]; // relative volume 0..1	
	maxv = Max(maxv, relvolume);
}

// point of control
poc = 0;
for ( i = 0; i < bins; i++ ) {
	if ( maxv == mat[ i ][ 1 ] ) {
		poc = mat[ i ][ 0 ]; // price level at highest vap
		break;
	}
}

Filter = Status( "lastbarinrange" );
AddColumn( poc, "POC", 1.2 );

To explore last 260 trading days simply set range to 260 recent bars in analysis toolbar
133

8 Likes

thank for answer, and with which look pack period can i work for the volume price pofil?

which value i have to change?

@odin,

Have you seen the picture below of the code?

In your original message you wrote that you want to look at last 260 trading days.

Secondly your thread subject (as well as your post) mention "...Explore" which in AmiBroker world means executing Analysis Exploration.

That's what the code does... it outputs result(s) in Exploration.

And the picture I uploaded clearly shows where to set 260 recent bars look back period before hitting exploration button.

First you have to choose "1 recent bar" mode in Range menu. Then you insert 260 and hit enter.

And in analysis settings you set to Daily interval since you want to explore trading days. Then you click Explore button.

1 Like

Hi,
Error found in the above AFL at
mat = PriceVolDistribution( H, L, V, bins = 100, 0, fbi, lbi );
I tried for different numbers for bins, but inavain.

Thanks

Even i tried it, but you are troubleshootng in bins parameter but that is not where the issue is.

For some reason, maybe some things would have changed over the time.
currently, in 6.30.5, the last two args, fbi and lbi both return the same Bar Index value which for me is the last bar.
@fxshrat you can please check if you are getting same values.

You can use the code from manual and use the other functions to get first and last visible value.
in same link of pricevoldistribution.html

fvb = FirstVisibleValue( bi ); 
lvb = LastVisibleValue( bi ); 

then it works.

First of all why... apparently you guys do not seem to understand that readers can not see your screen.

If you "scream":

"Error found..."

then it is zero useful because there can be multiple error (messages).

You need to learn to post exact error message.
Is it really so difficult? I don't think so.

Now let me guess... you refer to such message, right?
1

So why not simply reading and trying to understand what that message is saying actually?
It clearly says prices in range are the same or NULL.

1st baby step...
What are prices in that function?
Let's look...
It is 1st two arguments of PriceVolDistribution function -> priceH and priceL -> which are set to H (High) and L (Low) arrays.

Next baby step...
So it obviously would mean that they have to be different to run without such error... (since "different" is the opposite of "same", right?)

Hm, what are reasons for them to be equal.
Well, obviously when O == H == L == C then they are equal.
So for example if you have bars like these ones from data array:

0

So what can be do for such cases?
We could add some artificial small value to one price array argument when both arguments are equal.

priceH = IIf( H == L, H+1e-5, H);
mat = PriceVolDistribution( priceH, L, V, bins = 100, 0, fbi, lbi );

... and the message disappears...

BTW,
Follow the white rabbit:
"How do I debug..."


The code of this thread here is exploration code but not chart code.


Here is edited version together with loop-less POC detection

/// exploring POC (point of control) value
/// @link https://forum.amibroker.com/t/volume-at-price-explore-possible/8910/7
/// by fxshrat@gmail.com
/// derived from example of AB manual
/// @link https://www.amibroker.com/guide/afl/pricevoldistribution.html
bi = BarIndex();
fbr = Status( "firstbarinrange" );
lbr = Status( "lastbarinrange" );
fbi = LastValue(ValueWhen(fbr, bi));
lbi = LastValue(ValueWhen(lbr, bi));

priceH = IIf( H == L, H+1e-5, H);
mat = PriceVolDistribution( priceH, L, V, bins = 100, true, fbi, lbi );

// point of control
mat_sort = MxSortRows(mat, False, 1);				
poc = mat_sort[0][0];	
maxv = mat_sort[0][1];	// Vol. at POC

Filter = Status( "lastbarinrange" );
AddColumn( poc, "POC", 1.2 );
AddColumn( maxv, "Vol. @POC", 1.2 );

PS: You need to set Analysis "Range:" of analysis tool bar. Setting that one to "1 recent bars" makes no sense.

1 Like

As per instruction by Fxsharat, I have tick marked all quottions in the range in the exploration. It works fine.

Thanks

Following AFL ( modifations to the above AFL) gives list of instruments hanging around POC.

/// exploring POC (point of control) value
/// @link Volume at Price --> Explore Possible?
/// by fxshrat@gmail.com
/// derived from example of AB manual
/// @link https://www.amibroker.com/guide/afl/pricevoldistribution.html

// Important Note :
// 1) when you check for syntax error ( verify syntax, it may give error or during execution
// 2) To over come this, before exploration, tick mark all quotation in the range
bi = BarIndex();
fbr = Status( "firstbarinrange" );
lbr = Status( "lastbarinrange" );
fbi = LastValue(ValueWhen(fbr, bi));
lbi = LastValue(ValueWhen(lbr, bi));

priceH = IIf( H == L, H+1e-5, H);
mat = PriceVolDistribution( priceH, L, V, bins = 100, true, fbi, lbi );

// point of control
mat_sort = MxSortRows(mat, False, 1);
poc = mat_sort[0][0];
maxv = mat_sort[0][1]; // Vol. at POC

MV26= Volume*100/MA(V,26); // one month volume average

Filter = Status( "lastbarinrange" );
AddColumn( poc, "POC", 1.2 );
//AddColumn( maxv, "Vol. @POC", 1.2 );
addColumn( IIf(Close>=Open , Close,IIf(Close<Open ,Close,Null)) ,"Close",1.1,colorDarkGrey,IIf(Close>=Open,colorPaleGreen,IIf(Close<Open,colorPink,colorLightGrey)));
addColumn( IIf(poc-Close >=0 , abs(poc-Close),IIf(poc-Close <0 ,abs(poc-Close),Null)) ,"Diff",1.1,colorDarkGrey,IIf(poc-Close >=0,colorPaleGreen,IIf(poc-Close < 0,colorPink,colorLightGrey)));
addColumn( IIf(Close>=Open AND mv26 > 0, mv26,IIf(Close 0,mv26,Null)) ,"MaVol",1.1,colorDarkGrey,IIf(Close>=Open,colorPaleGreen,IIf(Close<Open,colorPink,colorLightGrey)));
SetSortColumns(-2,5);// sort AverageVolume

Small Change/addition done the above AFL.

/// exploring POC (point of control) value
/// @link https://forum.amibroker.com/t/volume-at-price-explore-possible/8910/7
/// by fxshrat@gmail.com
/// derived from example of AB manual
/// @link https://www.amibroker.com/guide/afl/pricevoldistribution.html

// Important Note :
// 1) when you check for syntax error ( verify syntax, it may give error or during execution
// 2) To over come this, before exploration, tick mark all quotation in the range 
bi = BarIndex();
fbr = Status( "firstbarinrange" );
lbr = Status( "lastbarinrange" );
fbi = LastValue(ValueWhen(fbr, bi));
lbi = LastValue(ValueWhen(lbr, bi));

priceH = IIf( H == L, H+1e-5, H);
mat = PriceVolDistribution( priceH, L, V, bins = 100, true, fbi, lbi );

// point of control
mat_sort = MxSortRows(mat, False, 1);				
poc = mat_sort[0][0];	
maxv = mat_sort[0][1];	// Vol. at POC

MV26= Volume*100/MA(V,26);  // one month volume average
DiffPer = abs(poc-Close)*100/Close;
Filter = Status( "lastbarinrange" );
AddColumn( poc, "POC", 1.2 );
//AddColumn( maxv, "Vol. @POC", 1.2 );
addColumn( IIf(Close>=Open , Close,IIf(Close<Open ,Close,Null)) ,"Close",1.1,colorDarkGrey,IIf(Close>=Open,colorPaleGreen,IIf(Close<Open,colorPink,colorLightGrey)));
addColumn( IIf(poc-Close >=0 , DiffPer,IIf(poc-Close <0 ,DiffPer,Null)) ,"DiffPer",1.1,colorDarkGrey,IIf(poc-Close >=0,colorPaleGreen,IIf(poc-Close < 0,colorPink,colorLightGrey)));
addColumn( IIf(Close>=Open AND mv26 > 0, mv26,IIf(Close<Open AND mv26 > 0,mv26,Null)) ,"MaVol",1.1,colorDarkGrey,IIf(Close>=Open,colorPaleGreen,IIf(Close<Open,colorPink,colorLightGrey)));
SetSortColumns(-2,5);// sort Date, Diffper
1 Like