![]() |
|
|||||||
| Strategy Analyzer Support for automated system backtesting and optimization using the NinjaTrader Strategy Analyzer. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Jun 2012
Posts: 37
Thanks: 5
Thanked 4 times in 3 posts
|
Hello,
I have coded a very simple test strategy to investigate the behaviour of using different signal names for different trades within the same strategy. I am a bit confused by the results. The strategy has an option DoTradeMultiple to trade either one signal (EMA 50) or three (EMA 50/100/200). The signal names are EMA 50/100/200 accordingly. As I undertstand it the Entry and Exit points for the EMA 50 strategy should be identical whether DoTradeMultiple is set or not. But this does not appear to be the case. I have attached spreadsheets for the backtest results of EMA50 only and EMA50/100/200 to compare, and the test strategy code. Please could you let me know what is causing this behaviour, and whether it is expected or a bug? Thanks One example of a discrepancy is below, and there are many more: 50 100 200 ES 09-12 Sell 1 1350.25 20/06/2012 11:21 NT-00078 Exit 6L NT-00084 EMA50 0 1 Backtest ES 09-12 Sell 1 1349.00 20/06/2012 11:25 NT-00081 Exit 7L NT-00087 EMA50 0 1 Backtest 50 ES 09-12 Sell 1 1350.25 20/06/2012 11:21 NT-00036 Entry 1S NT-00036 EMA50 0 1 Backtest ES 09-12 Buy 1 1350.75 20/06/2012 11:49 NT-00038 Entry 1L NT-00038 EMA50 0 1 Backtest |
|
|
|
|
|
#2 |
|
Member
Join Date: Jun 2012
Posts: 37
Thanks: 5
Thanked 4 times in 3 posts
|
Results attachements for the above...
Last edited by pmcgoohan; 06-26-2012 at 05:12 AM.
|
|
|
|
|
|
#3 | ||||
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
Hello pmcgoohan,
The Entry methods, closes any existing position in the opposite direction before entering a position. For example if you are long and a short signal is generated via the EnterShort() method, then it will first close the long position and then will enter the short position. From the 50.txt file NinjaTrader is closing existing position Quote:
Quote:
Quote:
Quote:
Joydeep M.
NinjaTrader Customer Service |
||||
|
|
|
|
|
#4 |
|
Member
Join Date: Jun 2012
Posts: 37
Thanks: 5
Thanked 4 times in 3 posts
|
I think you missed the point a bit there- I have no problem with the way the 50 EMA trades on its own.
As I understand it using different signal names means the position of other signals is ignored, so the 100/200 EMA trades shouldnt interfere with the 50 EMA trades at all. But the 50 EMA trades are different when running on their own, as compared to when running alongside the 100/200 EMA trades. Why is this? |
|
|
|
|
|
#5 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
Hello pmcgoohan,
Thanks for the clarification. To assist you further can you tell me, while backtesting,
I look forward to assisting you further.
Joydeep M.
NinjaTrader Customer Service |
|
|
|
|
|
#6 |
|
Member
Join Date: Jun 2012
Posts: 37
Thanks: 5
Thanked 4 times in 3 posts
|
Entries per direction = 1
Entry handling = UniqueEntries Exit on close = false As I understand it, UniqueEntries should ensure that the three different MA trade types ignore each others positions. If you want to recreate it- I am running against ES the 500 Tick Bar from 20/06/2012 to 24/06/2012. |
|
|
|
|
|
#7 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
Hello pmcgoohan,
It may be the case where your strategy logic is sending Long and Short order on the same bar which is making the positions count to go haywire. I would suggest to check for the order direction for all the EMA's so that no reverse order gets submitted on the same bar. Also even for unique entries there will only one market position.
Joydeep M.
NinjaTrader Customer Service |
|
|
|
|
|
#8 |
|
Member
Join Date: Jun 2012
Posts: 37
Thanks: 5
Thanked 4 times in 3 posts
|
But surely the point of using different signal names is that you dont need to check what the other signals are doing?
What is the point of using signal names if you have to check whether other signals are submitting orders at the same time? Unless I have misunderstood something, it seems to me that this should be treated as a serious bug. |
|
|
|
|
|
#9 |
|
NinjaTrader Customer Service
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,499
Thanks: 109
Thanked 291 times in 280 posts
|
Hello,
We did have some internal discussion on this case as I can see your point. However take the following scenario which is the primary issue and what occurs in your case. protected override void OnBarUpdate() { EnterLong("EMA50"); EnterLong("EMA100"); EnterShort("EMA50"); } If you run this the output is as follows: Buy 1 tagged EMA50 Buy 1 tagged EMA100 Sell 2 to close and return to flat tagged Close Sell 1 tagged EMA50 Once that EnterShort() occurs it sells 2 to close both the tagged EMA100 and tagged EMA50 positions due to the EnterShort command(Even though entershort was only tagged EMA50). Thus in an event where the strategy would need to reverse its entire position the entry of another named unique entry can effect the performance of another leg since the strategy has only one master Position.MarketPosition. This is a limitation of our managed code and you would need to introduce your own handling to create your own MarketPositions for each leg and update them baised on specific orders filling in OnOrderUpdate() if you need this capability or utilize the unmanaged mode. Now we did see an item where position would report higher then expected. This is being further isolated to see if this is expected or there is an issue that needs to be looked into for next major release however that is separate to your primary concern described above.. -Brett
Brett
NinjaTrader Customer Service |
|
|
|
|
|
#10 |
|
Member
Join Date: Jun 2012
Posts: 37
Thanks: 5
Thanked 4 times in 3 posts
|
Thanks for looking into this for me.
I would have expected the following behaviour: Position 0 EnterLong("EMA50"); Position 1L EnterLong("EMA100"); Position 2L EnterShort("EMA50"); Position 0 To continue... ExitShort("EMA50"); Position 1L ExitLong("EMA100"); Position 0 In other words, I don't see why reversing the earlier EMA50 leads to a total reversal of market position. It should just cover 1 and short 1, even if that means we end up flat. That is self crossing and is legitimate and transaction efficient. If you have contradictory trading signals, you should be flat. Isnt this what it would do if you ran the EMA50 and EMA100 as seperate strategies on the same instrument? This is a genuine question, as this is probably the way I will have to do it now. Edit: also managed orders should submit once the OnBarUpdate event in all timeframes has fired and the total position adjustment is known. eg: you should never send 1 long and 2 short orders on the same bar from different signals- just 1 short order.
Last edited by pmcgoohan; 06-26-2012 at 11:53 AM.
|
|
|
|
|
|
#11 |
|
NinjaTrader Customer Service
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,499
Thanks: 109
Thanked 291 times in 280 posts
|
Hello,
Understood, what you are expecting is not how the feature works which is why I clarified. To do what you want would require separate strategies with separate position events, you can Tag them with names in a single strategy but it is primarily for accounting purposes. -Brett
Brett
NinjaTrader Customer Service |
|
|
|
|
|
#12 |
|
Member
Join Date: Jun 2012
Posts: 37
Thanks: 5
Thanked 4 times in 3 posts
|
Ok- thanks Brett.
I will split my logic across several strategies, and try to use managed orders still. Looking at your rules for managed order entry, I see that "new order entries are ignored when the strategy position is flat and an order submitted by an enter method (EnterLongLimit() for example) is active and the order is used to open a position in the opposite direction" Can I get round this by cancelling any previous EnterLongLimit/EnterShortLimit orders just before (ie: the code line before) a new EnterLong/EnterLongLimit call using CancelOrder. Is CancelOrder compatible with managed orders in this way? |
|
|
|
|
|
#13 |
|
NinjaTrader Customer Service
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,499
Thanks: 109
Thanked 291 times in 280 posts
|
Hello,
Yes this can be done, however keep in mind that these cancellation have to go out through your network and take milleseconds to get fully cancelled. I would suggest waiting at least one OnBarUpdate to make sure the order is truly cancelled and not filled before you submit the second entry order. Please see this sample: http://www.ninjatrader.com/support/f...ad.php?t=18890
Brett
NinjaTrader Customer Service |
|
|
|
|
The following user says thank you to NinjaTrader_Brett for this post: |
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Sell signals, no Buy signals and v v ??? | tradr | Indicator Development | 3 | 05-18-2012 09:31 AM |
| Strategy Wizard to generate signals on multiple time frames | rmyrick | Automated Trading | 1 | 11-19-2010 01:23 PM |
| Using multiple entry/exit signals simultaneously | Learning1 | Strategy Development | 6 | 09-18-2007 02:27 PM |
| Strategy: Using multiple entry/exit signals simultaneously | NinjaTrader_Josh | Reference Samples | 0 | 09-06-2007 12:56 PM |
| Blocking Multiple Order Signals | underground | Automated Trading | 8 | 03-22-2005 06:29 AM |