Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Prevent Negative Bars (Future data)

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

    Prevent Negative Bars (Future data)

    When testing strategies, is there a way to make sure that my strategy does not "peek" forward? In NT if you give it Close[-1] it will give you a "future" bar when backtesting. I have been burned by this before, and would like to prevent the mistake from happening again.

    Is there a way to guarantee that does not happen?

    #2
    frostengine,

    In programming, accessing a negative index is hardly ever advised here. As long as the index is greater than 0 you are guaranteed the strategy isn't peeking into the future. This is like looking at memory that isn't part of the array in some cases.

    These dataseries are built up historically bar by bar so they also wouldn't have access to future values of themselves. Close[-1] may work, I haven't tried it, but as a general rule of thumb dataseries will not contain future values.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      The negative index certainly exists, I have used it in combination with some "data mining" code I wrote.

      For example, you can even do RSI(3,1)[-1] and it will work.. Close[-5].. If you give Time[-5] it will print out the time exact 5 bars into the future. It will let you go as far into the future as you have data for.This glitch has existed for a while in NT.

      My problem is, I have very complex strategies with loops all over the place, I try to ensure no negative indexes exist, but due to the complexity of the code its hard to test for. I wish there was a way to cause NinjaTrader to generate an exception if a negative index was accessed.

      However, the negative index but does have its perks when data mining, but needs to be a way to prevent it. I can not count how many times I "thought", I had a good strategy only to realize it was peaking. This is a serious issue.

      Comment


        #4
        frostengine,

        For example, if you create your own data series you must use MyDataseries.Set() to add any elements to it, if you don't add them they don't exist. What could be happening here is that NinjaTrader behaves a bit differently for indicator historical plots and I just haven't done any tests yet that exposed the behavior to me. I will have to double check with our Tech Lead as its more of a development item. I don't have source code access so I can't really look beyond the surface here.

        I guess I am not sure what you are asking here. If you program your code so that it doesn't try to access negative numbers as indices, then it won't be peeking into the future. Generally, for loops, etc. are not advised nor needed in most cases. Do you have an example of what you need to not peek into the future? Could you explain what it is you want to make so that it cannot peek into the future?

        If you are asking about general exceptions, etc. you can check for negative indices and throw your own exception in C#.
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by frostengine View Post
          The negative index certainly exists, I have used it in combination with some "data mining" code I wrote.

          For example, you can even do RSI(3,1)[-1] and it will work.. Close[-5].. If you give Time[-5] it will print out the time exact 5 bars into the future. It will let you go as far into the future as you have data for.This glitch has existed for a while in NT.

          My problem is, I have very complex strategies with loops all over the place, I try to ensure no negative indexes exist, but due to the complexity of the code its hard to test for. I wish there was a way to cause NinjaTrader to generate an exception if a negative index was accessed.

          However, the negative index but does have its perks when data mining, but needs to be a way to prevent it. I can not count how many times I "thought", I had a good strategy only to realize it was peaking. This is a serious issue.
          Let us go back to basics here. If you are calling things with indices from values that are calculated, then all you need to do to ensure that you never call with a negative index is to lower-bound your values when you use them in a call.

          Let us assume that you have a calculated int called CalcValue.

          Then all you need to do when calling it for a Close for example would be Close[Math.Max(CalcValue, 0)].

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by trilliantrader, 04-18-2024, 08:16 AM
          4 responses
          18 views
          0 likes
          Last Post trilliantrader  
          Started by mgco4you, Today, 09:46 PM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by wzgy0920, Today, 09:53 PM
          0 responses
          9 views
          0 likes
          Last Post wzgy0920  
          Started by Rapine Heihei, Today, 08:19 PM
          1 response
          10 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by Rapine Heihei, Today, 08:25 PM
          0 responses
          10 views
          0 likes
          Last Post Rapine Heihei  
          Working...
          X