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 12-21-2008, 09:42 PM   #1
cunparis
Senior Member
 
Join Date: Feb 2008
Location: Paris
Posts: 720
Thanks: 12
Thanked 15 times in 9 posts
Default Weird behavior with entries per direction

I'm experiencing something weird and I think maybe I don't understand something.

I have a multi-instrument multi-timeframe strategy. When I run with Entries per direction set to 1-6 I get the same number of trades as I do when setting it to 1. But if I set it to 7 I get more trades. Close inspection shows that only 2 trades are done in parallel when I use 7. I have it set up to trade 7 markets, I think the 7 entries per direction and 7 markets is a big coincidence.

I was thinking I put 1 entries per direction and I'd get say just ES for a given date. And if I put 2 entries per direction I'd get a trade on ES & YM for a given date. But from what I see I only get ES & YM when I put 7.
Last edited by cunparis; 12-21-2008 at 09:51 PM.
cunparis is offline  
Reply With Quote
Old 12-22-2008, 09:20 AM   #2
NinjaTrader_Ben
NinjaTrader Customer Service
 
NinjaTrader_Ben's Avatar
 
Join Date: May 2008
Location: Denver, CO
Posts: 3,157
Thanks: 0
Thanked 3 times in 3 posts
Default

Hello,


It is difficult to say without looking at your code. I suggest using TraceOrders and debug it:
http://www.ninjatrader-support.com/H...aceOrders.html

Not you will probably want to use the last (advanced) method on this link to enter your trades as it allows you to specify bars in progress:
http://www.ninjatrader-support.com/H...EnterLong.html

Also, take it one step at a time: one instrument> one trade, two instruments> two trades, etc.
NinjaTrader_Ben is offline  
Reply With Quote
Old 12-22-2008, 01:51 PM   #3
cunparis
Senior Member
 
Join Date: Feb 2008
Location: Paris
Posts: 720
Thanks: 12
Thanked 15 times in 9 posts
Default

The trace orders confirms what I thought was happening. I set the # of entries to 5 and "allEntries".

Code:
10/30/2007 9:20:00 PM Entered internal PlaceOrder() method at 10/30/2007 9:20:00 PM: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='L2' FromEntrySignal=''
10/30/2007 9:49:00 PM Entered internal PlaceOrder() method at 10/30/2007 9:49:00 PM: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='L0' FromEntrySignal=''
10/30/2007 9:49:00 PM Ignored PlaceOrder() method at 10/30/2007 9:49:00 PM: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='L0' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'
The first entry works and the second is rejected. I can't find any reason why it'd be rejected and I suspect this may be a bug.

Now I put entriesPerDirection at 7:

Code:
10/30/2007 9:20:00 PM Entered internal PlaceOrder() method at 10/30/2007 9:20:00 PM: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='L2' FromEntrySignal=''
10/30/2007 9:49:00 PM Entered internal PlaceOrder() method at 10/30/2007 9:49:00 PM: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='L0' FromEntrySignal=''
10/30/2007 9:59:00 PM Entered internal PlaceOrder() method at 10/30/2007 9:59:00 PM: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='L0' FromEntrySignal=''
10/30/2007 9:59:00 PM Ignored PlaceOrder() method at 10/30/2007 9:59:00 PM: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='L0' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'
Now the first 2 trades are accepted and the third one is refused.

I'm really stuck on this, I hope there is an explanation. Thanks for looking at it.
cunparis is offline  
Reply With Quote
Old 12-22-2008, 01:56 PM   #4
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,460
Thanks: 1
Thanked 163 times in 82 posts
Default

cunparis,

You need to break down your code to its bare essentials. Then slowly debug it. You need to manually track your orders and see what is happening. After you determine the simplest case works then you can slowly add layers of complexity to your testing. You shouldn't just jump all of a sudden to testing 7 different orders simultaneously. One step at a time.
NinjaTrader_Josh is offline  
Reply With Quote
Old 12-22-2008, 02:37 PM   #5
cunparis
Senior Member
 
Join Date: Feb 2008
Location: Paris
Posts: 720
Thanks: 12
Thanked 15 times in 9 posts
Default

Quote:
Originally Posted by NinjaTrader_Josh View Post
cunparis,

