Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Issue with my if statement

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

    Issue with my if statement

    Hello

    I'm trying to do a few calculations based on the condition that there has been a change in price. I did it doing the following way:

    Code:
    if(Close[0] !=(Close[1]){... etc
    To test this, I inserted a print statement within the IF statement and got the following output:
    Line 1: Close[0]: 1665.25 Close[1]: 1665.5
    Line 2: Close[0]: 1665.25 Close[1]: 1665.5
    Line 3: Close[0]: 1665.25 Close[1]: 1665.5
    Line 4: Close[0]: 1665.25 Close[1]: 1665.5
    Line 5: Close[0]: 1665.25 Close[1]: 1665.5
    Line 6: Close[0]: 1665.25 Close[1]: 1665.5
    On the next "OnBarUpdate" shouldn't the value on Close[1] on Line 2 equal "1665.25" etc. Have I misunderstood how DataSeries work?

    I'm trying to avoid doing the calculation on the same Close value twice in a row. Any idea on how I can achieve my goal?

    Thanks

    #2
    Originally posted by daaim0 View Post
    Hello

    I'm trying to do a few calculations based on the condition that there has been a change in price. I did it doing the following way:

    Code:
    if(Close[0] !=(Close[1]){... etc
    To test this, I inserted a print statement within the IF statement and got the following output:


    On the next "OnBarUpdate" shouldn't the value on Close[1] on Line 2 equal "1665.25" etc. Have I misunderstood how DataSeries work?

    I'm trying to avoid doing the calculation on the same Close value twice in a row. Any idea on how I can achieve my goal?

    Thanks
    Looks like you have COBC = false. Is that correct?

    Comment


      #3
      Yes I do. I assume my output is justified then?

      Comment


        #4
        Hello daaim0,

        Welcome to the NinjaTrader Support Forums!

        Yes, that would be expected since with COBC set to false each incoming tick of data will cause OnBarUpdate() to be triggered. Once, the bar closes you will see the values change, otherwise while ticks of data are coming in the previous days Close will not change. You may want to print out the "CurrentBar" so that you can see when a new bar is formed for the values to change.

        JCNinjaTrader Customer Service

        Comment


          #5
          Thanks very much

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          656 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          371 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          109 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          574 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          579 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X