Bars

Functionality

A classical indicator calculates one or multiple values using an existing data series.
Data series can be anything from closing prices to daily lows or values of an hourly period etc.
Every period (meaning all candles of one day, one hour, etc.) is assigned one or more indicator values. The following example is based on an indicator value, such as with a moving average, for example. To calculate a smoothed moving average, TradersYard X needs a data series. In this example, we will use the closing prices. All closing prices of a bar (candle) that are represented in the chart will be saved in a list and indexed.
The current closing price, meaning the closing price of the bar that is on the right-hand side of the chart, will be assigned an index of 0. The bar to the left of that will have an index of 1 and so on. The oldest bar displayed will have an index value of 500.
Whenever a new bar is added within a session it will become the new index 0; the bar to the left of it, which previously had an index of 0, will become index 1, and so on. The oldest bar will become index 501. Within a script (a self-created program/algorithm) the Close will be representative for the array (list) of all closing prices. The last closing price is thus Close [0]; the closing price previous to this will become Close [1], the value before that will become Close [2] and the oldest bar will be Close [501]. The number within the squared brackets represents the index. TradersYard X allows you to use the „bars ago" expression for this in general cases.
Obviously, every bar will not only have a closing value but also a High, Low, Open, Median, Typical, Weighted, Time, and Volume. Thus, the high of the candle that occurred 10 days ago will be High [10], yesterday’s low Low [1]...
Important tip:
The previous examples all assume that the calculations will occur at the end of a period. The value of the currently running index is not being taken into consideration.
If you wish to use the values of the currently forming candle then you will need to set the value of
CalculateOnClosedBar to „false".
In this case, the currently running bar will have the value 0, the bar next to the current bar will have the value 1, and so on. The oldest bar (as in the example above) would now have the value 502.
With close [0] you would receive the most recent value of the last price that your data provider transmitted to TradersYard X. All values of the bar (high [0], low [0]…) may still change as long as the bar is not yet finished/closed and a new bar has not yet started. Only the open [0] value will not change.

Properties of Bars

"Bars" represents a list of all bars (candles) within a chart (see Functionality, Bars).
Bars (public IBars Bars) can be used directly in a script and equates to BarsArray [0] (see Bars.GetNextSessionTimeSpan for more information).
The list of bars itself has many properties that can be used in TradersYard X Script. Properties are always indicated by a dot before the objects (in this case bars, list of candles).
With the OnCalculate() method you can use any properties you want without having to test for a null reference. As soon as the function OnCalculate() is called up by TradersYard X Script, it is assumed that an object is also available. If you wish to use these properties outside of OnCalculate() then you should first perform a test for null references using if (Bars != null).
Copy link
On this page
Functionality
Properties of Bars