Announcement

Collapse
No announcement yet.

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 Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      571 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      330 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      549 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      549 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X