{ Function: _BarsDisplayed Purpose: Returns the number of bars visible on the chart. This function is useful to positioning text and data horizontally on the the chart as the user knows how many bars total are displayed. The function will return a value of zero until the first bar that is displayed at the left margin of the screen appears. It will then be incremented by 1 per bar, until LastBarOnChart is reached, at which point, its value will be the total number of bars displayed on the chart. If the value is tested when LastBarOnChart is reached, the total number of displayed bars can be used to then position text horizontally on the screen, so it left justified, right justified, centered, or positioned at a percentage of the horizontal range displayed. Notes: A binary search algorithm would be faster, starting from the LastBarOnChart, but this function is called only once per chart loading or refresh, so the additional savings from a more efficient algorithm would be minimal. Examine the method of calling the function below to see how the function is called only once per chart load/refresh. Author: MarkSanDiego Version: 05/17/09 initial version 07/08/09 modified to not require back references from the LastBarOnChart to avoid increasing the MaxBarsBack for the calling function and preventing the calling indicator from plotting as early as possible. Usage: Function should be called once per bar from indicator: vars: NBars(0); if BarStatus(1) = 2 then NBars = _BarsDisplayed; } vars: float LeftDateTime(0), bool StartCount(false), int BarsDisplayed(0); once begin LeftDateTime = GetAppInfo(aiLeftDispDateTime); end; { stop comparing current bars date and time to LeftDateTime once left margin bar is reached } once (ELDateToDateTime(Date) + ELTimeToDateTime(Time) >= LeftDateTime) begin StartCount = true; end; if StartCount then BarsDisplayed = BarsDisplayed + 1; _BarsDisplayed = BarsDisplayed;