Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Issue with OnBarUpdate and OnExecution being out of sync

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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?

    #2
    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?
    MatthewNinjaTrader Product Management

    Comment


      #3
      Matthew,

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

      Mark

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      635 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      365 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      106 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      567 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      571 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X