NinjaTrader Support Forum  
X

Attention!

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


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 11-30-2007, 04:25 PM   #1
woodside
Member
 
Join Date: Sep 2007
Posts: 72
Thanks: 0
Thanked 0 times in 0 posts
Default Scale out problem

I am developing a system to trade 2 contracts with different stops and targets.

I am using 2 different entry/stop/target signals, like "longlimit1" and "longlimit2"

I am able to get both orders submitted, and both stops and targets working properly. My problem is, is when one target gets hit, it cancels the remaining stop and target.

So, say the target for "longlimit1" gets hit, it should just cancel the stop for "longlimit1", instead it is canceling both the target and stop for "longlimit2" and leaving me with one open contract and no stops/targets.

The two stops/targets have different oco id's in the order list.

It seems to work fine in backtesting, I can see both entries and both exits where they should be, but running it in live or in replay is when the orders get canceled when they shouldn't.

In the initialize section I have these set: Any ideas?

EntriesPerDirection = 1;
EntryHandling = EntryHandling.UniqueEntries;
Last edited by woodside; 11-30-2007 at 04:59 PM.
woodside is offline  
Reply With Quote
Old 11-30-2007, 10:41 PM   #2
woodside
Member
 
Join Date: Sep 2007
Posts: 72
Thanks: 0
Thanked 0 times in 0 posts
Default

Here is the code I'm using for entries. Does this look correct?
(entryL is calculated above this code snippet).

Code:
SetProfitTarget("Long1", CalculationMode.Ticks, 160);
SetProfitTarget("Long2", CalculationMode.Ticks, 80);    
SetStopLoss("Long1", CalculationMode.Ticks, 55, false);
SetStopLoss("Long2", CalculationMode.Ticks, 50, false);                    
EnterLongLimit(entryL , "Long1"); 
EnterLongLimit((entryL-2) , "Long2");
woodside is offline  
Reply With Quote
Old 11-30-2007, 11:03 PM   #3
KBJ
Senior Member
 
Join Date: Mar 2007
Location: , Florida, USA
Posts: 663
Thanks: 36
Thanked 7 times in 6 posts
Default

Correction:

The workaround I suggested in the original edit of this post (below) should be unnecessary. I just re-tested this feature under 6.0.1000.6, and as Josh mentions in the prior post, it does work.

I suspect that this was either a problem in an earlier NT version, or more likely, that the problem I was trying to work around was related to the caching of parameter values by the Strategy Analyzer causing a change in these default values set by the code to be ignored until NinjaTrader was restarted.

Old Post:


EntryHandling defaults to AllEntries and unfortunately, setting EntriesPerDirection and EntryHandling in the Initialize method has no effect on the strategy.

I found the following was useful to prevent a strategy from being run with the wrong settings when placed in the OnBarUpdate method:

Code:
if ((EntryHandling != EntryHandling.UniqueEntries)  // Correct setting?
  || (EntriesPerDirection != 1))
{                                                  // No.  This is an error.
  Print( "**** Error - Entry handling is not set to UniqueEntries 1" );
  throw new System.ApplicationException("EntryHandling must be UniqueEntries, 1"); // Abort this run.
}
Last edited by KBJ; 12-01-2007 at 07:13 PM.
KBJ is offline  
Reply With Quote
Old 12-01-2007, 02:11 AM   #4
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

Setting EntriesPerDirection and EntryHandling in the Initialize method does work. It adjusts the setting for you away from the default settings automatically when you are loading up a strategy.

Woodside can you confirm with us what version of NinjaTrader you are on? I am also guessing you've seen this reference sample correct? http://www.ninjatrader-support.com/v...ead.php?t=3751 Not exactly the same as what you are doing but similar.
NinjaTrader_Josh is offline  
Reply With Quote
Old 12-01-2007, 09:58 AM   #5
woodside
Member
 
Join Date: Sep 2007
Posts: 72
Thanks: 0
Thanked 0 times in 0 posts
Default

I'm running 6.0.1.0006 multi broker.

I was able to get your example working, but when I try to incorporate that into my script it doesn't work right.

I guess I'll have to work with your sample and try to put my code in there and see what is different.
woodside is offline  
Reply With Quote
Old 12-01-2007, 10:45 AM   #6
woodside
Member
 
Join Date: Sep 2007
Posts: 72
Thanks: 0
Thanked 0 times in 0 posts
Default

My strategy uses multiple time frames. I think that is the issue.

Can someone look at the simple attached script? This will reproduce the issue I'm having. If you remove the

Add(PeriodType.Minute, 15);

and the:

if (BarsInProgress == 0)

The script will work fine, put those in and the extra orders get canceled. I'm running this strategy on a one minute ym12-07 if that matters.

-Erik
Attached Files
File Type: zip SampleScaleOut.zip (1.4 KB, 8 views)
Last edited by woodside; 12-01-2007 at 12:43 PM.
woodside is offline  
Reply With Quote
Old 12-01-2007, 12:57 PM   #7
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

woodside,

This is a bug in NT6. Your code works as expected in NT6.5 though. Thanks for reporting.
NinjaTrader_Josh is offline  
Reply With Quote
Old 12-01-2007, 02:46 PM   #8
woodside
Member
 
Join Date: Sep 2007
Posts: 72
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks for verifying that, I was driving myself crazy. I downloaded 6.5 and am having a few issues with my 2 contract strategy due to some changes.

I am getting an error on this line:

&& (BarsSinceExit() > 60 || BarsSinceExit() == -1 ))

this is the error:

Strategy,Error on calling 'OnBarUpdate' method for strategy 'RegressionTwoContract': You must use the overload that has a 'BarsInProgress' parameter when calling the BarsSinceExit() method in the context of a multi-time frame and instrument strategy.,

Can you help me with the changes I need to make? I've tried a few things without out success. It compiles fine but gives that error when running it.

Thanks.

-Erik
woodside is offline  
Reply With Quote
Old 12-01-2007, 04:18 PM   #9
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

In multi-time framed strategies the proper syntaxing for that method is as follows:
BarsSinceExit(int barsInProgressIndex, string signalName, int exitsAgo)
NinjaTrader_Josh is offline  
Reply With Quote
Old 12-01-2007, 04:52 PM   #10
woodside
Member
 
Join Date: Sep 2007
Posts: 72
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks for the help Josh, I have my strategy running correct under 6.5 now.

-Erik
woodside is offline  
Reply With Quote
Old 12-01-2007, 07:18 PM   #11
KBJ
Senior Member
 
Join Date: Mar 2007
Location: , Florida, USA
Posts: 663
Thanks: 36
Thanked 7 times in 6 posts
Default

Quote:
Originally Posted by Josh View Post
Setting EntriesPerDirection and EntryHandling in the Initialize method does work. It adjusts the setting for you away from the default settings automatically when you are loading up a strategy.
Josh: I just retested this and you are correct - it does work. I suspect that my problem in this area was related to the Strategy Analyzer caching old values of the parameters, which were then not overridden by a change in the default settings in the source code; these settings only take effect when NinjaTrader is restarted or when the strategy name is changed.
KBJ 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
locking scale grid pgabriel SuperDOM and other Order Entry Windows 3 09-27-2007 11:44 AM
Scale Out Partials jon_lbs Strategy Development 2 05-06-2007 10:44 PM
Bug in time scale in Charts? richard Charting 1 06-07-2006 08:34 PM
scale out of position? dave898 Miscellaneous Support 2 04-11-2006 12:51 PM
Why did it scale in? underground Automated Trading 6 04-21-2005 04:59 AM


All times are GMT -6. The time now is 12:15 PM.