NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Sunday May 26th at 12PM 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 09-24-2010, 12:06 PM   #1
wahooj
Member
 
Join Date: Mar 2010
Posts: 30
Thanks: 0
Thanked 0 times in 0 posts
Default Multiple instruments order getting canceled immediately

hello,

I have a strat that works with multiple instruments. If a limit is crossed i'll but spy's and if another limit is crossed I'll sell the ES. Profit targets and Stop losses are then set for each. What's happening is the Spy's enter and set their profit target and stop loss. On the next bar update the ES is triggered and set's it's profit target and stop loss, but then within the same bar the ES order is immediately canceled/Exited as are the stops. I'm attaching the output as well as the trade ledger. Any help would be much appreciated.

6/15/2010 8:39:00 AM Entered internal PlaceOrder() method at 6/15/2010 8:39:00 AM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1,000 LimitPrice=110.44 StopPrice=0 SignalName='Buy Breakout Bias 1' FromEntrySignal=''
6/15/2010 8:39:00 AM Entered internal SetStopTarget() method: Type=Target FromEntrySignal='' Mode=Ticks Value=65.9999999999981 Currency=0 Simulated=False
6/15/2010 8:39:00 AM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='' Mode=Ticks Value=44.9999999999987 Currency=0 Simulated=False
Time 83900

Date 20100615

High 110.41

Low 110.2


Range 0.209999999999994

Profit Target 65.9999999999981

Stop Loss 44.9999999999987


Profit Target2 21.9999999999994

Stop Loss2 14.9999999999996

Entry Point 110.41


6/15/2010 8:40:00 AM Entered internal PlaceOrder() method at 6/15/2010 8:40:00 AM: BarsInProgress=1 Action=SellShort OrderType=Limit Quantity=2 LimitPrice=1098.00 StopPrice=0 SignalName='Sell Reversal Bias 1' FromEntrySignal=''
6/15/2010 8:40:00 AM Entered internal SetStopTarget() method: Type=Target FromEntrySignal='Sell Reversal Bias 1' Mode=Ticks Value=21.9999999999994 Currency=0 Simulated=False
6/15/2010 8:40:00 AM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='Sell Reversal Bias 1' Mode=Ticks Value=14.9999999999996 Currency=0 Simulated=False
Time 84000

Date 20100615

High 110.41

Low 110.2



Range 0.209999999999994

Profit Target 65.9999999999981

Stop Loss 44.9999999999987


Profit Target2 21.9999999999994

Stop Loss2 14.9999999999996

Entry Point 110.41


6/15/2010 8:40:00 AM Cancelled pending exit order, since associated position is closed: Order='NT-00011/Backtest' Name='Profit target' State=Working Instrument='ES 06-10' Action=BuyToCover Limit price=1097.75 Stop price=0 Quantity=2 Strategy='MarketBiasBASE_Long_Short' Type=Limit Tif=Gtc Oco='NT-00005' Filled=0 Fill price=0 Token='b919262576464d62ae90d680d9cdcc02' Gtd='12/1/2099 12:00:00 AM'
6/15/2010 8:40:00 AM Cancelled OCO paired order: BarsInProgress=1: Order='NT-00011/Backtest' Name='Profit target' State=Cancelled Instrument='ES 06-10' Action=BuyToCover Limit price=1097.75 Stop price=0 Quantity=2 Strategy='MarketBiasBASE_Long_Short' Type=Limit Tif=Gtc Oco='NT-00005' Filled=0 Fill price=0 Token='b919262576464d62ae90d680d9cdcc02' Gtd='12/1/2099 12:00:00 AM'



Ledger for both trades: The spy trade shows it exited based on it's profit target but the ES was immediately exited stating a Stop loss" but we can see from the output the stop loss was 14.9 ticks. I have live until canceled set to true.
3 ES 06-10 Backtest MarketBiasBASE_Long_Short Short 2 1098 1098.25 6/15/2010 8:41:00 AM 6/15/2010 8:41:00 AM Sell Reversal Bias 1 Stop loss 1

4 SPY Backtest MarketBiasBASE_Long_Short Long 1000 110.44 111.1 6/15/2010 8:40:00 AM 6/15/2010 12:16:00 PM Buy Breakout Bias 1 Profit target 647.999999999997 1978.99999999999 12 230.000000000004 659.999999999997 12 217


