Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
backtesting discprenency with forward testing
Collapse
X
-
Originally posted by NinjaTrader_Bertrand View PostJon, then you would need to debug your strategy conditions, simplify as much as possible to get to the root of the issue. It's also very helpful to add visual confirmations that the code triggered trades, so can easily confirm what is working and what is not.
Like I said the only changes I made in my strategy was going from DateTime.Now to Time[0]. With DateTime.Now I was getting 2 trades and all sorts of text written to the output window. Once I ran the backtest on Time[0], I get absolutely nothing - No trades, No output, Nada.
Comment
-
Yes, you would need to debug then why this is the case for your conditions and how they are affected by the time reference you use - for example if the time stamp granularity offered by the series you run this on does not allow for an evaluation of your conditions it would not trigger (for example time being exactly equal to 93000 on a tick chart likely creates issues)BertrandNinjaTrader Customer Service
Comment
-
Originally posted by NinjaTrader_Bertrand View PostYes, you would need to debug then why this is the case for your conditions and how they are affected by the time reference you use - for example if the time stamp granularity offered by the series you run this on does not allow for an evaluation of your conditions it would not trigger (for example time being exactly equal to 93000 on a tick chart likely creates issues)
this is the code I'm using:
PHP Code:if(Time[0] > DateTime.Parse(endTime))
ExitAll("End of TradeDate");
PHP Code:if(DateTime.Now > DateTime.Parse(endTime))
ExitAll("End of TradeDate");
Also, just be clear, NT will NOT be able to support tick-based backtest runs, correct? Because COBC is defaulted to true? Even if I set the timeframe to 1-tick?
Comment
-
Jon, both Time[0] and DateTime.Now would return DateTime structures, try printing all associated components.
Do this snippet below work you? endTime is just a user supplied int here, as we're not working with DateTime structures.
Code:protected override void OnBarUpdate() { if (Historical) return; if (ToTime(Time[0]) > endTime) EnterLong(); Print(DateTime.Now); Print(Time[0]); }
BertrandNinjaTrader Customer Service
Comment
-
Originally posted by NinjaTrader_Bertrand View PostJon, both Time[0] and DateTime.Now would return DateTime structures, try printing all associated components.
Do this snippet below work you? endTime is just a user supplied int here, as we're not working with DateTime structures.
Code:protected override void OnBarUpdate() { if (Historical) return; if (ToTime(Time[0]) > endTime) EnterLong(); Print(DateTime.Now); Print(Time[0]); }
Thanks. That does work for me.
Thanks again!
jonmoron
Comment
-
Bertrand,
So all this talk about not getting 'intra-bar' fills in NT is hogwash? I've heard many people say that the NT backtester is sub-par because you will not get any intra-bar fills. But if I start a backtest and set the bars to 1-tick, the code will work on each tick, correct (assuming I have tick-data)?
Also, I seem to still have a problem with comparing time. This is what I want to do. I want to enter the market at a time (say 8:20am) and exit the market at another time (say 3:10pm). Those variables are set by the user. However, what seems to be happening, is after day 1 completes, I never am able to enter the market any other day (at 8:20 am) on a backtest.
Any suggestions?
thanks!
jon
Comment
-
Jon,
If you decide to run on a 1 tick series which is extremely taxing on system resources, yes it would be a 1-tick backtest.
To enter at 8:20AM you would actually have to have a bar with that exact time as the timestamp of the bar. When you check for something like if (ToTime(Time[0]) == 82000) you are looking for an exact match of the timestamp of the bar versus 8:20AM. If you are using tick data this may not be the case as each bar could have varying timestamps depending on when the tick came in. You would then need to set up an acceptable time range for the timestamps to be within. Note that setting up a range can result in multiple bars being true for the condition.Josh P.NinjaTrader Customer Service
Comment
-
Originally posted by NinjaTrader_Josh View PostJon,
To enter at 8:20AM you would actually have to have a bar with that exact time as the timestamp of the bar. When you check for something like if (ToTime(Time[0]) == 82000) you are looking for an exact match of the timestamp of the bar versus 8:20AM. If you are using tick data this may not be the case as each bar could have varying timestamps depending on when the tick came in. You would then need to set up an acceptable time range for the timestamps to be within. Note that setting up a range can result in multiple bars being true for the condition.
I understand. In fact in my code I check for ToTime(Time[0]) > ToTime(DateTime.Parse("startTime")). startTime is defined as 8:20. I
then enter the market. I also check if I've already entered and do not re-enter. This actually works beautifully in forward testing and goes in perfectly and not again after the next tick that comes in at 8:20.
In fact the entire strategy works just fine. When the trade-date ends (3:10pm), I do a similar exit-time check and then exit the market (resetting the previous boolean to prepare for the next day entry).
However this is when the entry logic is checked (3:11pm is greater than 8:20am) and re-enters. I want to re-enter the market on the NEXT trading day. Does this make sense?
thanks!
jon
Comment
-
Then in addition to your time checks I would add some date checks with ToDay(). http://www.ninjatrader-support.com/H...ide.html?ToDay
When the dates change only then can you reenter. Otherwise, don't allow retrading.Josh P.NinjaTrader Customer Service
Comment
-
Originally posted by NinjaTrader_Josh View PostThen in addition to your time checks I would add some date checks with ToDay(). http://www.ninjatrader-support.com/H...ide.html?ToDay
When the dates change only then can you reenter. Otherwise, don't allow retrading.
thanks!
jon
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by rbeckmann05, Yesterday, 06:48 PM
|
1 response
12 views
0 likes
|
Last Post
by bltdavid
Today, 05:43 AM
|
||
Started by llanqui, Today, 03:53 AM
|
0 responses
6 views
0 likes
|
Last Post
by llanqui
Today, 03:53 AM
|
||
Started by burtoninlondon, Today, 12:38 AM
|
0 responses
10 views
0 likes
|
Last Post Today, 12:38 AM | ||
Started by AaronKoRn, Yesterday, 09:49 PM
|
0 responses
15 views
0 likes
|
Last Post
by AaronKoRn
Yesterday, 09:49 PM
|
||
Started by carnitron, Yesterday, 08:42 PM
|
0 responses
11 views
0 likes
|
Last Post
by carnitron
Yesterday, 08:42 PM
|
Comment