Get first visible bar index

fvbi = FirstVisibleValue( bi );
qfdb = Status( "quickaflfirstdatabar" );

fdb = qfdb + fvbi;
fi = fdb;

```[quote="jay1, post:1, topic:25224, full:true"]

fvbi = FirstVisibleValue( bi );
qfdb = Status( "quickaflfirstdatabar" );

fdb = qfdb + fvbi;
fi = fdb;

[/quote]

i am not geting first visible bar index it gives 0 as bar index but at c[fi] it gives close of first bar of database.

@Jay1, in indicator mode, the first visible bar index is the one you get with FirstVisibleValue( bi ); as per your first line (you do not need to add anything).

The FirstVisibleValue() function allows you to get the first visible value for any array you pass to it, so you can use it also to get other arrays values and not only a bar index.

The alternative to it, usable only for the bar index is the Status() function:

  • "firstvisiblebar", "lastvisiblebar", "firstvisiblebarindex", "lastvisiblebarindex" - return bar number or bar index of first/last visible bar. Available in indicator mode only. Visible bar may potentially include "blank" future bars (past the last bar in the array) as defined in preferences.

So you could use it to know the number of the "TRUE" total visible bars (and calculate the "blank" bars).
Try this snippet (to see the difference your chart need to have some "blank" bars):

bi = BarIndex();
biFvb = FirstVisibleValue( bi );
biLvb = LastVisibleValue( bi );
stFvb = Status("firstvisiblebar");
stLvb = Status("lastvisiblebar");
blanks = stLvb - biLvb; 
biTotBars =  (biLvb - biFvb + 1);
stTotBars =  (stLvb - stFvb + 1);
title = "Fvb(bi): " + biFvb +  " Lvb(bi):  " + biLvb + " Visible Bars (bi): " + biTotBars + " BLANKS: " + blanks + "\n" +
	  "Fvb(Status): " + stFvb + " Lvb(Status): " + stLvb + " Visible Bars (Status): " + stTotBars + "\n" + 
	  "VisibleBar(bi) + BLANKS == " + (biTotBars + blanks) + " (same as " + stTotBars + "  Visible Bars (Status)";

The Status() function, as you know, can also be used for other purposes:

  • "quickaflfirstdatabar", "quickafllastdatabar" - This feature is for internal use only. These are bar indexes of actual underlying compressed quotation array that make up AFL's array[ 0 ] and array[ BarCount - 1]

I already commented on the use of this feature here.

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