![]() |
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 Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Sep 2007
Posts: 72
Thanks: 0
Thanked 0 times in 0 posts
|
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.
|
|
|
|
|
|
#2 |
|
Member
Join Date: Sep 2007
Posts: 72
Thanks: 0
Thanked 0 times in 0 posts
|
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");
|
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Mar 2007
Location: , Florida, USA
Posts: 663
Thanks: 36
Thanked 7 times in 6 posts
|
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.
|
|
|
|
|
|
#4 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Member
Join Date: Sep 2007
Posts: 72
Thanks: 0
Thanked 0 times in 0 posts
|
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. |
|
|
|
|
|
#6 |
|
Member
Join Date: Sep 2007
Posts: 72
Thanks: 0
Thanked 0 times in 0 posts
|
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
Last edited by woodside; 12-01-2007 at 12:43 PM.
|
|
|
|
|
|
#7 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
woodside,
This is a bug in NT6. Your code works as expected in NT6.5 though. Thanks for reporting.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#8 |
|
Member
Join Date: Sep 2007
Posts: 72
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#9 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
In multi-time framed strategies the proper syntaxing for that method is as follows:
BarsSinceExit(int barsInProgressIndex, string signalName, int exitsAgo)
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#10 |
|
Member
Join Date: Sep 2007
Posts: 72
Thanks: 0
Thanked 0 times in 0 posts
|
Thanks for the help Josh, I have my strategy running correct under 6.5 now.
-Erik |
|
|
|
|
|
#11 |
|
Senior Member
Join Date: Mar 2007
Location: , Florida, USA
Posts: 663
Thanks: 36
Thanked 7 times in 6 posts
|
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.
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |