Definition and Purpose:
The PRELOADBARS instruction in ProBuilder language is used to set the maximum number of historical bars that should be preloaded before the execution of a trading system. This is crucial for the accurate calculation of indicators that require a certain amount of historical data to provide reliable results.
DEFPARAM PRELOADBARS = number_of_bars
Here, number_of_bars represents the number of past bars to preload. This value should be set based on the maximum look-back period of the indicators used within the trading strategy.
Consider a scenario where you are using a moving average based on the last 100 bars to make trading decisions. To ensure that the moving average is calculated accurately from the start of the trading system, you need to preload at least 100 bars.
DEFPARAM PRELOADBARS = 150
myMA = average[100](close)
IF NOT ShortOnMarket AND close[1] < myMA[1] THEN
SELLSHORT 1 SHARES AT MARKET
ENDIF
SET STOP %TRAILING 2
In this example, PRELOADBARS is set to 150, which is more than sufficient to calculate the 100-bar moving average from the beginning of the dataset. This setup helps in making immediate and accurate trading decisions as soon as the trading system starts.
PRELOADBARS to a higher number than needed can increase the memory usage and computational time, so it should be optimized based on the maximum look-back period required by your indicators.PRELOADBARS is set too low relative to the needs of your indicators, it may lead to inaccurate calculations and potentially misleading trading signals at the start of the data series.This instruction is particularly important for strategies that involve complex indicators or those that require a significant historical context to function correctly, such as moving averages, exponential moving averages, or other similar technical analysis tools.