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

Out of range error

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

    Out of range error

    I have two if statements, one detects a cross above a level of an indicator the other detects a cross below a level of the indicator. There is nothing fancy about the code just two simple if statements. The first "IF" functions fine, however when I add in the second "IF" statement now I get an "Out of range error"

    The first IF STATEMENT :
    if (Default[0] > 70 && Default[1] <= 70)
    {
    startBarsAgo = CurrentBar;
    Draw.VerticalLine(this, @"xAbove70" + Bars.Count.ToString(),
    0, Brushes.HotPink, DashStyleHelper.Dot, 2);
    Print(string.Format("Start bar : {0}", startBarsAgo.ToString()));
    }

    The second IF STATEMENT :
    if (Default[0] < 70 && Default[1] >= 70)
    {
    endBarsAgo = CurrentBar;
    Draw.VerticalLine(this, @"xBelow70" + Bars.Count.ToString(),
    0, Brushes.Cyan, DashStyleHelper.Dash, 2);
    Print(string.Format("End bar : {0}", endBarsAgo.ToString()));
    }

    #2
    So in trouble shooting I tried putting a try/catch block around the second "IF" statement and it works, however I could still use some insight into what is going on, what I'm missing. Also, no exception is being thrown and output to the console.

    Comment


      #3
      My guess is you're accessing Default value 1 bar ago at CurrentBar = 0. It works in the first if statement because Default[0] > 70 is false so it doesn't check Default[1] <= 70 because it's the way && operator works.

      So place this at start of your code:
      if(CurrentBar <1) return;

      Comment


        #4
        Thanks Leeroy, that worked out.

        Comment


          #5
          Hello Itachi,

          Below is a link to a forum post on indexing errors.
          Hello, I want to create an indicator that show data in a chart but calculate in other charttime different to the time of the chart where is showed. For example:


          Leeroy_Jenkins, thank you for providing this guidance.
          Chelsea B.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by rhyminkevin, Today, 04:58 PM
          4 responses
          52 views
          0 likes
          Last Post dp8282
          by dp8282
           
          Started by iceman2018, Today, 05:07 PM
          0 responses
          5 views
          0 likes
          Last Post iceman2018  
          Started by lightsun47, Today, 03:51 PM
          0 responses
          7 views
          0 likes
          Last Post lightsun47  
          Started by 00nevest, Today, 02:27 PM
          1 response
          14 views
          0 likes
          Last Post 00nevest  
          Started by futtrader, 04-21-2024, 01:50 AM
          4 responses
          50 views
          0 likes
          Last Post futtrader  
          Working...
          X