Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem Adding Instruments from IB

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

    Problem Adding Instruments from IB

    Hi,
    I have a strategy that worked nicely in 6.5 but is broken in 7.0.0.19, so I've been trying to debug. The strategy uses multiple instruments in the Initialize method and I put a simple print statement in to check if the historical data is loaded correctly. Here's a portion of the code:
    Code:
            protected override void Initialize()
            {
    
                Add("ES 12-10", PeriodType.Day, 1);
                Add("YM 12-10", PeriodType.Day, 1);    
                
                SpreadCloses = new DataSeries(this);    // synch dataseries    
                
    
                CalculateOnBarClose = true;        
                ExitOnClose = false;
                EntryHandling = EntryHandling.UniqueEntries; 
                Add ("YM 12-10", PeriodType.Minute, 1);
                                                         
                Print ("Init Done");
            }
    
            protected override void OnStartUp() 
    {
                       
     for (int x = 0; x <stDevPeriod ; x++)        
                {
                    
                    Print (" x= "+ x + "   NQ = " +Closes[0][x]+ "    ES = " + Closes[1][x]+ "   YM = "+ Closes[2][x]);
                }
    }
    This code outputs the following:
    PHP Code:
    Init Done
    **NT** Enabling NinjaScript strategy 'DEBUGStrategy/634e07b0cef04464aa7f01419f1deb14' On starting a real-time strategy StrategySync=SubmitImmediately SyncAccountPosition=False EntryHandling=UniqueEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositions ExitOnClose=False Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True MaxRestarts=4 in 5 minutes
     x
    0   NQ 1873    ES 1096.25   YM 10316
    **NT** Error on calling 'OnStartUp' method for strategy 'DEBUGStrategy/634e07b0cef04464aa7f01419f1deb14'You are accessing an index with a value that is invalid since its out of rangeI.Eaccessing a series [barsAgowith a value of 5 when there are only 4 bars on the chart
    I've attached the strategy window also. I can't figure out why I'm getting the error, I assume the daily values are not loading properly, but if I use the Historical Data Manager, I can see the data is in the database, but the strategy doesn't seem to have any data in the [1] bars.
    Attached Files

    #2
    GiantHogweed, can you please retry with a CurrentBars check for each series used?

    Code:
     
    if (CurrenrBars[0] < 0 || CurrentBars[1] < 0 ....) return;
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Hi Bertrand,

      I have now changed my code to this:
      Code:
              protected override void Initialize()
              {
      
                  Add("ES 12-10", PeriodType.Day, 1);
                  Add("YM 12-10", PeriodType.Day, 1);    
                  
                  SpreadCloses = new DataSeries(this);    // synch dataseries    
                  
      
                  CalculateOnBarClose = true;        
                  ExitOnClose = false;
                  EntryHandling = EntryHandling.UniqueEntries; 
                  Add ("YM 12-10", PeriodType.Minute, 1);
                                                           
                  Print ("Init Done");
              }
      
              protected override void OnStartUp() 
      {
              Print ("Bar Index 0 = " + CurrentBars[0]);
              Print ("Bar Index 1 = " + CurrentBars[1]);
              Print ("Bar Index 2 = " + CurrentBars[2]);
              Print ("Bar Index 3 = " + CurrentBars[3]);
          return;
      }
      and this is my output:
      PHP Code:
      **NT** Enabling NinjaScript strategy 'DEBUGStrategy/5c92062baaf24f55b5247939138a6df3' On starting a real-time strategy StrategySync=SubmitImmediately SyncAccountPosition=False EntryHandling=UniqueEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositions ExitOnClose=False Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True MaxRestarts=4 in 5 minutes
      Bar Index 0 
      0
      Bar Index 1 
      0
      Bar Index 2 
      0
      Bar Index 3 

      I cannot understand why I am not loading in historical daily data into each bar index....

      Comment


        #4
        Hmm, would you see the same with using DoNotMerge as merge policy option for the ES master symbol?

        The 12-10 is not the current front month at this point in time yet.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          I set the policy option to "Do Not Merge" for ES 12-10. The output did not change, CurrentBars = 0 for all four series.

          Comment


            #6
            I ran your sample here and moved the bars printing bars to OnBarUpdate() and it works ok. You are on first bar (CurrentBar 0) for all series at the OnStartUp() call point.
            BertrandNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by kevinenergy, 02-17-2023, 12:42 PM
            117 responses
            2,766 views
            1 like
            Last Post jculp
            by jculp
             
            Started by Mongo, Today, 11:05 AM
            5 responses
            15 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by SightCareAubetter, Today, 12:55 PM
            0 responses
            3 views
            0 likes
            Last Post SightCareAubetter  
            Started by traderqz, Today, 12:06 AM
            8 responses
            16 views
            0 likes
            Last Post traderqz  
            Started by SightCareAubetter, Today, 12:50 PM
            0 responses
            2 views
            0 likes
            Last Post SightCareAubetter  
            Working...
            X