Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multiple Timeframe Question

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

    Multiple Timeframe Question

    First let me say, as a newbie to NT I am thoroughly enjoying this software! The capabilities are quite tremendous.

    I have been using the wizard for generating some strategy ideas. I know I can't use multiple time frames with only the wizard. I now need to go further and was curious, if I wanted to use the same strategy, but different time lengths, is there an example I can see how the code is written?

    Ex. If close>MA (30 min) AND close>ma (5min) only then go long - Can I cut and paste the 5 min code within the 30 min code with the provision that 5 min qualifier also be true, then go long? Is there an example or a reference page to see how the actual wording and NT language is used?

    I'm not a coder, so even though I know how to structure the logic, the language and punctuation is a stumbling block.

    Thanks!

    #2
    Hello Canuck,

    Thank you for the kind words about NinjaTrader.

    The time frame that the strategy is run against is selected when you run the strategy, not when you create it. You can use the same strategy on 30 minute or 5 minute bars. See more info here on running a strategy.

    When you need to combine time frames is when you work with code. There is a sample available by clicking tools > edit NinjaScript > Strategy. Documentation for multiseries is also available here:
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      I've been trying to figure this out, after reading the info provided. I keep getting a lot of errors popping up. Is my synthax wrong?

      Here is an example: I want to add 5 and 10 minute bars:

      Add(PeriodType.Minute, 5);
      Add(PeriodType.Minute, 10);

      Let's say I want to the 10 minute SMA close current bar ago to be greater than 10 minute bar 1 period ago, is this not the correct synthax?

      SMA(BarsArray[2],14[0]) > SMA(BarsArray[2],14[1]))

      I assumed barsarray[2] denotes the second period, 10 min, added on my top description? I get the error "cannot apply indexing with [] to an expression of type 'int'"

      Thanks

      Comment


        #4
        The issue is the index brackets next to the period parameter. The following line should compile for you:

        if (SMA(BarsArray[2],14)[0] > SMA(BarsArray[2],14)[0])
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Ah I see, thanks for your help Ryan!

          Comment


            #6
            Am I on the right track? If you could take a look at the following simple portion and let me know why this doesn't work.

            All I'm asking it to do, look at the 30 min CCI, if that's above 0 then look at the 15 min CCI, if that's above 0 go long.


            protected override void Initialize()
            {


            Add(PeriodType.Minute, 30);
            Add(PeriodType.Minute, 15);

            CalculateOnBarClose = true;
            }

            protected override void OnBarUpdate()
            {
            if (BarsInProgress == 1)

            {
            // Condition set 1
            if (CCI(BarsArray[1],14)[0]) > 0

            //Condition set 1a
            if (CCI(BarsArray[2],14)[0])>0;

            {
            EnterLong(DefaultQuantity, "");
            }
            }
            }

            Comment


              #7
              Hello Canuck,

              What series is the strategy applied to? If you want to work with two series total, you can simplify this. You could use 30 minutes for the series that it's applied to, and 15 minute as your secondary.
              Last edited by NinjaTrader_RyanM1; 12-10-2010, 09:45 AM.
              Ryan M.NinjaTrader Customer Service

              Comment


                #8
                So if I removed the barsinprogress, it would look at 30 min on a rolling basis?

                >"Also, what series is the strategy applied to? ... You could use 30 minutes for the series >that it's applied to, and 15 minute as your secondary"

                I was under the impression that's what the code was doing? Looking at the 30 min section, then looking at each 15 min portion of the original 30 min?

                Comment


                  #9
                  if (BIP == 1), means that you are only looking at the values during updates to this series. You're looking at values on your 15 minute bars for each 30 minute bar. It's useful to print timestamps for your series so you can see how they're aligned.

                  if (BarsInProgress == 1)
                  {
                  Print("Primary Series " + Time[0] + "SecondarySeries " + Times[1][0]);
                  }

                  I was under the impression that's what the code was doing? Looking at the 30 min section, then looking at each 15 min portion of the original 30 min?
                  Yes, your code is doing exactly this. However, there is an additional series - the series the strategy is applied to. Since it's not working the way you expect, you should simplify.

                  If you're only comparing two series:
                  Primary series - The series the strategy is applied to. You could use 30 minute for this.
                  Secondary series - 15 minute series you add in Initialize()
                  Last edited by NinjaTrader_RyanM1; 12-08-2010, 10:06 AM.
                  Ryan M.NinjaTrader Customer Service

                  Comment


                    #10
                    I see what you mean, that makes sense.

                    Thanks!

                    Comment


                      #11
                      Thanks so far for your help as I've got the code able to compile. My new issue is that adding the barsarray filter for the shorter time period now will cause the model to execute whenever that filter is triggered, even though the longer term filter is not triggered. I think I'm missing something in the logic.

                      Is the following sequence correct?

                      Primary series 30 min, secondary 15min.

                      if (filters for primary series)
                      && something
                      && (now I want the short term filter) (Filter(barsarray[1]>something)
                      {
                      Enterlong
                      }

                      Taking out the short term filter it works properly. Adding that line in and it executes whenever the short term filter hits.

                      Between the longer term and shorter period filters, do I need to add if (barsinprogress==1)? I tried that, but I get a lot of errors. I was under the impression that anytime you call up barsarray(period) you then are able to use what's stored in that data?

                      Thanks
                      Last edited by canuck; 12-10-2010, 09:13 AM.

                      Comment


                        #12
                        I wonder if this has something to do with the calculate on bar true? From the help file, if I set it to true, it will look at the 30 min bar, then I want the short time period to look at the next 2 15 min bars, which is what Figure 1 of the help file suggests. Yet this doesn't seem to be the case when I run the model. Am I missing some sort of 'reset' button to get the model to start counting forward bars and waiting until the short term indicators are triggered?

                        Thanks

                        Comment


                          #13
                          I looked again at code from your previous post. Changing it to work with only two series is good, and then adding the bip check for the primary series should get you back on track. It will also help to use that print statement from earlier to see how the times are aligned for the values you're trying to access. I apologize for any confusion.

                          if (BarsInProgress == 0)
                          {
                          Print("Primary Series " + Time[0] + "SecondarySeries " + Times[1][0]);

                          if (CCI(BarsArray[0],14)[0] > 0 && CCI(BarsArray[1],14)[0]>0)
                          EnterLong();
                          }
                          Ryan M.NinjaTrader Customer Service

                          Comment


                            #14
                            Ah I think I see what's the problem, the shorter period doesn't move forward 2 periods. When I look at an execution, for example, of 2pm trade execution the printout is as follows:

                            PrimarySeries 2:00pm SecondarySeries 1:45
                            PrimarySeries 2:00pm SecondarySeries 1:45

                            I would like the the model to have the following calculation

                            PrimarySeries 2:00pm SecondarySeries 2:00
                            PrimarySeries 2:00pm SecondarySeries 2:15

                            Would I then rewrite the code and have time(0) for the furthest period (2:15) then time(1) for 2pm? Essentially just doubling my code to include both periods?

                            Thanks again, I really appreciate it.

                            Comment


                              #15
                              Canuck - Are you working from 6.5 or 7 on this?
                              Ryan M.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              649 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              370 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              109 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              574 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              576 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X