thanks
wahooj is offline  
Reply With Quote
Old 09-24-2010, 12:37 PM   #2
NinjaTrader_Brett
NinjaTrader Customer Service
 
NinjaTrader_Brett's Avatar
 
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,498
Thanks: 109
Thanked 291 times in 280 posts
Default

Hello,

Thank you for your forum post.

What approach are you using are you using an unmanaged or managed entry appoach?

If you are unsure I would need to see the line in your code that you are entering both of these orders in the market.

I look forward to assisting you further.
NinjaTrader_Brett is offline  
Reply With Quote
Old 09-24-2010, 12:53 PM   #3
wahooj
Member
 
Join Date: Mar 2010
Posts: 30
Thanks: 0
Thanked 0 times in 0 posts
Default

Managed. But i during my trouble shooting I've tried unmanaged to no avail.

Here's the code. I cleaned it up a little so it wouldn't be so lengthy.

protected override void Initialize()
{
Add("ES 06-10", PeriodType.Minute ,1);

TraceOrders = true;
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{

if (BarsInProgress != 0)
return;
{
if ( ToTime(Time[0]) > rangeStart && ToTime(Time[0]) <= rangeEnd)
{

profitTarget1 = Some Formula;
stopLoss1 = Some Formula;
profitTarget2 = Some Formula;
stopLoss2 = Some Formula ;

}
}

if(CrossAbove(Close, top, 1) && buyBreakoutBias1 == null)
{
buyBreakoutBias1 = EnterLongLimit(0, true,ent1,(top+ n ), "Buy Breakout Bias 1");
SetProfitTarget(CalculationMode.Ticks, profitTarget1);
SetStopLoss(CalculationMode.Ticks, stopLoss1);

}

if(CrossBelow(Close, entrypointtop, 1) && sellReversalBias1 == null)
{
sellReversalBias1 = EnterShortLimit(1,true, ent2, Closes[1][0], "Sell Reversal Bias 1");
SetProfitTarget("Sell Reversal Bias 1", CalculationMode.Ticks, profitTarget2);
SetStopLoss("Sell Reversal Bias 1",CalculationMode.Ticks, stopLoss2 , false);
}

if(ToTime(Time[0]) == exitTrade)
{
ExitShort("","");
ExitLong("","");
ExitShort(1,ent2, "", "");
ExitLong(1,ent2, "", "");
bottom= 0;
top= 0;
range = 0;
profitTarget1 = 0;
profitTarget2 = 0;
stopLoss1 = 0;
stopLoss2 = 0;

}
wahooj is offline  
Reply With Quote
Old 09-24-2010, 01:06 PM   #4
NinjaTrader_Brett
NinjaTrader Customer Service
 
NinjaTrader_Brett's Avatar
 
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,498
Thanks: 109
Thanked 291 times in 280 posts
Default

Hello,

Here is the issue I believe at first glance:

if(CrossAbove(Close, top, 1) && buyBreakoutBias1 == null)
{
buyBreakoutBias1 = EnterLongLimit(0, true,ent1,(top+ n ), "Buy Breakout Bias 1");

Once buyBreakoutBias1 because !null then this stops executing. Which is what you want for an unmanaged approach but not for managed.

You have to continually call EnterLongLimit until your filled as when you stop calling it the order is cancelled. Please see here:

http://www.ninjatrader.com/support/h...d_approach.htm

Specifically this: By default, orders submitted via Entry() and Exit() methods automatically cancel at the end of a bar if not re-submitted
NinjaTrader_Brett is offline  
Reply With Quote
Old 09-24-2010, 02:20 PM   #5
wahooj
Member
 
Join Date: Mar 2010
Posts: 30
Thanks: 0
Thanked 0 times in 0 posts
Default

Ahhh okay. That fixes another problem that i didn't realize i had until now but not this specific problem. The problem is not that the ES entry "sellReversalBias1" is getting canceled before it has a chance to fill it's just the opposite. The ES entry is getting filled it's just exiting immediately instead of waiting for the stop loss or profit target. By eliminating the null check It's now resubmitting every time that condition is met.
wahooj is offline  
Reply With Quote
Old 09-24-2010, 02:24 PM   #6
NinjaTrader_Brett
NinjaTrader Customer Service
 
NinjaTrader_Brett's Avatar
 
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,498
Thanks: 109
Thanked 291 times in 280 posts
Default

Hello,

Awesome. Glad your on the right track now.

Let me know if I can be of further assistance.
NinjaTrader_Brett is offline  
Reply With Quote
Old 09-24-2010, 02:37 PM   #7
wahooj
Member
 
Join Date: Mar 2010
Posts: 30
Thanks: 0
Thanked 0 times in 0 posts
Default

i still have my original problem of the ES exiting in the same bar it enters. Any other suggestions for that?
wahooj is offline  
Reply With Quote
Old 09-24-2010, 02:43 PM   #8
NinjaTrader_Brett
NinjaTrader Customer Service
 
NinjaTrader_Brett's Avatar
 
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,498
Thanks: 109
Thanked 291 times in 280 posts
Default

Hello,

How is it exiting, Can you find this section in the output window with TraceOrders=True enabled where the entry is closed out.

I would suggest also adding Print() lines to all your exit logic to make sure its executing as you expect.
NinjaTrader_Brett is offline  
Reply With Quote
Old 09-24-2010, 03:21 PM   #9
wahooj
Member
 
Join Date: Mar 2010
Posts: 30
Thanks: 0
Thanked 0 times in 0 posts
Default

i have trace orders= true that's where the output from ealier came from. You'll notice in the output i submitted in post #1 that it does not specify exiting the order. It states that the strat is canceling pending order since associated position is closed. See the order below. It Enters at 1098 then sets a profit target then a stop loss and then cancels those stops because the position was closed.

6/15/2010 8:40:00 AM Entered internal PlaceOrder() method at 6/15/2010 8:40:00 AM: BarsInProgress=1 Action=SellShort OrderType=Limit Quantity=2 LimitPrice=1098.00 StopPrice=0 SignalName='Sell Reversal Bias 1' FromEntrySignal=''

6/15/2010 8:40:00 AM Entered internal SetStopTarget() method: Type=Target FromEntrySignal='Sell Reversal Bias 1' Mode=Ticks Value=21.9999999999994 Currency=0 Simulated=False

6/15/2010 8:40:00 AM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='Sell Reversal Bias 1' Mode=Ticks Value=14.9999999999996 Currency=0 Simulated=False

6/15/2010 8:40:00 AM Cancelled pending exit order, since associated position is closed: Order='NT-00017/Backtest' Name='Profit target' State=Working Instrument='ES 06-10' Action=BuyToCover Limit price=1097.75 Stop price=0 Quantity=2 Strategy='MarketBiasBASE_Long_Short' Type=Limit Tif=Gtc Oco='NT-00009' Filled=0 Fill price=0 Token='47082fb4d12745c5845f4809c3956263' Gtd='12/1/2099 12:00:00 AM'

6/15/2010 8:40:00 AM Cancelled OCO paired order: BarsInProgress=1: Order='NT-00017/Backtest' Name='Profit target' State=Cancelled Instrument='ES 06-10' Action=BuyToCover Limit price=1097.75 Stop price=0 Quantity=2 Strategy='MarketBiasBASE_Long_Short' Type=Limit Tif=Gtc Oco='NT-00009' Filled=0 Fill price=0 Token='47082fb4d12745c5845f4809c3956263' Gtd='12/1/2099 12:00:00 AM'
wahooj is offline  
Reply With Quote
Old 09-24-2010, 03:53 PM   #10
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

Hello wahooj,

Beyond the stops and targets, the only exit condition I can see on ES is:
ExitShort(1,ent2, "", "");

Is this what's causing the exit or something else? You should be able to look at the report for one of the ES trades and identify a signal name for the exit condition. Hopefully that will provide some clues.

After running the report, click Trades tab and then look at Exit Name for one of the trades.
NinjaTrader_RyanM is offline  
Reply With Quote
Old 09-24-2010, 04:18 PM   #11
wahooj
Member
 
Join Date: Mar 2010
Posts: 30
Thanks: 0
Thanked 0 times in 0 posts
Default

Sry, my first post must have been a little confusing. I posted the data from the trade report there, but called it the Ledger.

It's assigning the exit name as Stop loss. I'm not sure why though because we can see from the output that a stop loss of 14.9 ticks was set after the order was executed as was a Profit Target of 21.99 ticks.
Something is changes those stops to only 5 ticks away because you'll notice the "Cancel pending exit order" is canceling the Profit Target at a price of 1097.75 which is not 21.99 ticks away. Here's the trade report again.

3 ES 06-10 Backtest MarketBiasBASE_Long_Short Short 2 1098 1098.25 6/15/2010 8:41:00 AM 6/15/2010 8:41:00 AM Sell Reversal Bias 1 Stop loss -25 1331 0 25 0 0 1
wahooj is offline  
Reply With Quote
Old 09-24-2010, 04:40 PM   #12
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

I see. It may help to print out the order details for the stop loss. The value of the variable is 14.999 but the following block may help you identify the actual value submitted with the order.

protectedoverridevoid OnOrderUpdate(IOrder order)
{
if (order.Name == "Stop loss")
Print(order.ToString());
}
NinjaTrader_RyanM is offline  
Reply With Quote
Old 09-24-2010, 05:23 PM   #13
wahooj
Member
 
Join Date: Mar 2010
Posts: 30
Thanks: 0
Thanked 0 times in 0 posts
Default

ah okay, i didn't know i could print order details like that. I'll try and post .
wahooj is offline  
Reply With Quote
Old 09-24-2010, 07:02 PM   #14
wahooj
Member
 
Join Date: Mar 2010
Posts: 30
Thanks: 0
Thanked 0 times in 0 posts
Default

Well, it doesn't give a value of ticks but it confirms the price of 1098.25 which would be a value of 5 ticks. Not sure why it's not using the value of the variable. I'll keep playing around with it and let you know.
Thanks.

Order='NT-00010/Backtest' Name='Stop loss' State=PendingSubmit Instrument='ES 06-10' Action=BuyToCover Limit price=0 Stop price=1098.25 Quantity=2 Strategy='MarketBiasBASE_Long_Short' Type=Stop Tif=Gtc Oco='NT-00005' Filled=0 Fill price=0 Token='b21815e9ab1e4377b23606cdb076b498' Gtd='12/1/2099 12:00:00 AM'
Order='NT-00010/Backtest' Name='Stop loss' State=Accepted Instrument='ES 06-10' Action=BuyToCover Limit price=0 Stop price=1098.25 Quantity=2 Strategy='MarketBiasBASE_Long_Short' Type=Stop Tif=Gtc Oco='NT-00005' Filled=0 Fill price=0 Token='b21815e9ab1e4377b23606cdb076b498' Gtd='12/1/2099 12:00:00 AM'
Order='NT-00010/Backtest' Name='Stop loss' State=Working Instrument='ES 06-10' Action=BuyToCover Limit price=0 Stop price=1098.25 Quantity=2 Strategy='MarketBiasBASE_Long_Short' Type=Stop Tif=Gtc Oco='NT-00005' Filled=0 Fill price=0 Token='b21815e9ab1e4377b23606cdb076b498' Gtd='12/1/2099 12:00:00 AM'
wahooj is offline  
Reply With Quote
Old 09-25-2010, 12:14 PM   #15
NinjaTrader_Austin
NinjaTrader Customer Service
 
NinjaTrader_Austin's Avatar
 
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 89 times in 81 posts
Default

wahooj, good to hear you're getting closer. Please keep playing around with it and let us know if you need specific assistance. As always, it is a great idea to print out everything that could be related to the issue at hand.

Brett's order update code is a nice start, but you can also print out the status of every single order update, like this:
Code:
protected override void OnOrderUpdate(IOrder order)
{
    Print(order.ToString());
}
NinjaTrader_Austin 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
EnterLong() order canceled rnhoo Automated Trading 1 09-04-2010 01:02 AM
Order PartFilled, then canceled at next bar zark.be Automated Trading 1 03-05-2010 10:51 AM
Pending order can't be canceled. mic.o8o Version 7 Beta General Questions & Bug Reports 1 12-21-2009 09:23 AM
Order Cancels itself immediately puppeye Automated Trading 1 03-27-2009 02:35 AM
If an order is rejected, does it need to be canceled? Bormir Strategy Development 4 03-09-2009 01:33 PM


All times are GMT -6. The time now is 11:18 PM.