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