How to find the value of a single array element on a specific date

Hi,

I am trying to customize the VAP to use a certain date instead of firstvisiblebar. I’ve tried something like this. ValueWhen returns an array and the pricevoldistribution function here expects a value. Can you help with a fix?

I am just starting and this could be a very simple fix. Searched the forum and function references. The info could already be there. But am having a bit of difficulty finding it. Thanks in advance

// a demo showing 
// re-implementation of VAP overlay using 
// PriceVolDistribution and low-level graphics 
bi = BarIndex(); 
//fvb = FirstVisibleValue( bi ); 
**fvb = ValueWhen(DateTime() == _DT("2016-02-02"),bi,1);**
lvb = LastVisibleValue( bi ); 

mx = PriceVolDistribution( H, L, V, 100, False, fvb, lvb ); 

GfxSetCoordsMode( 1 ); 

GfxSelectPen( colorRed ); 

bins = MxGetSize( mx, 0 ); 
for( i = 0; i < bins; i++ ) 
{ 
price = mx[ i ][ 0 ]; // price level 
relvolume = mx[ i ][ 1 ]; // relative volume 0..1 
relbar = relvolume * (lvb-fvb+1); 
GfxMoveTo( fvb, price ); 
GfxLineTo( fvb + relbar, price ); 
} 

Plot( C, "Price", colorDefault, styleBar ); 

if( ParamToggle("BuildinVAP", "No|Yes") ) PlotVAPOverlay( 100, 100, colorGreen, 2 );

To find a single value of an array on a specific date, use Lookup.

fvb = Lookup(bi, _DT("2016-02-02"));

3 Likes