SetForeign() or foreign() does not pass BarCount
of the called foreign symbol, it captures O
, H
, L
, C
, V
, OI
, Aux1
and Aux2
arrays.
So, when you write:
you are essentially calling Volume
of foreign symbol BANKNIFTY-I
, however, the BarCount - 1
still refers to the base (options) chart symbol. BarCount - 1
of the base chart does not guarantee that the same bar number would be existent in the foreign symbol that you are calling. Most likely, it could result as a data hole, in other words, data could be missing for that foreign bar.
Both SetForeign() and foreign() function holds a fixup
parameter which reads as:
fixup parameter controls if data holes are filled with previous bar data or not.
-
0 - the holes are not fixed
-
1 - default value - missing data bar OHLC fields are all filled using previous bar Close and volume is set to zero
-
2 - (old pre-4.90 behaviour) - causes filling the holes in the data with previous O, H, L, C, V values
When you specifically ask for BarCount - 1
, you get existent Volume
value of the base (options) chart symbol, however, in your case since BarCount - 1
is possibly non-existent for the foreign Futures symbol (i.e. BANKNIFTY-I) you get 0
as fixup = 1
by default.
I am not sure from where you picked to use BarCount - 1
everywhere as an alternate to LastValue().
Consider going through:
If you are planning to capture more than one array of a foreign symbol or do more than one-liner operation with array(s) on foreign symbol, then using SetForeign() makes sense:
SetForeign( "BANKNIFTY-I" );
futV = V;
/* do something else */
RestorePriceArrays();
printf( "Volume of BNI Option = %1.0f\n", LastValue( V ) );
printf( "Volume of BNI Fut = %1.0f\n", LastValue( futV ) );
Otherwise, you are better with foreign(), like so:
futV = Foreign( "BANKNIFTY-I", "V" );
printf( "Volume of BNI Option = %1.0f\n", LastValue( V ) );
printf( "Volume of BNI Fut = %1.0f\n", LastValue( futV ) );
Also note, if BANKNIFTY-I
foreign symbol does not exist at all in that DB or your 3rd party data-plugin is messing up something, in that case, you're likely to get foreign Volume
as 0
as well.
Lastly, LastValue() fixates at an array's last element value. Alternately, SelectedValue() could also be used which will return array value at currently selected bar.