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

Issues around adding multiple time frames

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

    Issues around adding multiple time frames

    Hi All,

    I've been working on a fairly complex strategy involving two time frames (5min and 60min). When I back test it I get a certain result. Then I go and add another time frame to the strategy (240min). I do nothing other than add the 3rd time frame in the initialise method ie: I dont use it anywhere in the strategy. I then run the exact same back test and get a different result.

    I thought maybe it was something to do with the rest of my code and the complexity of the strategy. So I created a new very simple moving average crossover strategy to test this issue, and the same thing happens. I have pasted the code below:


    protected overridevoid Initialize()
    {
    //Add(PeriodType.Minute, 240);
    this.BarsRequired = 48;
    CalculateOnBarClose =
    true;
    }

    protected overridevoid OnBarUpdate()
    {
    if (CrossAbove(SMA(5), SMA(20), 1)
    EnterLong(
    1);


    if (CrossBelow(SMA(5), SMA(20), 1)
    EnterShort(
    1);
    }
    If I run the above code I get a certain result. If I then uncomment the line to add the 240minute time frame and run it again, I get a different result. I have even specified that 48 * 5min bars are required (which equals a 240min bar)

    What is going on? Is this correct behaviour? It is causing Massive result differences in my real strategy.
    thanks.

    #2
    Hi DarkPool,

    You'll want to work with BarsInProgress to filter updates to a specific series. OnBarUpdate will be called for every series, so simply adding a series can definitely change your results.

    If you wanted to prevent processing on all but the primary series, you can add this line to the top of OnBarUpdate()

    if (BarsInProgress != 0) return;
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the reply, but I just added that line to the above code I posted and the same issue occurs. Are you sure that is the correct code?

      Comment


        #4
        I don't think he meant for you to paste that line exactly, that was just to demonstrate how you would use BarsInProgress. In your case, if you don't want to calculate on the 3rd data series, I think it would be:

        if (BarsInProgress == 2) return;

        Comment


          #5
          Sorry, what is the current issue you're having?

          Working with BarsInProgress is critical in multiseries scripts and would be needed anytime you add a series to your strategy. There are examples linked here in the help guide that can help flesh out the concept a little better.


          Adding another series can also change your results because the minimum bars required must be satisfied for all series in the script. This can lead to different starting points and sequences.
          Last edited by NinjaTrader_RyanM1; 06-04-2012, 12:58 PM.
          Ryan M.NinjaTrader Customer Service

          Comment


            #6
            Oh I see now. I wasn't understanding the BarsInProgress properly. It's working now. Thanks to both of you.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by josh18955, 03-25-2023, 11:16 AM
            6 responses
            436 views
            0 likes
            Last Post Delerium  
            Started by FAQtrader, Today, 03:35 PM
            0 responses
            5 views
            0 likes
            Last Post FAQtrader  
            Started by rocketman7, Today, 09:41 AM
            5 responses
            18 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by frslvr, 04-11-2024, 07:26 AM
            9 responses
            127 views
            1 like
            Last Post caryc123  
            Started by selu72, Today, 02:01 PM
            1 response
            14 views
            0 likes
            Last Post NinjaTrader_Zachary  
            Working...
            X