First approach to multi timeframe trading with ProRealTime

Hello everyone, in this article I will present a new feature long awaited by many traders, “multi timeframe” support for automatic trading with ProBacktest and ProOrder!

What is the multi-timeframe mode?

Since some of you will have no idea what it is and why it is so important and interesting, I will briefly explain to you how and why to use different timeframes in programming and what impact it can have on your trading strategies.

Use different timeframes to build strategies:

When building a trading strategy, it is common to use valuable information over multiple time units. For example: imagine that for your new scalping strategy on DAX in 1 minute, you need to know the daily trend of the market, in a 5 minute chart using moving averages or any other equivalent indicators. So far (and without our new tool!) to get data from superior timeframes, you had to use your calculator and rules of 3 to define the hypothetical periods that would have given us approximate data of the daily MA in a 5 minute timeframe. This is no longer the case today, now we can call data directly from any other TF on the fly to make our trading decisions.

See also the updated documentation keyword: TIMEFRAME (ProBacktest / ProOrder)

Let’s create our first multi-timeframe strategy!

Our trading strategy on the DAX could thus be programmed like this:

So we have in our strategy 2 different timeframes, one in the 5 minute timeframe (declared at the beginning of the code) and the “default” timeframe. This one defines the timeframe which is used to launch the strategy under ProBacktest or ProOrder, in our example it would be the 1 minute timeframe.
Separating time units implies that each variable will be calculated in the timeframe in the block where it is located. Our variable “MA20” is thus calculated in the 5 minute TF, but this one can be tested in any other TF as it is on line 13, in the “default” TF in the variable “bulltrend “.

You will notice that the syntax editor uses a different color with every block of code which uses a different timeframe, declared with the help of the TIMEFRAME instruction (the same instruction which is used for ProScreener, but with a different syntax that we will discuss more later) and other than the main one (the default TF):

The calculation rate and the variables updates (syntax)

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).

Examples:

  • 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

Available modes:

  • UpdateOnClose: only closed bars are used
  • Default: The variables defined in superior timeframes take into account each update of the main timeframe

Warning!

UpdateOnClose allows to read the code and thus to inform the variables only once per bar, at its closing. It should be understood that without the use of this mode, the variable data is updated with each new bar of the “default” time unit.
So without having declared this mode in our example code, the variable MA20 of the 5 minute TF would have been filled with the Close of the 1 minute bar. This will be of enormous importance if you want to get the right data from your indicators in the upper timeframes! Why ? Simply because, as a general rule, we are still waiting for closure to consider accurate information and this is all the more important when we consider making trading decisions based on indicator calculations.

Difference between UpdateOnClose and “default” mode

We can use the GRAPH instruction to visualize our different variables calculated in different TF:

In “UpdateOnClose” mode, our variable MA20 of the 5-minute chart (in red), recalculates only once every 5 minutes.

In “default” mode, the variables of the 5-minute timeframe are calculated at each update of the default timeframe, so we notice that the orders are different, since it is no longer the same strategy !!

What to know about this particularity:

  • In “updateonclose” mode, the code of the TIMEFRAME are evaluated at each new bar of the TIMEFRAME, so the variable is naturally logged in the upper TF.
  • In “default” mode, the entire code is evaluated at each index change of the main TF. However, the index of the variables in the upper TIMEFRAME is incremented only when the index of their TF is changed, while the current state [0] of the variables is reset to its value at the close of the last aggregated candlestick (either [1]) before evaluating the TIMEFRAME code.

Interaction with orders

What many of you expect from this new feature is the ability to interact with orders, without waiting for the bar of our strategy to be completed and therefore the code to be read.
Indeed, the multitimeframe mode does not change the behavior of ProBacktest / ProOrder. The code is always read only once per bar and when it is closed. Except that now we can use a 15-minute strategy and interact with its orders every minute.

