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

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 judysamnt7, 03-13-2023, 09:11 AM
                4 responses
                59 views
                0 likes
                Last Post DynamicTest  
                Started by ScottWalsh, Today, 06:52 PM
                4 responses
                36 views
                0 likes
                Last Post ScottWalsh  
                Started by olisav57, Today, 07:39 PM
                0 responses
                7 views
                0 likes
                Last Post olisav57  
                Started by trilliantrader, Today, 03:01 PM
                2 responses
                21 views
                0 likes
                Last Post helpwanted  
                Started by cre8able, Today, 07:24 PM
                0 responses
                10 views
                0 likes
                Last Post cre8able  
                Working...
                X