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

Historical data on secondary series lags behind primary Series.

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

    Historical data on secondary series lags behind primary Series.

    My strategy relies on 200 days of historical data on 5 min series to log all major swing high/lows. This works great and I've logged all major and minor swings in arrays, which I update once per hour in OnBarUpdate(). The problem arises when I try to add a secondary series on 1 minute. I need the 1 minute ( or smaller) series so that I can check move velocity coming into my grid of trade evaluation points. When I add the secondary series, I have to ensure that the CurrentBar[0] (5min) and CurrentBar[1] values meet the needs of my look back calculations.and array logging. I have put in the check as below, where RangeBars is 10000 (for example):

    if (CurrentBars[0] < RangeBars || CurrentBars[1] < RangeBars*5 )
    return;

    The strategy can be enabled and all seems fine, but the strategy will not execute any trades. The reason is that the CurrentBars[1] is lagging far behiind the CurrentBars[0] count. When I debug I'll see that my CurrentBars[0] is correctly above 10,000 because the script has gone through the chart historical data which is set to load 200 days. Unfortunately the CurrentBars[1] is a much lower count and no where near satisfying my check above. This means that the script will not execute my trade logic and would need to wait until the 50,000 count is reached at some later point to start executing trade logic.

    How do I get the secondary series historical data to sync up like primary series? I have tries adding both series to the chart which I initiate strategy, but no luck. The strategy would take many days of running before the CurrentBars[1] count is reached.

    #2
    Hello CyberNate,

    Thank you for your note.

    It's hard to say what may be occurring without seeing your code. Theoretically, a secondary 1 minute series would have a much higher CurrentBars count than a primary series of 5 minute bars, so I'd really have to look at what you're doing in your code. If you are comfortable sharing at least a reduced version of your strategy here, please do so. If not, please email platformsupport[at]ninjatrader[dot]com and attach your strategy. Please put "2269832 ATTN. Kate W." in the subject line and a link to this thread in the body.

    In the meantime, I would also encourage you to turn on the TraceOrders function:



    Do you see the strategy ignoring or cancelling any attempted trades?

    Thanks in advance; I look forward to assisting you further.

    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Kate View Post
      Hello CyberNate,

      Thank you for your note.

      It's hard to say what may be occurring without seeing your code. Theoretically, a secondary 1 minute series would have a much higher CurrentBars count than a primary series of 5 minute bars, so I'd really have to look at what you're doing in your code. If you are comfortable sharing at least a reduced version of your strategy here, please do so. If not, please email platformsupport[at]ninjatrader[dot]com and attach your strategy. Please put "2269832 ATTN. Kate W." in the subject line and a link to this thread in the body.

      In the meantime, I would also encourage you to turn on the TraceOrders function:



      Do you see the strategy ignoring or cancelling any attempted trades?

      Thanks in advance; I look forward to assisting you further.
      Hello Kate,

      The rest of the code is irrelevant because it never gets past the Return in the CurrentBar check. If I relax the current bar check, the code will fail because I am going back up to 10,000 bars to retrieve major and minor swings from the ninja Swing indicator and putting those swing points into SwingHigh and SwingLow arrays. The 1 minute series count is at a far lower count. I can show you in a debugging screenshot. I don't need order tracing as I debug line by line directly in Visual Studio.

      Comment


        #4
        Hello CyberNate,

        Thank you for your reply.

        It's much easier for us to test on our end to see what may be occurring, which is why I ask for an example of your code. If you're uncomfortable posting it or emailing it in, that is fine; we just may take longer to assess what may be happening.

        Where is the value of RangeBars coming from? Do you have a third data series of Range bars?

        If you add this line prior to your CurrentBars check, can you give an example of the output?

        Print(string.Format("CurrentBars[0]: {0} > RangeBars: {1} || CurrentBars[1]: {2} > (RangeBars*5): {3}", CurrentBars[0], RangeBars, CurrentBars[1], RangeBars*5));

        Thanks in advance; I look forward to assisting you further.



        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Kate View Post
          Hello CyberNate,

          Thank you for your reply.

          It's much easier for us to test on our end to see what may be occurring, which is why I ask for an example of your code. If you're uncomfortable posting it or emailing it in, that is fine; we just may take longer to assess what may be happening.

          Where is the value of RangeBars coming from? Do you have a third data series of Range bars?

          If you add this line prior to your CurrentBars check, can you give an example of the output?

          Print(string.Format("CurrentBars[0]: {0} > RangeBars: {1} || CurrentBars[1]: {2} > (RangeBars*5): {3}", CurrentBars[0], RangeBars, CurrentBars[1], RangeBars*5));

          Thanks in advance; I look forward to assisting you further.


          Kate,

          Thanks a lot for your help. I added the code and here's the output below.

          This is in Market Replay:

          CurrentBars[0]: 39494 > RangeBars: 10000 || CurrentBars[1]: 6546 > (RangeBars*5): 50000
          CurrentBars[0]: 39494 > RangeBars: 10000 || CurrentBars[1]: 6546 > (RangeBars*5): 50000
          CurrentBars[0]: 39494 > RangeBars: 10000 || CurrentBars[1]: 6546 > (RangeBars*5): 50000
          CurrentBars[0]: 39494 > RangeBars: 10000 || CurrentBars[1]: 6546 > (RangeBars*5): 50000
          CurrentBars[0]: 39494 > RangeBars: 10000 || CurrentBars[1]: 6546 > (RangeBars*5): 50000
          CurrentBars[0]: 39494 > RangeBars: 10000 || CurrentBars[1]: 6546 > (RangeBars*5): 50000
          CurrentBars[0]: 39494 > RangeBars: 10000 || CurrentBars[1]: 6546 > (RangeBars*5): 50000
          CurrentBars[0]: 39494 > RangeBars: 10000 || CurrentBars[1]: 6546 > (RangeBars*5): 50000
          CurrentBars[0]: 39494 > RangeBars: 10000 || CurrentBars[1]: 6546 > (RangeBars*5): 50000
          CurrentBars[0]: 39494 > RangeBars: 10000 || CurrentBars[1]: 6546 > (RangeBars*5): 50000
          CurrentBars[0]: 39494 > RangeBars: 10000 || CurrentBars[1]: 6546 > (RangeBars*5): 50000
          CurrentBars[0]: 39494 > RangeBars: 10000 || CurrentBars[1]: 6546 > (RangeBars*5): 50000
          CurrentBars[0]: 39494 > RangeBars: 10000 || CurrentBars[1]: 6546 > (RangeBars*5): 50000
          CurrentBars[0]: 39494 > RangeBars: 10000 || CurrentBars[1]: 6546 > (RangeBars*5): 50000
          CurrentBars[0]: 39494 > RangeBars: 10000 || CurrentBars[1]: 6546 > (RangeBars*5): 50000

          I think the issue is really only with Market Replay. If I enable with live market, then the data looks fine:

          CurrentBars[0]: 38865 > RangeBars: 10000 || CurrentBars[1]: 194161 > (RangeBars*5): 50000
          CurrentBars[0]: 38865 > RangeBars: 10000 || CurrentBars[1]: 194161 > (RangeBars*5): 50000
          CurrentBars[0]: 38865 > RangeBars: 10000 || CurrentBars[1]: 194161 > (RangeBars*5): 50000
          CurrentBars[0]: 38865 > RangeBars: 10000 || CurrentBars[1]: 194161 > (RangeBars*5): 50000
          CurrentBars[0]: 38865 > RangeBars: 10000 || CurrentBars[1]: 194161 > (RangeBars*5): 50000
          CurrentBars[0]: 38865 > RangeBars: 10000 || CurrentBars[1]: 194161 > (RangeBars*5): 50000
          CurrentBars[0]: 38865 > RangeBars: 10000 || CurrentBars[1]: 194161 > (RangeBars*5): 50000
          CurrentBars[0]: 38865 > RangeBars: 10000 || CurrentBars[1]: 194161 > (RangeBars*5): 50000
          CurrentBars[0]: 38865 > RangeBars: 10000 || CurrentBars[1]: 194161 > (RangeBars*5): 50000

          So now, the question becomes, how do I make Market Replay work correctly? I've found that the only reliable way to test is with Market Data Replay. All other historical data tests are invalid. I could use SIM trading, but I want to test on many different time frames.


          Last edited by CyberNate; 09-09-2019, 01:30 PM.

          Comment


            #6
            As mentioned in email, I see that the issue is specific to "PlayBack Connection" for Market Replay. In the strategy settings I have "infinite" lookback and 10,000 set for Bars Required to Trade. It is with these settings that the second data series does not have sufficient historical data.

            Comment


              #7
              I think I've figured it out. On the second data series you have to explicitly specify how many bars to load in the AddDataSeries with barsToLoad parameter:
              AddDataSeries(string instrumentName, BarsPeriod barsPeriod, int barsToLoad, string tradingHoursName, bool? isResetOnNewTradingDay)

              Comment


                #8
                I cannot believe there is no easy way to automate the setting of AddDataSeries() parameters! I wanted this to be universally used for any instrument, but according to what I've read you must set ALL of the parameters in order to use the barsToLoad like this:

                AddDataSeries("CL 10-19", new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1 }, BarsRequiredToTrade, "CME US Index Futures ETH", null);

                What a pain! I just want the barsToLoad parameter set as I've done with variable BarsRequiredToTrade.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by RookieTrader, Today, 09:37 AM
                3 responses
                15 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by kulwinder73, Today, 10:31 AM
                0 responses
                5 views
                0 likes
                Last Post kulwinder73  
                Started by terofs, Yesterday, 04:18 PM
                1 response
                23 views
                0 likes
                Last Post terofs
                by terofs
                 
                Started by CommonWhale, Today, 09:55 AM
                1 response
                4 views
                0 likes
                Last Post NinjaTrader_Erick  
                Started by Gerik, Today, 09:40 AM
                2 responses
                7 views
                0 likes
                Last Post Gerik
                by Gerik
                 
                Working...
                X