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 Hwop38, 05-04-2026, 07:02 PM
      0 responses
      161 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Started by CaptainJack, 04-24-2026, 11:07 PM
      0 responses
      310 views
      0 likes
      Last Post CaptainJack  
      Started by Mindset, 04-21-2026, 06:46 AM
      0 responses
      245 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      350 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      179 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Working...
      X