Is there a way to guarantee that does not happen?
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Prevent Negative Bars (Future data)
Collapse
X
-
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?Tags: None
-
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
-
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
-
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
-
Originally posted by frostengine View PostThe 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 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 tony_28217, Today, 07:04 PM
|
0 responses
3 views
0 likes
|
Last Post
by tony_28217
Today, 07:04 PM
|
||
Started by flybuzz, Today, 10:33 AM
|
1 response
8 views
0 likes
|
Last Post
by flybuzz
Today, 06:59 PM
|
||
Started by spencerp92, 10-10-2023, 09:56 AM
|
4 responses
303 views
0 likes
|
Last Post
by flybuzz
Today, 06:45 PM
|
||
Started by samish18, Yesterday, 10:13 AM
|
1 response
23 views
0 likes
|
Last Post Today, 06:15 PM | ||
Started by Austiner87, Today, 05:02 PM
|
0 responses
5 views
0 likes
|
Last Post
by Austiner87
Today, 05:02 PM
|
Comment