Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Booleans in If Statements

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

    Booleans in If Statements

    I have coded the following in a multi-time frame strategy for entry condition--which it completely ignores and enters into a position anyway. I was under the assumption the default value is true?

    if( (DAILY.RANGE > 2 || DAILY.A > 85 || DAILY.A < -85) )
    {
    do something;
    }

    However when I do the following, it works perfectly.

    if( (DAILY.RANGE > 2 || DAILY.A > 85 || DAILY.A < -85) == true)
    {
    do something;
    }

    I don't understand why. I did some research and according to what I Google'd the default value is a boolean is false; however, the following code seem to default to true?

    if(enteredpos) //enteredpos is a boolean variable with initial value set to false
    {
    do something
    }

    if(FirstTickofBar)
    {
    }

    if((ToTime(Time[0]) == 220000))
    {
    }

    Does it mean for boolean variables the default is false but for conditions within if statements you have to specify true or false condition?

    #2
    Hello shipolito,

    Thanks for your post.

    What I recommend would be to add print statements just before your "if" statement so that you can have a record of the state of each condition.

    You mention this is an MTF strategy and that orders are being place when not expected, you may need to review your code to ensure that it is running correctly as each added bars object will call the OnbarUpdate() method and when that happens the references may then point to other objects. Please see the helpguide here for additional information: http://ninjatrader.com/support/helpG...nstruments.htm

    Booleans can be initialized to any state, true or false, according to the needs of your logic.

    FirstTickOfBar is a system bool that is intended for use when CalculateOnbarClose = false as it then provides a reference point that is true on 1st tick of the bar that may contain 1000's of ticks. In the case of CalculateOnBarClose = true, there is only one tick.

    In an MTF code please note that references change and different code must be used to accomodate. In the specific case of Time, you would use Times: http://ninjatrader.com/support/helpG...nt7/?times.htm

    Comment


      #3
      It turns out the fault is not the code but in the uberly expensive Market Replay data that I purchased. There was nearly a month of missing data and when the data started to flow again that resulted in erroneous output. Enabling the strategy post data gap resolved everything.

      I wish there were more vendors of Market Replay data.

      Comment


        #4
        What product did you buy?

        Comment


          #5
          Someone posted a bad review about the company and their data on a website formerly known as BMT and lawyers were involved! At least that was the threat and they also had the customer's NT license terminated.

          Of course anyone can post a fake customer service reply message but I too almost got involved in litigation after a small understanding that could have been easily resolved if they didn't shoot first and ask questions later--they are very aggressive and have bad customer service in terms of not having manners/jumping to conclusions.

          They also don't want to correct misspellings on their website that I pointed out, ha! I guess if you're the top data provider you'll treat anyone the way you like.

          Anyway, all that just to say PM me if you want to know where I got it from. I don't feel like dealing with them in any shape or form--so nasty!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          558 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          324 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
          545 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          547 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X