Purpose

This function displays the number of bars visible on a chart.

Users have the functions GetAppInfo(AiHighestDispValue) and GetAppInfo(AiLowestDispValue) to determine the highest and lowest values that are currently displayed on a chart. These are useful for positioning custom text on the chart, and also to determine which indicators are close enough to the price action to warrant their display on the chart. With the highest and lowest values known, users can code the vertical position of text as a percentage of total vertical height, to maintain the relative position of the text as the price range on the chart varies.

Similar functions GetAppInfo(AiLeftDispDateTime) and GetAppInfo(AiRightDispDateTime) are available to determine the leftmost bar and the rightmost bar DateTime. However, these are more awkward for use in positioning text horizontally on a chart, since the position must be converted to an “offset” number of bars for the functions Text_New(Date(Offset), Time(Offset), Price, “Text To Display”) and Text_SetLocation(Text_ID, Date(Offset), Time(Offset), Price).

If the number of bars displayed on the chart is known, then the offset for the leftmost bar is also known. Once the offset of the leftmost bar is known the user could position text on a chart as a percentage of the horizontal time range as conveniently as the vertical position can now be specified. This would allow the text to maintain it’s relative hozontal position if the chart were resized or the density of its bar spacing were altered.

The indicator custom text displays the input parameters used to generate the Bollinger ribbons. The input parameters of this indicator have specified that this custom text should be positioned at the 50% horontal time range of the chart. After function _BarsDisplayed calculates the number of bars displayed in the above chart, the horizontal midpoint bar offset is easily calculated so the custom text can be correctly displayed.

This text will automatically maintain a center position on the horizontal axis, regardless of the size of the chart or the bar spacing density.

Function Method

Function GetAppInfo(AiLeftDispDateTime) is called to determine the DateTime of the leftmost bar of the chart. Once the chart is loaded and a LastBarOnChart condition occurs, a loop walks toward the left from the rightmost bar until the DateTime of the loop’s target bar equals the leftmost bar DateTime, and counts the associated offset to the leftmost bar.

Although a binary search method would be faster, it is questionable whether the additional complexity would be warranted, as the _BarsDisplayed function is called once and only once when the chart is either loaded or refreshed.

This method works for all time frames: monthly, weekly, daily, intraday (minute) and tick bars. It produces the correct result regardless of short trading days, holidays, or session length. It’s simplicity makes it easy for users to understand and also to modify for other purposes.

Downloads

 Initially posted version:  05/07/09

Latest Update:  05/17/09

*.ELD files are compiled for TS 8.6

All ELD and code text files packaged here:

BarsDisplayed.zip

Users of earlier versions fo TradeStation may compile the code
from the text files included in the above *.zip file.

The code may be visualized here:

Indicator BarsDisplayed

Function BarsDisplayed