The CalculateOnLastBars instruction in ProBuilder language is designed to optimize the performance of trading indicators by limiting the number of bars used in calculations. This feature is particularly useful for reducing memory consumption and speeding up the computation of indicators, especially when dealing with large datasets.
Purpose: The primary purpose of this instruction is to enhance the efficiency of indicator calculations by specifying the number of most recent bars to consider. This not only conserves memory but also accelerates the processing time, making it ideal for real-time data analysis.
DEFPARAM CalculateOnLastBars = n
Where n represents the number of bars to calculate from the most recent bar backwards.
Suppose you want to calculate a moving average but only for the last 100 bars to ensure quick computation. You would use the following code:
DEFPARAM CalculateOnLastBars = 100
myMovingAverage = Average[100](close)
This code snippet sets the calculation to consider only the last 100 bars for computing the moving average of the closing prices.
It’s important to note that using CalculateOnLastBars can affect the appearance and accuracy of indicators on a chart, as calculations ignore older data beyond the specified bar count. This parameter should be used judiciously, particularly when historical data is crucial for the analysis.
For beginners, it’s advisable to experiment with different values of n to see how it impacts the performance and output of your indicators. This instruction is not tied to any specific type of indicator (like RSI, MACD, etc.), and can be used universally across various calculations where performance optimization is desired.