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

Simple if statement not working in NinjaScript 8

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

    Simple if statement not working in NinjaScript 8

    Hi there,

    I'm trying to put a dot in the chart when a condition is met. For some reason the if statement is not working properly. I'm using NinjaTrader 8.

    In the protected override void OnBarUpdate() function, the following works if it's the only statement:
    Draw.Dot(this, "Bull" + CurrentBar, true, 0, Low[0] - 5, Brushes.Blue); // draw a dot under every price bar

    But if I try to compare the current to the previous bar like this, it's not working:
    if (Low[0] >= Low[1]) // draw a dot whenever the current low is above the previous low
    {
    Draw.Dot(this, "Bull" + CurrentBar, true, 0, Low[0] - 5, Brushes.Blue);
    }

    Any idea what's wrong here? Thanks in advance

    #2
    Hello ieee1294,

    Thanks for your post and welcome to the NinjaTrader forums!

    If your script is not working as expected, always check the "log" tab of the control center for any run time type error messages. If your script is not checking for the CurrentBar to be more than 1 then it is possible that your script would error on bar index error. Reference: https://ninjatrader.com/support/help...currentbar.htm
    So you might want to use:

    if (Currentbar < 1) return; // ensure there are two bars before going further

    If you want your draw statement to work on other instruments I would suggest changing Low[0] - 5 to Low[0] - 5 * TickSize TickSize is an instrument property that represents the smallest movement by that instrument, so in the example the dot would always be 5 ticks below the Low regardless of the applied instrument. Reference: https://ninjatrader.com/support/help.../?ticksize.htm
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Paul, thanks for the extremely prompt reply - did not expect that on a New Year's Eve!

      Didn't know about the log tab until now, and thanks - it's like you said, I didn't check for CurrentBar. That fixed my issue. Thanks for the TickSize tip, I'm also using it already, just showing simplified code to get the point across easily.

      Hope you have a happy new year! Cheers.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by rayyyu12, Today, 05:38 PM
      0 responses
      12 views
      0 likes
      Last Post rayyyu12  
      Started by xepher101, Yesterday, 12:19 PM
      2 responses
      29 views
      0 likes
      Last Post xepher101  
      Started by thumper57, Today, 04:30 PM
      0 responses
      8 views
      0 likes
      Last Post thumper57  
      Started by OllieFeraher, 05-09-2024, 11:14 AM
      5 responses
      16 views
      0 likes
      Last Post MisterTee  
      Started by jackiegils, Yesterday, 11:05 PM
      1 response
      11 views
      0 likes
      Last Post marcus2300  
      Working...
      X