You need to break down your code to its bare essentials. Then slowly debug it. You need to manually track your orders and see what is happening. After you determine the simplest case works then you can slowly add layers of complexity to your testing. You shouldn't just jump all of a sudden to testing 7 different orders simultaneously. One step at a time.
I understand what you're saying. I just don't understand how this could possibly be happening. I mean I have my strategy enter two orders and the 2nd is rejected due to the entriesPerDirection property. I'm not sure that breaking my strategy down would make a difference but I will give it a try since I'm really stuck on this and I can't do anything else.

I still suspect there is a bug here because I can't find any way for a 2nd trade to get rejected when I have specified 5 entries!
cunparis is offline  
Reply With Quote
Old 12-22-2008, 03:00 PM   #6
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,460
Thanks: 1
Thanked 163 times in 82 posts
Default

cunparis,

It is very simple to test on your end. Just create a strategy that goes EnterLong() twice and you will see it works just fine. Because the base case works it is likely something in your code and that is what you need to find. You need to eliminate all the variables possible and slowly reintroduce them one by one.

If you find the simple base case not to work then that is a different story, but on our end the base case works without fail.
NinjaTrader_Josh is offline  
Reply With Quote
Old 12-22-2008, 03:37 PM   #7
cunparis
Senior Member
 
Join Date: Feb 2008
Location: Paris
Posts: 720
Thanks: 12
Thanked 15 times in 9 posts
Default

Thanks for the ideas, I suspect it's a problem using multi-timeframe & multi-instrument. I'll do as you say and then make it multi-timeframe and then multi-instrument. I'll report my findings.

On a related note, if I want to limit the entries myself, how can I do this? Do I use the IOrder and then OnOrderUpdate? The problem is I submit orders that are not always valid (do not always match the entry signal) so I need a confirmation that the order was executed.

Thanks
cunparis is offline  
Reply With Quote
Old 12-22-2008, 03:48 PM   #8
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,460
Thanks: 1
Thanked 163 times in 82 posts
Default

Then you can use IOrder and check status off of the IOrder object.
NinjaTrader_Josh is offline  
Reply With Quote
Old 12-29-2008, 06:52 AM   #9
cunparis
Senior Member
 
Join Date: Feb 2008
Location: Paris
Posts: 720
Thanks: 12
Thanked 15 times in 9 posts
Default

I think I might have found what was wrong, but the problem is I don't understand EntriesPerDirection. When I started this thread, I had put

Code:
EnterLong(1, 1, "L" + BarsInProgress);
In testing today I wanted to test with a position size of 2. Since I'm using the timeframe parameter to submit to a shorter timeframe, I have to specify the quantity. Can I do that like this?

Code:
EnterLong(1, EntriesPerDirection, "L" + BarsInProgress);
I don't think that's correct but I'm not sure.

EDIT: Ok it seems I'm mixing up the quantity with entriesPerDirection. I understand the latter is used to prevent one from having multiple positions. So am I supposed to code up the quantity myself? I could add a variable with getter/setter to make it configurable with the strategy parameters. Or I can code up a position sizing algorithm based on account balance?

Speaking of account balance, I've read that Ninjatrader doesn't know our account balance, but for me it's showing my real balance with Mirus.

Thanks
Last edited by cunparis; 12-29-2008 at 06:59 AM.
cunparis is offline  
Reply With Quote
Old 12-29-2008, 09:18 AM   #10
NinjaTrader_Ben
NinjaTrader Customer Service
 
NinjaTrader_Ben's Avatar
 
Join Date: May 2008
Location: Denver, CO
Posts: 3,157
Thanks: 0
Thanked 3 times in 3 posts
Default

Hello,

So am I supposed to code up the quantity myself?
>> Yes.

I could add a variable with getter/setter to make it configurable with the strategy parameters.
>> Yes, you could do this.

Or I can code up a position sizing algorithm based on account balance?
>> Yes, you will need to track the account balance yourself within your code. NT does not know your account balance. This link demonstrates how to keep track of this:
http://www.ninjatrader-support2.com/...ead.php?t=4084
NinjaTrader_Ben is offline  
Reply With Quote
Old 12-29-2008, 12:48 PM   #11
cunparis
Senior Member
 
Join Date: Feb 2008
Location: Paris
Posts: 720
Thanks: 12
Thanked 15 times in 9 posts
Default

Quote:
Originally Posted by NinjaTrader_Ben View Post
Hello,

So am I supposed to code up the quantity myself?
>> Yes.

I could add a variable with getter/setter to make it configurable with the strategy parameters.
>> Yes, you could do this.

