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

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 Shansen, 08-30-2019, 10:18 PM
          24 responses
          938 views
          0 likes
          Last Post spwizard  
          Started by Max238, Today, 01:28 AM
          0 responses
          3 views
          0 likes
          Last Post Max238
          by Max238
           
          Started by rocketman7, Today, 01:00 AM
          0 responses
          2 views
          0 likes
          Last Post rocketman7  
          Started by wzgy0920, 04-20-2024, 06:09 PM
          2 responses
          27 views
          0 likes
          Last Post wzgy0920  
          Started by wzgy0920, 02-22-2024, 01:11 AM
          5 responses
          32 views
          0 likes
          Last Post wzgy0920  
          Working...
          X