Sample strategy:

  • Orders are triggered with a cross with the SuperTrend in the 15-minute TF with close data (blue line)
  • The stoploss level is calculated with the last 20 lowest low in the 5-minute TF in real time because it does not use the UpdateOnClose mode (red line)
  • The stoploss is changed every minute if necessary

The black line represents the Close of the 1 minute candlestick.

As you can see, this opens a wide field of new possibilities and exploration for automatic trading strategies, such as:

  • Using information from other time units to comfort you in your trading decisions
  • Changing your stoploss and takeprofit on the fly, within your strategies
  • Entering or exiting before the market closes in a daily strategy
  • Partially closing your positions inside candlesticks
  • Opening new positions inside bars if the market gives you reason
  • Etc ..

In short, you will need to unlearn everything you thought before, there is now almost no limit, now only your imagination that will limit your development!

 

Manual trading with ProOrder!

Another new feature is the ability to GRAPH indicators and thus benefit from the multi-timeframe instruction in manual trading. Indeed, displaying indicators of other time units is still not possible in the price chart, so why not use what ProBacktest offers us?

Imagine that in your daily trading, you use the moving averages 20 and 50 periods in the 5-minute TF. But you need 15-minute Bollinger Bands and the Daily Trend with a SMA20. So let’s declare these variables in a trading strategy and “GRAPH” all of them:

Here’s what this displays on our screen:

After launching the backtest, the chart will update automatically and you will have multi-timeframe (MTF) support for your manual trading too!
Of course, this is hijacking of the functionality to allow us to use it in our manual trading, you will not have candlesticks, nor all the graphical features that the ProBuilder language offers, but I think that this will interest many traders!

 

Multi-timeframe, a new approach for automatic trading with ProRealTime

I am very excited about the coming weeks, and all the new ideas that will emerge from our members. This new feature for automated trading will allow us to explore new strategies like never before with ProRealTime.
The discussions and test strategies have already started on the forum in this topic: [beta-testing] multi timeframe support for automatic trading, ideas are welcome! (I’ll meet you there for all your questions!).

ProRealTime has released a short video about benefit of the new engine that embed the Multi timeframe functionnality: 

