![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| Strategy Analyzer Support for automated system backtesting and optimization using the NinjaTrader Strategy Analyzer. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Sep 2008
Posts: 183
Thanks: 0
Thanked 1 time in 1 post
|
Attached is a very simple custom fill type that allows market orders to get filled at the current bar's closing price rather than the next bar's opening price. Drop the file into your "Types" source directory (something like C:\Users\UserName\Documents\NinjaTrader 6.5\bin\Custom\Type) and open for editing and recompile any Strategy/Indicator inside NT to install it. Choose the new CurrentBar fill type in the backtesting parameters dialog to activate it. All order types other than market orders proceed using the default fill method. Multi-instrument strategies where you submit orders to bars other than the primary/first bar set are not supported.
Note: I'm aware of the dangers and the objections from backtesting purists with regards to "peeking in the future" in this way, so I don't want to argue about that specific issue. For anyone who doesn't have a deep understanding of how market movements around bar breaks affect your strategy, I don't recommend you use this fill type. In fact, I only recommend this fill type for backtesting trading on daily or larger bars, where your realtime trades happen immediately before the day's trading session closes, but you don't want the time/storage overhead of backtesting using minute bars. For that type of trading, after hours market fluctuations may make this fill type more accurate than the default fill type. If you trade intraday, using this fill type is probably a very bad idea. |
|
|
|
|
|
#2 |
|
Certified NinjaScript Consultant
|
Thank you, Anagoge
|
|
|
|
|
|
#3 | |
|
Senior Member
Join Date: Sep 2008
Posts: 483
Thanks: 0
Thanked 2 times in 2 posts
|
Quote:
Do you have any ideas to do something like this for MaxDrawDown? As it stands, the results are based on the trade open to trade close, subtracted from starting equity. This is completely unacceptable. Rather an appropriate use of DrawDown would show the trader the actual risk that was involved in the trade. Could you offer any ideas for how to do this? ACTUAL DRAW DOWN = The adverse difference between "Fill Price of trade" and the max drawdown while the trade was open. Or the adverse excursion while the trade was live. Clearly, going from when the trade was opened to when the trade was filled does not even begin to give a true picture of the actual risk or and hence the profit factor. If you could offer any assistance in this regard, I would appreciate it. |
|
|
|
|
|
|
#4 |
|
Senior Member
Join Date: Sep 2008
Posts: 183
Thanks: 0
Thanked 1 time in 1 post
|
If you are looking for the maximum adverse extension of each individual trade, NT has a graph for that built-in.
If you want the maximum unrealized drawdown across all trades, there is some related information here: http://www.ninjatrader-support2.com/...ad.php?t=11125 In general, the drawdown calculations are a bit confusing and buggy, but that thread at least attempts to clear things up, and NT 6.5 or 7 might have what you want. I've asked here for a feature that graphs the unrealized equity curve and drawdowns, which is a very useful for strategies with trades that are held for several days/months or that trade very volatile instruments. For example, if you are trading leveraged futures, NT could report a profit on a trade where your account in reality was actually wiped out to 0 (or you had a margin call), if you went down to 0 and then went way back up, on an unrealized basis.
Last edited by Anagoge; 02-26-2009 at 11:51 AM.
|
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Sep 2008
Posts: 483
Thanks: 0
Thanked 2 times in 2 posts
|
Anagoge,
Thanks. I read that thread first before posting here. The graph you refer to in your last trade, that is not for backtesting, correct? Josh gave me an idea here: http://www.ninjatrader-support2.com/...9213#post79213 Which is a good work around for now. Essentially a method that will trade per trade and just write to a file. I can then at least get the info I need. I will also get unrealized per trade in the process. As may as well just write my own backtesting log with my own class, lol. Another way I was getting around it was with a Max Stop setting, but that was a lot of trial and error. But it did give me an idea how bad my intraday drawdown was. For example. Set Close on Exit to false. Set Max Stop to something crazy like 1000 points. Then work it back to 500 points, then 250, until your values change then keep splitting the difference until your stop is no longer changing the results and of course that would give you an "idea" as to how bad your worst draw down was. Then do it with Close on Exit as well for intraday. not perfect, but seemed to help. Ideally, getting said per trade would be nice (or an accurate MAE based on real cost). Anyway, you echoed my sentiment exactly. The drawdown in its current state is simply not acceptable as a true measurement of a real drawdown that one may have incurred in real trading with a real broker, who will really shut off your account and take your real money, lol. Thanks for the post. |
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Sep 2008
Posts: 183
Thanks: 0
Thanked 1 time in 1 post
|
The maximum adverse extension graph is for backtesting and is under Graphs and then MAE in the dropdown. There is some MAE info in the help, if you search for it there. Using stops to get the max is a decent, if time consuming, workaround for the moment. If you get anything working to log the unrealized equity curve and drawdowns, I'd love to see it.
|
|
|
|
|
|
#8 |
|
Senior Member
Join Date: Sep 2008
Posts: 183
Thanks: 0
Thanked 1 time in 1 post
|
Someone asked for more detailed steps to use this, so here they are:
Note that you don't need to make any changes to your strategies, indicators, etc. to use this. Just make sure you choose the FillType when desired. |
|
|
|
|
|
#10 |
|
Senior Member
Join Date: Dec 2009
Posts: 135
Thanks: 2
Thanked 1 time in 1 post
|
Hi Anagoge
A great "enhancement" you have provided here, exactly what I was looking for. Unfortunately I found now out, that with this enhancement StopLoss-Commands no more work. Maybe also other limit/stop commans, I have to check it. Did you not encounter this problem too? Or do you use only simple Enter and Exit commands? Thanks for any feedback, Andre |
|
|
|
|
|
#11 |
|
Senior Member
Join Date: Sep 2008
Posts: 183
Thanks: 0
Thanked 1 time in 1 post
|
You are correct - this custom fill type forces orders to be filled at the current bar's closing price. It probably isn't appropriate for any other types of orders that must fill at other prices, such as a stop loss, or intrabar exits using Level 2 data and multiple time frames, etc. You might be able to hack the code to force fills at other prices based on the order type (stop loss, trailing stop, etc.), but I don't know exactly what you would need to change, since I'm only using this for backtesting on daily data and I'm happy to only fill at the closing price.
Last edited by Anagoge; 01-06-2010 at 01:40 AM.
|
|
|
|
|
|
#12 | |
|
Senior Member
Join Date: Aug 2008
Location: Netherlands
Posts: 159
Thanks: 17
Thanked 5 times in 5 posts
|
Thanks alot Anagoge for this custom filltype; exactly what I was looking for.
I've corrected four NinjaTrader 7.0 errors in your original file, which makes it compatbile with NT 7.0. Please see the attachment for this.Quote:
![]() Edit: I've just noticed that this same problem persists in the "Trades" tab of the Strategy Analyzer, where the time is + 1 unit (in comparison with the chart). So, the chart uses the closing price of 18-8-2010, places the arrows and lines on 19-8-2010, and the "Trades" tab places the entry also at 19-8-2010. Is it possible to override this (apparently) default behavior of NinjaTrader? Any thoughts would be helpful, Regards,
Last edited by J_o_s; 08-24-2010 at 05:48 AM.
|
|
|
|
|
|
|
#13 |
|
Senior Member
Join Date: Sep 2008
Posts: 183
Thanks: 0
Thanked 1 time in 1 post
|
J_o_s, when I looked at NT 6.5, I did not find a way to change the trade date, and made a note of that in my comments in the source file. Unfortunately, since I'm mainly using another trading tool, I don't have the urge to investigate methods for modifying the dates in NT 7, but it might be possible. Someone else here might be able to assist you.
|
|
|
|
|
|
#14 | |
|
Senior Member
Join Date: Aug 2008
Location: Netherlands
Posts: 159
Thanks: 17
Thanked 5 times in 5 posts
|
Quote:
![]() I noticed that the class "NinjaTrader.Cbi.Order" includes an "Time" component, which "gets or sets the time of last change". That's the only class I've come across which looks like it might work. ![]() However, I can't access the value of the previous bar in the CurrentBarFillType.cs, neither with Time[1] nor with a DateTimeSeries class. Anyone got a hint or tip for me? ![]() Regards, |
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to buy at the closing price on current bar? | klchoi123 | Strategy Analyzer | 65 | 08-03-2010 06:49 AM |
| Help on Wrong Closing Price | dreamliner | Miscellaneous Support | 6 | 12-29-2008 03:37 PM |
| Virtual execution price is not the same as the current price | Xtrooper | ATM Strategies (Discretionary Trading) | 4 | 10-06-2008 09:12 AM |
| Current position in a backtest | Jean-Marc-Molina | ATM Strategies (Discretionary Trading) | 4 | 04-27-2008 10:21 AM |
| CrossBelow previous bar and omit current bar | ct | General Programming | 1 | 06-03-2007 02:54 AM |