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

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
    Paul H.NinjaTrader Customer Service

    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 chbruno, Today, 04:10 PM
          0 responses
          3 views
          0 likes
          Last Post chbruno
          by chbruno
           
          Started by josh18955, 03-25-2023, 11:16 AM
          6 responses
          436 views
          0 likes
          Last Post Delerium  
          Started by FAQtrader, Today, 03:35 PM
          0 responses
          6 views
          0 likes
          Last Post FAQtrader  
          Started by rocketman7, Today, 09:41 AM
          5 responses
          19 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by frslvr, 04-11-2024, 07:26 AM
          9 responses
          127 views
          1 like
          Last Post caryc123  
          Working...
          X