NinjaTrader Support Forum  

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 10-18-2011, 03:12 PM   #1
hamburglergt
Junior Member
 
Join Date: Sep 2011
Posts: 20
Thanks: 0
Thanked 0 times in 0 posts
Default Issue with OnBarUpdate and OnExecution being out of sync

In my strategy, after an order has been filled, I place a trailing stop order than I want to manage the price of synthetically. So in my OnExecution I have the following code (after some amount of checking)

Code:
IOrder trailStop = SubmitOrder(0, OrderAction.Sell, OrderType.Stop, execution.Order.Quantity, 0, epv.fillPrice, "", this.LONG_BUY_TRAIL_TAG + epv.entryno);
						trailStopOrders.Add(trailStop);
I then check in the OnBarUpdate to see if the price action has triggered my application to want to move the trailing stop price. here is the relevant code from OnBarUpdate:

Code:
for(int i = 0; i < trailStopOrders.Count; i++)
			{
				
				IOrder order = (IOrder)trailStopOrders[i];
				EntryPatternValues epv = null;
				orderMap.TryGetValue(order.OrderId, out epv);
				if((order.OrderAction == OrderAction.Sell) && (epv != null))
				{
						
						if(High[0] > (epv.farPrice + (Math.Abs(epv.a - epv.farPrice) * .5)))
						{
							
							ChangeOrder(order, order.Quantity, 0, (epv.farPrice + (Math.Abs(epv.a - epv.farPrice) * .382)));
						}
					
				}
			}
It seems however, whenever I run this, (I also have debugged in visual studio), that Right after the order is placed from the OnExecution method (which also adds the order to the arraylist I am using) that the next time OnBarUpdate gets called and has values in my "trailStopOrders" is almost 1000 bars later according to CurrentBar. Am I approaching this incorrectly or oversighting on something?
hamburglergt is offline  
Reply With Quote
Old 10-18-2011, 04:02 PM   #2
NinjaTrader_Matthew
NinjaTrader Customer Service
 
NinjaTrader_Matthew's Avatar
 
Join Date: Apr 2010
Location: Denver, CO, USA
Posts: 4,858
Thanks: 162
Thanked 579 times in 570 posts
Default

Hello,

I do not see any issues with the snippet you have provided. Is it that OnBarUpdate is not being called until 1000 bars later, is it is just this single condition that isn't true until later?

Do you have this snippet in any other statements that might be preventing it from calling with each incoming tick? For example, do are you using a Time Filter to limit trading times?
NinjaTrader_Matthew is offline  
Reply With Quote
Old 10-19-2011, 09:12 AM   #3
hamburglergt
Junior Member
 
Join Date: Sep 2011
Posts: 20
Thanks: 0
Thanked 0 times in 0 posts
Default

Matthew,

I solved the issue, it was a matter of another thread modifying the arraylist. Thanks for your help!

Mark
hamburglergt 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
OnExecution neb1998 Strategy Development 6 01-28-2011 01:50 PM
NT7B6 Indicators: Non-displayed daily bars - yesterday's OnBarUpdate is out of sync kdoren Version 7 Beta General Questions & Bug Reports 2 01-18-2010 09:00 AM
OnBarUpdate Vs. OnExecution binwang2 Strategy Development 1 12-01-2009 10:24 AM
Variable transfer/access between OnBarUpdate and OnExecution noincomenojobnoassets Strategy Development 9 09-23-2009 03:36 AM
OnExecution Mike Winfrey Strategy Development 2 12-14-2008 06:59 AM


All times are GMT -6. The time now is 05:24 AM.