Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Basic multi-time frame question

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

    Basic multi-time frame question

    I have the following code. I'm using one minute data. Unfortunately nothing is printed out. If I change to "Add(PeriodType.Minute, 30)" there is printing but not when "Add(PeriodType.Minute, 60)" is used. What am I missing?
    Code:
    [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]protected [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]override [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] Initialize()[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]Add(PeriodType.Day, [/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]CalculateOnBarClose = [/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
    [FONT=Courier New][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080]<summary>[/COLOR][/SIZE][/FONT]
    [FONT=Courier New][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000] Called on each bar update event (incoming tick)[/COLOR][/SIZE][/FONT]
    [FONT=Courier New][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080]</summary>[/COLOR][/SIZE][/FONT]
    [FONT=Courier New][SIZE=2][COLOR=#0000ff]protected [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]override [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] OnBarUpdate()[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
    [FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] (BarsInProgress == [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
    [FONT=Courier New][SIZE=2]Print([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"Here"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
    [FONT=Courier New][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
    [/COLOR][/SIZE][/FONT]
    Last edited by jonesr227; 08-25-2007, 08:11 PM.

    #2
    I don't see anything wrong with your code. Hmm. Do you have enough historical data loaded for the 60min bars? Are there any errors in the log?

    I have attached a multi-instrument reference sample that has code exactly like yours and it works fine on my comp. Please see if it works for you.
    Attached Files
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by Josh View Post
      I don't see anything wrong with your code. Hmm. Do you have enough historical data loaded for the 60min bars? Are there any errors in the log?

      I have attached a multi-instrument reference sample that has code exactly like yours and it works fine on my comp. Please see if it works for you.
      Josh,

      I'm using 1 min data from 1/1/07 to the present. No errors are appearing in the log.

      I tried your code. I don't know how to import this code (is this possible?) so I just cut and pasted into my code. The code works OK. I tried 60 minute up to 240 minutes and it all works. But as soon as I change "Add(PeriodType.Minute, 240);" for example to "Add(PeriodType.Day, 1);" it no longer works; i.e. nothing is printed out and nothing appears in the error log.

      This should work, shouldn't it?

      Comment


        #4
        To import the NinjaScript archive: http://www.ninjatrader-support.com/H...e.html?Import1

        Yes, theoretically it should work but like you've noticed it isn't. I am experiencing the same behavior you are so I will look into it some more and report back with my findings.

        Edit: It would appear that when your primary bars are intraday bars you cannot add non-intraday bar objects (e.g. daily, weekly, etc). As a workaround you could load your primary bars as daily bars and then call your minute/tick/vol bars as secondary. When your primary bars are non-intraday you will also not have problems adding more non-intraday bars. I will contact the NinjaTrader development team to see if they know whats causing this.
        Last edited by NinjaTrader_JoshP; 08-26-2007, 12:24 AM.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          After talking to Dierk we have resolved the issue. The reason the strategy wouldn't print anything when you go from primary intraday bars and add secondary non-intraday bars is because of the two conditions that need to be satisfied first.
          1. OnBarUpdate() is called only when it can find a common timestamp between both series (e.g. you need enough data for both time intervals).
          2. Both time intervals need to have enough bars loaded to meet the "Min. bars required" parameter before Condition #1 can be met. When your primary bars are 1min bars the default lookback is only 7 days, but the default "Min. bars required" is 20. This means by default you would not be able to find a common timestamp to satisfy Condition #1 because the daily bars are 20 days in, but 1mins are only 7 days in.
          To fix this you could add this line of code to the Initialize() section
          Code:
          BarsRequired = 0;   //(any value up to 8 seems to work)
          Alternatively, you could set the "Min. bars required" parameter to less than or equal to 8 when you load the strategy (it is under the "General" category on the right-hand side of the Strategies window).
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            Josh,

            Thanks for your help, but I'm still having problems.

            Below is the code I'm using. I've added the BarsRequired = 0; statement. Unfortunately I'm still not seeing any print out. I'm using 1 minute bars as the primary bars.

            You suggest a second solution: "set the "Min. bars required" parameter to less than or equal to 8 when you load the strategy (it is under the "General" category on the right-hand side of the Strategies window)."

            I tried this as well and still no luck. By the "Strategies window" I assume you mean the backtest properties dialog? Are there any other important settings I should have to make this work?

            Code:
            [FONT=Courier New][SIZE=2][COLOR=#0000ff]protected[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]override[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] Initialize()[/SIZE][/FONT]
            [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
            [FONT=Courier New][SIZE=2]Add(PeriodType.Day, [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
            [SIZE=2][FONT=Courier New]BarsRequired = [/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
            [FONT=Courier New][SIZE=2]CalculateOnBarClose = [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
            [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
            [FONT=Courier New][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080]<summary>[/COLOR][/SIZE][/FONT]
            [FONT=Courier New][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000] Called on each bar update event (incoming tick)[/COLOR][/SIZE][/FONT]
            [FONT=Courier New][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080]</summary>[/COLOR][/SIZE][/FONT]
            [FONT=Courier New][SIZE=2][COLOR=#0000ff]protected[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]override[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] OnBarUpdate()[/SIZE][/FONT]
            [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
            [FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] (BarsInProgress == [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
            [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
            [SIZE=2][FONT=Courier New]Print([/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800000]"Primary Bars: "[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]+Time[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]]);[/SIZE][/FONT]
            [FONT=Courier New][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
            [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
            [FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] (BarsInProgress == [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
            [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
            [SIZE=2][FONT=Courier New]Print([/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800000]"Secondary Bars: "[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]+Time[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]]);[/SIZE][/FONT]
            [FONT=Courier New][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
            [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
            [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
            Last edited by jonesr227; 08-26-2007, 02:33 AM.

            Comment


              #7
              Are you connected to a provider that support historical daily data? If not, that will be your problem.

              Here is a matrix of connectivity providers and their varying levels of data support.

              RayNinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_Ray View Post
                Are you connected to a provider that support historical daily data? If not, that will be your problem.

                Here is a matrix of connectivity providers and their varying levels of data support.

                http://www.ninjatrader-support.com/H...ricalData.html
                I'm trying to do a historical backtest; as I mentioned above, I have imported 1 minute data going back to 1/1/07. Are you saying that despite the fact that I have imported sufficient data to do the backtest I still need to be connected to a live data provider?

                Comment


                  #9
                  Your strategy calls for daily bars this NinjaTrader needs access to historical daily data. Right now, it only has access to minute data.

                  You can either connect to any of our supported vendors that can provide Daily data or you can import daily data using the format specified in the link below.



                  In the meantime, you can backtest on any interval that uses minute based time intervals.
                  RayNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by sidlercom80, 10-28-2023, 08:49 AM
                  166 responses
                  2,233 views
                  0 likes
                  Last Post sidlercom80  
                  Started by thread, Yesterday, 11:58 PM
                  0 responses
                  1 view
                  0 likes
                  Last Post thread
                  by thread
                   
                  Started by jclose, Yesterday, 09:37 PM
                  0 responses
                  6 views
                  0 likes
                  Last Post jclose
                  by jclose
                   
                  Started by WeyldFalcon, 08-07-2020, 06:13 AM
                  10 responses
                  1,414 views
                  0 likes
                  Last Post Traderontheroad  
                  Started by firefoxforum12, Yesterday, 08:53 PM
                  0 responses
                  11 views
                  0 likes
                  Last Post firefoxforum12  
                  Working...
                  X