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

Multiple instrument out of range

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

    Multiple instrument out of range

    Suppose I make an indicator where I simply plot the close of a second instrument as an indicator. This is of course easy to do with:

    Add( <instrument>, PeriodType.Day, 1 );

    and

    protected override void OnBarUpdate()
    {
    plot0.Set(Closes[1][0]);
    }

    This works fine until I select a range on my chart where the primary instrument doesn't have any data. For example, if I have data for MSFT from 1/1/1990 and IBM from 1/1/1980. I use MSFT as my primary instrument and I plot IBM as an indicator using the method above. As long as I don't choose an earlier startdate than 1/1/1990 for my chart there is no problem. However if I choose for example 1/1/1989 as startdate I get an error message: "You are accessing an index with a value that is invalid since its out of range".

    If I have only the primary instrument on my chart without the indicator then there is no problem. Even if I select the chart to start on 1/1/1989, it will simply start from 1/1/1990 because it has no earlier data. However when using the indicator based on a second instrument it gives an error. It apparently gets an invalid index.

    How can I prevent this from happening in my code? I want to make it robust, so maybe I need to somehow check if the primary series exists before doing plot0.Set(Closes[1][0])? How can I do that?

    #2
    FireFly, please try including a CurrentBars check for all involved series - for example :

    if (CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired)
    return;
    BertrandNinjaTrader Customer Service

    Comment


      #3
      @NinjaTrader_Bertrand: that doesn't solve the problem.

      BUT it seems I have already solved the problem by simply using

      if (BarsInProgress == 0)
      {

      }

      How stupid that I didn't think about that earlier!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by lorem, Today, 09:18 AM
      1 response
      4 views
      0 likes
      Last Post lorem
      by lorem
       
      Started by bmartz, Today, 09:30 AM
      0 responses
      2 views
      0 likes
      Last Post bmartz
      by bmartz
       
      Started by GussJ, 03-04-2020, 03:11 PM
      14 responses
      3,244 views
      0 likes
      Last Post GussJ
      by GussJ
       
      Started by ArkansasClint, Today, 09:28 AM
      0 responses
      0 views
      0 likes
      Last Post ArkansasClint  
      Started by hazylizard, Today, 08:38 AM
      4 responses
      12 views
      0 likes
      Last Post hazylizard  
      Working...
      X