NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > Application Technical Support > Strategy Analyzer

Strategy Analyzer Support for automated system backtesting and optimization using the NinjaTrader Strategy Analyzer.

Reply
 
Thread Tools Display Modes
Old 06-26-2012, 05:07 AM   #1
pmcgoohan
Member
 
Join Date: Jun 2012
Posts: 37
Thanks: 5
Thanked 4 times in 3 posts
Default Multiple Signals Discrepancy In Backtest

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
Attached Files
File Type: cs TestMultipleSignals.cs (1.9 KB, 4 views)
pmcgoohan is offline  
Reply With Quote
Old 06-26-2012, 05:09 AM   #2
pmcgoohan
Member
 
Join Date: Jun 2012
Posts: 37
Thanks: 5
Thanked 4 times in 3 posts
Default

Results attachements for the above...
Attached Files
File Type: txt 50 100 200.txt (196.7 KB, 1 views)
File Type: txt 50.txt (66.8 KB, 1 views)
Last edited by pmcgoohan; 06-26-2012 at 05:12 AM.
pmcgoohan is offline  
Reply With Quote
Old 06-26-2012, 05:29 AM   #3
NinjaTrader_Joydeep
NinjaTrader Customer Service
 
NinjaTrader_Joydeep's Avatar
 
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
Default

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:
ES 09-12,Sell,1,1350.25,20/06/2012 11:21,NT-00035,Exit,-,NT-00035,Close position,0,1,Backtest,
and then entering new short position
Quote:
ES 09-12,Sell,1,1350.25,20/06/2012 11:21,NT-00036,Entry,1S,NT-00036,EMA50,0,1,Backtest,
Exiting the short
Quote:
ES 09-12,Buy,1,1350.75,20/06/2012 11:49,NT-00037,Exit,-,NT-00037,Close position,0,1,Backtest,
Entering a new long position
Quote:
ES 09-12,Buy,1,1350.75,20/06/2012 11:49,NT-00038,Entry,1L,NT-00038,EMA50,0,1,Backtest,
This is expected.
NinjaTrader_Joydeep is offline  
Reply With Quote
Old 06-26-2012, 05:36 AM   #4
pmcgoohan
Member
 
Join Date: Jun 2012
Posts: 37
Thanks: 5
Thanked 4 times in 3 posts
Default

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?
pmcgoohan is offline  
Reply With Quote
Old 06-26-2012, 05:50 AM   #5
NinjaTrader_Joydeep
NinjaTrader Customer Service
 
NinjaTrader_Joydeep's Avatar
 
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
Default

Hello pmcgoohan,
Thanks for the clarification.

To assist you further can you tell me, while backtesting,
  1. What Entries per direction you have set
  2. What is the Entry Handling you have set.

I look forward to assisting you further.
NinjaTrader_Joydeep is offline  
Reply With Quote
Old 06-26-2012, 05:58 AM   #6
pmcgoohan
Member
 
Join Date: Jun 2012
Posts: 37
Thanks: 5
Thanked 4 times in 3 posts
Default

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.
pmcgoohan is offline  
Reply With Quote
Old 06-26-2012, 08:22 AM   #7
NinjaTrader_Joydeep
NinjaTrader Customer Service
 
NinjaTrader_Joydeep's Avatar
 
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
Default

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.
NinjaTrader_Joydeep is offline  
Reply With Quote
Old 06-26-2012, 08:29 AM   #8
pmcgoohan
Member
 
Join Date: Jun 2012
Posts: 37
Thanks: 5
Thanked 4 times in 3 posts
Default

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.
pmcgoohan is offline  
Reply With Quote
Old 06-26-2012, 09:11 AM   #9
NinjaTrader_Brett
NinjaTrader Customer Service
 
NinjaTrader_Brett's Avatar
 
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,499
Thanks: 109
Thanked 291 times in 280 posts
Default

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
NinjaTrader_Brett is offline  
Reply With Quote
Old 06-26-2012, 11:45 AM   #10
pmcgoohan
Member
 
Join Date: Jun 2012
Posts: 37
Thanks: 5
Thanked 4 times in 3 posts
Default

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.
pmcgoohan is offline  
Reply With Quote
Old 06-26-2012, 12:30 PM   #11
NinjaTrader_Brett
NinjaTrader Customer Service
 
NinjaTrader_Brett's Avatar
 
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,499
Thanks: 109
Thanked 291 times in 280 posts
Default

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
NinjaTrader_Brett is offline  
Reply With Quote
Old 06-26-2012, 03:20 PM   #12
pmcgoohan
Member
 
Join Date: Jun 2012
Posts: 37
Thanks: 5
Thanked 4 times in 3 posts
Default

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?
pmcgoohan is offline  
Reply With Quote
Old 06-27-2012, 06:10 AM   #13
NinjaTrader_Brett
NinjaTrader Customer Service
 
NinjaTrader_Brett's Avatar
 
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,499
Thanks: 109
Thanked 291 times in 280 posts
Default

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
NinjaTrader_Brett is offline  
Reply With Quote
The following user says thank you to NinjaTrader_Brett for this post:
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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


All times are GMT -6. The time now is 03:38 AM.