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

Newbie question

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

    Newbie question

    Hi,

    Just starting out with ninja C#. I have writen the following code,

    {
    if((High[0] < High[1]) && (High[1] > High[2]));

    DrawDot("high", true, 1, High[1], Color.Black);
    Print("Condition True");
    }


    and am getting the following error,


    Error on calling 'OnBarUpdate' method for indicator 'HighsTest' on bar 0: Object reference not set to an instance of an object.

    #2
    Originally posted by GKonheiser View Post
    Hi,

    Just starting out with ninja C#. I have writen the following code,

    {
    if((High[0] < High[1]) && (High[1] > High[2]));

    DrawDot("high", true, 1, High[1], Color.Black);
    Print("Condition True");
    }


    and am getting the following error,


    Error on calling 'OnBarUpdate' method for indicator 'HighsTest' on bar 0: Object reference not set to an instance of an object.
    You cannot call High[1] for the first bar, because the first bar has no bar that preceeds it. You can only run your code starting with the second bar.

    Code:
    {
         if(CurrentBar == 0)
              return;
         if(High[0] < High[1]) && (High[1] > High[2])
         {   
                DrawDot("high", true, 1, High[1], Color.Black);
                Print("Condition True");
         }
    }
    Further pay attention what you do with your brackets and semicolons. The line

    Code:
    if((High[0] < High[1]) && (High[1] > High[2]));
    is just an empty statement, which translates to "if the condition is true, do nothing".

    The code

    Code:
    {
              if((High[0] < High[1]) && (High[1] > High[2]))  // semicolon removed
            
                DrawDot("high", true, 1, High[1], Color.Black);
                Print("Condition True");
    }
    is incorrect, because you forgot to set the bracket to include the print line. Without the bracket the print line will be executed all the time, as it is not linked to the condition.

    Comment


      #3
      Thanks that's a big help. I'm trying to build an indicator form the ground up that effectively plots Highs and Lows and this is the first little step. ; )

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by junkone, Today, 11:37 AM
      0 responses
      1 view
      0 likes
      Last Post junkone
      by junkone
       
      Started by quantismo, 04-17-2024, 05:13 PM
      5 responses
      33 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by proptrade13, Today, 11:06 AM
      1 response
      5 views
      0 likes
      Last Post NinjaTrader_Clayton  
      Started by love2code2trade, 04-17-2024, 01:45 PM
      4 responses
      34 views
      0 likes
      Last Post love2code2trade  
      Started by cls71, Today, 04:45 AM
      2 responses
      10 views
      0 likes
      Last Post eDanny
      by eDanny
       
      Working...
      X