Share this

  1. Roberto S. • 07/03/2018 #

    Hi, very useful! Is this feature already available?

    • Nicolas • 07/03/2018 #

      Yes, it’s available through ProRealTime software account: https://www.prorealtime.com
      And also very soon for IG/PRT Sponsored ones (within a few weeks). But first for DEMO accounts, and it is planned for next week.

  2. turame • 07/03/2018 #

    Hello !

    I’m afraid that the code given in the video doesn’t as the video showing it. Maybe is it an other code ??
    I”m sorry but I can’t add a picture here. But if anyone can test the following code and tell me if I’m crazy (^_^)
    Here is the code used in the video :

  3. turame • 07/03/2018 #

    Sorry, the code doesn’t want to display it here…

  4. Lucie RIBAUDEAU • 07/03/2018 #

    Bonjour, pour tendance haussière on utilise ” bulltrend” et pour tendance baissière ? j’ai essayé avec ” downtrend” mais cette variable n’est pas reconnue par PRT. merci

    Hello, for uptrend we use “bulltrend” and for downtrend? I tried with “downtrend” but this variable is not recognized by PRT. thank you

    • Nicolas • 07/03/2018 #

      En effet, il n’y pas d’exemple pour la tendance baissière. Il faudrait programmer cette partie.

  5. Leo • 07/03/2018 #

    If this is the 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.
    Can be X a variable to be optimize?
    Thanks

  6. golha • 07/03/2018 #

    Thanks, have been waiting for this for years! Just wish it could be on real trading accounts in IG VERY SOON.

  7. golha • 07/03/2018 #

    will it be in V10.3 in IG or there will be a 10.4 for this function? just want to know when it is available for live accounts.

    • Nicolas • 07/03/2018 #

      Should be available for live accounts in October. But you can already ask your broker to activate it on your personal account.

    • planbtrading • 07/03/2018 #

      thanks Nicolas for your tutoring on this topic. IG have recently told me MTF still being tested and only available on DEMO accounts. Is this response consistent for everyone else?

      best, PlanB

    • Nicolas • 07/03/2018 #

      That’s right. Still only usable on demo accounts for now.

  8. gabri • 07/03/2018 #

    Nicolas, anything yet for ProBuilder?

  9. jonjon • 07/03/2018 #

    Hi Nicholas

    I’m so excited about this functionality. I’ve been following at a distance but devoting more time to it now.

    I’m just repeating the Q from gabri above: any idea if / when we will have MTF with ProBuilder? I’m trading through Interactive Brokers and I’m interested in triggering orders from bespoke indicators as a way of semi automating things.

    Thanks

    Jonathan

    • Nicolas • 07/03/2018 #

      PRT should work on MTF for ProBuilder next year, as an update of the v11 to come, from the last news I have.

  10. Frankyboy • 07/03/2018 #

    Hi Nicolas,
    I am really looking forward to the multi-timeframe feature, but was told today that it is still uncertain when it can be used in live trading… do you have any more insights / updates on this?
    I would specifically like to use it for closing positions on higher timeframe strategies (1h, 2h) shortly before IG charges overnight fees (say around 21:55 London time), by switching to a 1min timeframe or so. I am afraid that the “DEFPARAM flatafter 220000” command will not guarantee the positions closures before IG makes the cutoff. Until it is possible to use different timeframes in one strategy, do you know of other (automated) ways to accomplish position closures around 21:55 on a 1h or 2h chart?
    Thanks in advance!

    • Nicolas • 07/03/2018 #

      There is no other way to do that than uses the round hour test like the way you already do.

  11. smokingfox • 07/03/2018 #

    Hi Nicolas, i am testing a strategy in 1 hour timeframe. one of the pieces of code i am using in the strategy is the Complete trailing stop code function.
    This code calculates the SL once the bar has closed. on a one hour timeframe this is a long time to be exposed unless i put a “stop ploss x” in the script.
    I have tried to use the timeframe function to calculate the Complete trailing stop code function on a lower time frame so that my trailing stop is calculated more frequently, e.g. on a 5minute timeframe, the SL would update every 5 minutes from the commencement of the hourly bar.
    however this doesnt seem to be allowed as the system says you need to use a lower timeframe as your base and then use your indicators from the higher timeframe to initiate positions.

    My first question is:
    Am i able to code the system in the way i have been trying to , by pulling through the lower timeframes to calculate in a higher timeframe strategy.

    My Second question is:
    I am trying to write my script in a low timeframe, say 5minutes, using indicators from the high timeframe, 1hour, to determine entering into transactions. i.e. to replicate my trade execution from the high timeframe model. This then allows the Complete trailing stop code function to calculate on the lower timeframe.
    However, the error i get now is that on the 5 minute timeframe, if i am not longonmarket, the model is taking positions on each bar within that 1hour period. If the position is closed because of take profit or stop loss, then a new position is opened on the next bar.
    This is too many positions!
    what i wanted was to open the position at the start of the hourly bar based on the rules of the hourly trading setup, and then exit trades based either on the hourly rules, or on the calculation of the trailing stop which is to be calculated on the 5minute time frame.

    grateful for any thoughts or feedback you can provide.

    • Nicolas • 07/03/2018 #

      1/ Yes, but the strategy must be launched on the smaller timeframe.
      2/ In this case, you need to declare that you want to use the values of the superior timeframe that are updated only at Close with “updateonclose”:
      TIMEFRAME(1 hour, updateonclose)

  12. Bel • 07/03/2018 #

    Greetings Nicolas and the crew. My system is looking at the daily code for bias once the daily bar closes and need to use 5min code for entries and exits for example. So i need to launch the strategy from the 5min tf and declare i want to use values of the superior tf updated on Close: TIMEFRAME(Daily, updateonclose) if i understand correctly. Please correct me if I’m wrong. Thank you in advance:) Happy coding and happy trading!

    • Nicolas • 07/03/2018 #

      Right, this is how it should be coded. Quick and simple example here: https://www.prorealcode.com/topic/echelle-de-temps-multiples/#post-82039

    • Bel • 07/03/2018 #

      Thank you Nicolas.

  13. robdav • 07/03/2018 #

    Hi Nicolas

    The multitimeframe GRAPH hack above is very useful.

    Do you know if PRT are planning on releasing the ability to do multitimeframe indicators without having to use the workaround above?

    Thanks

    Rob

    • Nicolas • 07/03/2018 #

      Yes it will be added directly into ProBuilder programming for indicators, without using this workaround.

  14. robdav • 07/03/2018 #

    Any idea which version/release date? Thanks.

  15. VN • 07/03/2018 #

    Hi Nicolas, thank you for posting this blog on MTF. I have a very simple code which looks at the ROC on a default TF (1min) and a 5min, but it seems like the ROC values on the 5min TF are not the same as those ROC values returned from running a separate 5 min chart with the same indicator. I am using “updateonclose” and I also tried “default” but it just does not work correctly.

  16. VN • 07/03/2018 #

    here is the code (i couldnt paste it using the Add PRT code”

    timeframe(5 minute, updateonclose)
    myRSI5 = rsi[14](close)
    myROC5 = ROC[14](close) // set the 5 min interval calculation point
    condition1 = myROC5 < 0 AND myROC5[0] < myROC5[1] // to be done on a 5 min timeframe interval

    timeframe(default)
    myRSI = rsi[14](close)
    myROC = ROC[14](close) // reset the time frame calculation window so everything below this line will be evaluated against the specified TF on the chart
    condition2 = myRSI crosses under 30 // evaluated on the default chart time frame
    condition3 = myROC < 0 AND myROC[0] < myROC[1] // evaluated on the default chart time frame

    IF NOT ShortOnMarket AND condition1 AND condtion2 AND condition3 THEN
    SELLSHORT 1 at MARKET
    ENDIF

  17. VN • 07/03/2018 #

    I would expect that the condition1 line specifically the “myROC5[0] < myROC5[1] " part of the code to return the ROC at the 5 min closes TF so for example, if I am running this code on a 1 min chart (default setting) eg. if I pick a random time, say 11:17, then I would expect myROC5[0] to be the ROC value as of 11:15 as that is the nearest complete candle on a 5 min chart and the myROC5[1] to be the 11:10 ROC value. When I plot the myROC5 value of this script and I compare it to a ROC running on a separate 5 min chart, the values are not the same. Is this to be expected? Would be grateful if you can provide any assistance?

    • Nicolas • 07/03/2018 #

      Please open a new specific topic with codes and explanation like you did here, better for discussions, thanks.

  18. VN • 07/03/2018 #

    Hi Nicolas, I have raised this question already under an MTF related topic here – https://www.prorealcode.com/topic/mtf-sequential-setup/page/2/. Would really appreciate if you can opine on the query as the “updateonclose” logic of the timeframe function produces puzzling results..

  19. Crystal Babe • 07/03/2018 #

    Hi Nicolas, any update yet if this method can be used on IG sponsored PRT charts ?
    is there a simplified method to do this or needs to be manually coded?

    • Nicolas • 07/03/2018 #

      MTF is available for IG PRT since a long time. The simplified creation of code is not yet supporting it (but I might be wrong since I don’t use it). There are a lot of topics that deal with MTF coding in the forums. A non exhaustive list: (topics tagged with “MTF” keyword): https://www.prorealcode.com/topics-tag/mtf/

  20. Crystal Babe • 07/03/2018 #

    ok thanks, the lat time i enuired they said not yet, will try to add to my codes.cheers

avatar
Register or

Top