• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi-timeframe questions

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Multi-timeframe questions

    (Yes I've read, and re-read the section on multi-timeframe programming..)

    The problem is, assuming the primary timeframe is 10min chart, Add() two additional, hourly and 2min of the same instrument to the indicator.

    If the logic is to compute something (same logic for all three), store the results somewhere, then the main one (10min) will also do the 2nd pass of the logic, based on the current states gathered from the other two, and its own.

    The 'states' are stored in one list per time frame, and the lists are stored in a static array so 10min one can reference all of them. This is not the problem.

    Something like

    All will need to do

    Part1( mylist); // my list to store the states

    then
    the 10min will do

    Part2();


    The problem is, when the 10min is ready to do the trade logic computation based on 'current states of all three', how to ensure the 10min's OnBarUpdate is called AFTER the hourly and 2-min.

    I am not using OnBarClose true, I will maintain my own tick count and maybe do the real thing every, say 133ticks.
    The problem still exists if I am doing my counting every 133k, i.e., I want to have the hourly and the 2-min execute its logic and update the states before the 10min do its work.

    One thing I can do is to let 10min do ALL the work, including those of hourly and 2min, but this means I will need to write three versions of the Part1() code.

    Suggestions?

    #2
    Hello balancenv,

    I am not quite sure what exactly you are trying to do and how you want it to function. Can you show me some snippets or pseudo code of how you are calling these custom methods and what results you are getting vs the results that you expect?

    Happy to be of further assistance.
    JCNinjaTrader Customer Service

    Comment


      #3
      Let me rephrase the question:

      if I add hourly, and 2-min, in addition to the original 10min timeframe to an indicator, and if the CalculateOnBarClose is false.

      What is the sequence UpBarUpdate will be called for each of the timeframe, on each incoming tick?
      is it always 10min first, then in order of how others were added? or ?

      Is the sequence fixed and guaranteed or random?

      Comment


        #4
        Primary bars will always be executed before the secondary bars.

        The sequence would be as such over the course of an hour on historic bars

        0 = 10 minute
        1 = 2 minute
        2 = 60 minute

        0 | 09:30
        1 | 09:30
        2 | 09:30
        1 | 09:32
        1 | 09:34
        1 | 09:36
        1 | 09:38
        0 | 09:40
        1 | 09:40
        1 | 09:42
        1 | 09:44
        1 | 09:46
        1 | 09:48
        0 | 09:50
        1 | 09:50
        1 | 09:52
        1 | 09:54
        1 | 09:56
        1 | 09:58
        0 | 10:00
        1 | 10:00
        1 | 10:02
        1 | 10:04
        1 | 10:06
        1 | 10:08
        0 | 10:10
        1 | 10:10
        1 | 10:12
        1 | 10:14
        1 | 10:16
        1 | 10:18
        0 | 10:20
        1 | 10:20
        1 | 10:22
        1 | 10:24
        1 | 10:26
        1 | 10:28
        0 | 10:30
        1 | 10:30
        2 | 10:30

        For the real-time bars, it will call 0, 1, 2, etc just like you were seeing on historical


        You can test this yourself using the following

        Code:
        			protected override void Initialize()
        			{
        				Add(PeriodType.Minute, 2);
        				Add(PeriodType.Minute, 60);
        				
        			}
        
        			protected override void OnBarUpdate()
        			{
        				
        				Print(BarsInProgress + " | " + Time[0].ToString("HH:mm"));
        				
        			}
        Last edited by NinjaTrader_Matthew; 01-30-2013, 03:19 PM.
        MatthewNinjaTrader Product Management

        Comment


          #5
          Thanks for the note. This was not my original question but your reply did help.
          This is for anyone will think helpful, as I have in the past learning from this forum.

          Assume you have 5 min, 2 min and 1 min with 2min being the main timeframe.
          And you want for each timeframe to compute something, then the 2min will gather all the information and make trade decision.

          But if 2-min wants to make decision based on 5min's states right now, we have to set onbarclose to false, and use tickcount to force 2-min logic is executed after the other two.

          Below is a sample code to accomplish this:
          You can modify the mod internal as you wish.
          PHP Code:
            protected override void Initialize()
                  {
                      
          Add(PeriodType.Minute1);
                      
          Add(PeriodType.Minute5);

                  }

                  protected 
          override void OnBarUpdate()
                  {
                      
          int tck BarsArray[2].TickCount 10;

                      if (
          tck >= 3)
                          return;

                      if ((
          tck == 1) && (BarsInProgress 0)) // everyone except the main timeframe
                          
          Print(BarsInProgress " | " BarsArray[2].TickCount " | " DateTime.UtcNow.ToString("HH:mm:ss.ffff"));
                      else
                      {
                          if ((
          tck == 2) && (BarsInProgress == 0)) // main timeframe
                              
          Print(BarsInProgress " | " BarsArray[2].TickCount " | " DateTime.UtcNow.ToString("HH:mm:ss.ffff"));
                      }
                  } 

          Sample output window shows when 2-min is executed (barsinprogress is 0), it has the latest information ...

          1 | 171 | 08:10:50.5594-05:00
          2 | 171 | 08:10:50.5594-05:00
          0 | 172 | 08:10:50.5914-05:00 <---
          1 | 181 | 08:11:01.3550-05:00
          2 | 181 | 08:11:01.3550-05:00
          0 | 182 | 08:11:01.4780-05:00 <---
          1 | 191 | 08:11:20.5731-05:00
          2 | 191 | 08:11:20.5731-05:00
          0 | 192 | 08:11:20.5731-05:00 <---
          1 | 201 | 08:11:24.1003-05:00
          2 | 201 | 08:11:24.1003-05:00
          0 | 202 | 08:11:24.1003-05:00
          1 | 211 | 08:11:24.1603-05:00
          2 | 211 | 08:11:24.1603-05:00
          0 | 212 | 08:11:24.1603-05:00
          1 | 221 | 08:11:26.5315-05:00
          2 | 221 | 08:11:26.5315-05:00
          0 | 222 | 08:11:26.5315-05:00
          1 | 231 | 08:11:26.6585-05:00
          2 | 231 | 08:11:26.6585-05:00
          0 | 232 | 08:11:26.6585-05:00
          1 | 241 | 08:11:32.2718-05:00
          2 | 241 | 08:11:32.2718-05:00
          0 | 242 | 08:11:32.4278-05:00

          Comment


            #6
            Bugs in market replay?

            I tried the same code under market replay.

            Well, if I make the primary timeframe as 5 min and adding two additional timeframes, one 2 min, the other 10 min, then the code will work as in real time.

            HOWEVER, when the 10min is changed to 30min, the (2) part was never printed out, meaning the onbarupdate was never executed for the 30min on each tick coming in.

            Is this a bug, or 'optimization feature' for market reply??

            1 | 11251 | 07:33:19.0763
            0 | 11252 | 07:33:19.0763
            1 | 11401 | 07:33:21.9345
            0 | 11402 | 07:33:21.9345
            1 | 11551 | 07:33:24.0206
            0 | 11552 | 07:33:24.0206
            1 | 11701 | 07:33:25.8357
            0 | 11702 | 07:33:25.8357
            1 | 11851 | 07:33:26.3608
            0 | 11852 | 07:33:26.3608

            Comment


              #7
              Hello balancenv,

              There is no issues using Market Replay and a Multi-Series Script that I am aware of. If you Print() the BarsInProcress without a Condition you should see the respected order of Multi-Time series.
              JCNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by ralett, Today, 11:28 AM
              0 responses
              1 view
              0 likes
              Last Post ralett
              by ralett
               
              Started by ChazJ, Today, 09:59 AM
              1 response
              4 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by Irukandji, Today, 09:34 AM
              1 response
              3 views
              0 likes
              Last Post NinjaTrader_PatrickG  
              Started by lunardiplomacy, Today, 08:32 AM
              3 responses
              12 views
              0 likes
              Last Post NinjaTrader_PatrickG  
              Started by ralett, Today, 08:24 AM
              1 response
              11 views
              0 likes
              Last Post NinjaTrader_PatrickG  
              Working...
              X