Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

compare to all data in dataseries

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

    compare to all data in dataseries

    I have a data series that records the Close[0] for each bar.

    I would like to compare the Close[0] to all of the data stored in the my data series to see if any of the prior closes are equal to the current close.

    How do you compare to all data and not just a specific recorded bar?

    Thank you.

    #2
    Hello,

    You wouldn't actually need to create your own data series for this.

    Instead you could use a for loop to compare the Close[0] to Close[X]

    C# iteration statements (for, foreach, do, and while) repeatedly execute a block of code. You use those statements to create loops or iterate through a collection.

    Code:
    //BARSBACK would be the distance you want to go back (you will want to ensure enough bars have been generated first
    
    for (int i = 1; i <= BARSBACK; i++)
    {
             if(Close[0]== Close[i])
         //do something
    }
    The following link will show you how you can ensure enough bars have been generated when working with indicators: http://www.ninjatrader.com/support/h...urrentbars.htm

    If this is for a strategy: http://www.ninjatrader.com/support/h...srequired2.htm

    Please let me know if I can be of further assistance.
    LanceNinjaTrader Customer Service

    Comment


      #3
      Originally posted by darkspeed View Post
      I have a data series that records the Close[0] for each bar.

      I would like to compare the Close[0] to all of the data stored in the my data series to see if any of the prior closes are equal to the current close.

      How do you compare to all data and not just a specific recorded bar?

      Thank you.
      Look up MRO in the NT Help.

      Comment


        #4
        What would be the best method if i wanted to count the instances of a match in the last x number of bars?

        Thank you.

        Comment


          #5
          Originally posted by darkspeed View Post
          What would be the best method if i wanted to count the instances of a match in the last x number of bars?

          Thank you.
          You would have to write a loop.

          Comment


            #6
            Thanks ..

            This may be a silly question but when you have a calculate on bar close set, does a loop complete on every bar close or does it only run one cycle of a loop on bar close?

            Comment


              #7
              Originally posted by darkspeed View Post
              Thanks ..

              This may be a silly question but when you have a calculate on bar close set, does a loop complete on every bar close or does it only run one cycle of a loop on bar close?
              Hello,

              If

              CalculateOnBarClose = true;

              and the loop is within

              OnBarUpdate()

              it will run the loop all the way through at the close of each bar.

              Please let me know if I can be of further assistance.
              LanceNinjaTrader Customer Service

              Comment


                #8
                Perfect thanks

                Comment

                Latest Posts

                Collapse

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