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

Comparing a current period to a past period

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

    Comparing a current period to a past period

    Hello,
    This is going to be a vague question, but I don't know how else to put it. I'm trying to compare a current period situation to a past period. So for instance to be lookback and compare all the times during the day that price closed at x. Can anyone give me an idea of how to do that? Thanks.

    #2
    There are a number of ways to handle this depending on what you're looking for.

    There are many NS methods that are designed to help you pull past values. I'd suggest looking at our resource sample on Referencing the Correct bar for a few examples of this:



    If these are custom calculations, you would need to save the past period values in an array so you can compare to the current values.

    This is similar to the way you'd check the current high value to the high 3 bars ago. (High[0], High[3], etc)

    For this, please see our Reference Sample on Using a DataSeries Objects to store calculations:

    MatthewNinjaTrader Product Management

    Comment


      #3
      Thanks Matthew. Alright I've been going over this I think I'm in the ball park. Now once I have created my DataSeries how do I then compare the values? The items I'll be comparing could have happened 2 bars ago or 10.

      Comment


        #4
        It's the same way you make comparison to price or indicator values - these are essentially data series that we have made for you.

        if(MyDataSeries[0] == MyDataSeries[5])
        MatthewNinjaTrader Product Management

        Comment


          #5
          Thanks again. Unfortunately I'm comparing a condition such as "at what value did this indicator close every time price closed at 100" so I can't name a specific bar in which that happened.

          Comment


            #6
            This is what I have so far:

            Code:
            private BoolSeries pricecomp;
            
            pricecomp = new BoolSeries(this,MaximumBarsLookBack.Infinite);
            
            pricecomp.Set(RSValue(3, period).iClose[0] > 10);
            I'm hoping that this will identify every time the RSValue was greater than 10. If this is correct I would like to use this information to then determine what price was at each of these instances. Any ideas?

            Comment


              #7
              Here is an example of reading what the price was when the RSI indicator is greater than 50

              Code:
              				if(RSI(20, 3)[0] > 50)
              				{
              				
              				pricecomp.Set(true);
              				}
              				else pricecomp.Set(false);
              				
              			
              				
              				if(pricecomp[0] == true)
              				{
              					Print("Price: " + Close[0] + " RSI:  " + RSI(20, 3)[0]);
              				}
              If you actually want to store that price to be able to compare those, that would take a DataSeries rather than the BoolSeries.

              Code:
              		private DataSeries isTrueprice;
              
                              isTrueprice = new DataSeries(this, MaximumBarsLookBack.Infinite);
              
              			if(RSI(20, 3)[0] > 50)
              				{
              					isTrueprice.Set(Close[0]);
              				}
              				
              				
              		        Print(isTrueprice[0] + " RSI:  " + RSI(20, 3)[0]);
              Last edited by NinjaTrader_Matthew; 02-08-2013, 07:48 AM.
              MatthewNinjaTrader Product Management

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by usazencort, Today, 01:16 AM
              0 responses
              1 view
              0 likes
              Last Post usazencort  
              Started by kaywai, 09-01-2023, 08:44 PM
              5 responses
              603 views
              0 likes
              Last Post NinjaTrader_Jason  
              Started by xiinteractive, 04-09-2024, 08:08 AM
              6 responses
              22 views
              0 likes
              Last Post xiinteractive  
              Started by Pattontje, Yesterday, 02:10 PM
              2 responses
              20 views
              0 likes
              Last Post Pattontje  
              Started by flybuzz, 04-21-2024, 04:07 PM
              17 responses
              230 views
              0 likes
              Last Post TradingLoss  
              Working...
              X