The TIMEFRAME function in ProBuilder language is used to specify the timeframe for which the trading conditions or variables are evaluated. This is particularly useful in multi-timeframe analysis, where a strategy might involve indicators or conditions across different time periods.
TIMEFRAME(TF, mode)
TIMEFRAME(default)
The TIMEFRAME function can be used in two ways:
Consider a strategy where an RSI indicator on a 1-hour timeframe is used to trigger trades, but trade management (like setting stop losses) happens on a 1-minute timeframe.
defparam cumulateorders = false
// Declare the strategy on the 1 hour timeframe
TIMEFRAME(1 hour, updateonclose)
myrsi = rsi[14]
buycondition = myrsi crosses over 50
// Orders management on the 1 minute timeframe
TIMEFRAME(1 minute, default)
if buycondition then
buy 10 contract at market
endif
if not onmarket then
breakeven = 0
endif
if longonmarket and close - tradeprice >= 15 * pointsize then
breakeven = 1
endif
if breakeven = 1 then
sell at tradeprice + 5 * pointsize stop
endif
graph breakeven
In this example, the RSI indicator is calculated based on the 1-hour timeframe with closed bars only. If the RSI crosses over 50, a buy order is placed in the 1-minute timeframe. The script also manages the stop loss based on the conditions defined.
Using different timeframes in a single strategy allows for more flexibility and detailed control over trade entry and management. It is crucial to understand the implications of the mode parameter, as it affects how data is refreshed and therefore can impact the execution of your trading strategy.