Or I can code up a position sizing algorithm based on account balance?
>> Yes, you will need to track the account balance yourself within your code. NT does not know your account balance. This link demonstrates how to keep track of this:
http://www.ninjatrader-support2.com/...ead.php?t=4084
Thanks Ben, much clearer now. At first Ninjatrader seems simple but the more I use it the more powerful it is. Just need to know C# to unleash it.
cunparis is offline  
Reply With Quote
Old 01-08-2009, 01:39 PM   #12
cunparis
Senior Member
 
Join Date: Feb 2008
Location: Paris
Posts: 720
Thanks: 12
Thanked 15 times in 9 posts
Thumbs up

I'd like to revisit this subject because I'm working on this right now.

My strategy basically has two instruments. in the code I do an algorithm like this:

Code:
            if(Position.MarketPosition == MarketPosition.Flat) {
// entry criteria here
            } else if (Position.MarketPosition == MarketPosition.Long) {
// exit criteria here
            } else if (Position.MarketPosition == MarketPosition.Short) {
// exit criteria here
            }
My question is if I'm trading two instruments, let's say the first 1 enters a trade. Will the 2nd instrument then go into the Flat code block? And if so and if there is an entry, will it enter?

Now I think this last part has to do with the "entries per direction". I assume if I put 1 that the second instrument would not enter the trade, it'd be ignored. and that if I want it to trade then I put it to 2. What do I put for entries handling?

I currently have my entriesPerDirection to 1 and the EntryHandling to "all" and I was surprised that I got a trade on the 2nd instrument while I already had one on the first. I thought I needed to put entriesPerDirection to 2 to get that behavior. This was live trading, I've never seen that with the backtesting.

Basically what'd I'd like is to have 1 trade max for each instrument. So if it's ES & YM, I'd like to be able to have one of each but not have 2 ES or 2 YM.

Thanks for clarifying this.
cunparis is offline  
Reply With Quote
Old 01-08-2009, 02:03 PM   #13
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,460
Thanks: 1
Thanked 163 times in 82 posts
Default

When working with multiple instruments you should bracket the segments with if (BarsInProgress == 0) to segregate which code block is for which instrument. When checking Position.MarketPosition on a multi-instrument strategy you could use Positions[0].MarketPosition instead.

http://www.ninjatrader-support.com/H...Positions.html

Just put EntriesPerDirection as 1 and EntryHandling = Unique Entries. Then you can trade both, but only once per entry order.
NinjaTrader_Josh is offline  
Reply With Quote
Old 01-08-2009, 02:11 PM   #14
cunparis
Senior Member
 
Join Date: Feb 2008
Location: Paris
Posts: 720
Thanks: 12
Thanked 15 times in 9 posts
Default

Quote:
Originally Posted by NinjaTrader_Josh View Post
When working with multiple instruments you should bracket the segments with if (BarsInProgress == 0) to segregate which code block is for which instrument. When checking Position.MarketPosition on a multi-instrument strategy you could use Positions[0].MarketPosition instead.

http://www.ninjatrader-support.com/H...Positions.html

Just put EntriesPerDirection as 1 and EntryHandling = Unique Entries. Then you can trade both, but only once per entry order.
I want to be able to have open trades on both instruments. I'm playing around and I put EntriesPerDirection=2 and EntryHandling=UniqueEntries and that seems to let me buy one of each. I think this is what I want.
cunparis is offline  
Reply With Quote
Old 01-08-2009, 02:15 PM   #15
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,460
Thanks: 1
Thanked 163 times in 82 posts
Default

That setting will allow you to buy twice per instrument. If that is acceptable to you then you are set.
NinjaTrader_Josh is offline  
Reply With Quote
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
Chart Trader: Condition based entries, time-axis entries, multiple OCO pairs etc. Elliott Wave Suggestions And Feedback 1 11-25-2008 04:23 AM
moving chart along y direction clearpicks Charting 8 09-26-2008 10:55 AM
Entries per direction latkinso General Programming 4 02-12-2008 10:27 AM
Weird Chase Behavior pdawg Strategy Development 5 08-09-2007 08:41 AM
Volume Direction in Strategy Wizard Brody Strategy Development 3 02-06-2007 09:52 AM


All times are GMT -6. The time now is 03:53 PM.

FULL RISK DISCLOSURE: Futures trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. View Full Risk Disclosure.