Allows to write conditions and/or declare variables in the selected timeframe (description of the ProBacktest command only on this page).
The syntax of the TIMEFRAME statement is TIMEFRAME (TF, mode) which allows you to put the code in a timeframe different from the main TF, or TIMEFRAME (default) to return to the default TF. “mode” is optional (the default is current bar).
- TIMEFRAME(weekly, UpdateOnClose)
- TIMEFRAME(30 minutes, default)
- TIMEFRAME(5 minutes)
List of TimeFrames available: x second (s), x minute (s), x hour (s), hourly, x day (s), daily, x week (s), weekly, x month (s), monthly, yearly
- UpdateOnClose: only closed bars are used
- Default: The variables defined in superior timeframes take into account each update of the main timeframe
Using a code on a 1 minute timeframe with:
will return values of the closed bars of the 1-hour timeframe for all codes below this instruction and each 1 minute (code is read at Close), while with:
you’ll get the current time values (not closed bars) of the 1-hour timeframe, and each 1 minute (code is read at Close).
The strategy is a 1-hour timeframe check for the RSI to cross over the level 50.
Then the order management is made in the 1-minute timeframe:
- launch an order if the “buycondition” is true (could also been coded in the 1-hour TF, since the crossover only occur on closed bars with “updateonclose”)
- manage the stoploss to put it at open price + 5 points if the price has reached at least 15 points of profit (see picture below for a better comprehension)
//declare the strategy on the 1 hour timeframe
timeframe(1 hour, updateonclose)
myrsi = rsi
buycondition = myrsi crosses over 50
//orders management on the 1 minute timeframe
timeframe(1 minute, default)
//create an order at market if the RSI has crosses the level 50 on the 1 hour timeframe
if buycondition then
buy 10 contract at market
//if not order on market, reset the breakeven status
if not onmarket then
//check if the current order has made 15 points of profit
if longonmarket and close-tradeprice>=15*pointsize then
//put stoploss at open price + 5 points
if breakeven=1 then
sell at tradeprice+5*pointsize stop
Order opened at 03:00 (because the RSI crossed the level 50) and the breakeven function put a stoploss at 08:47. Condition are well checked and executed each 1 minute.