Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

NT7 Advanced Order Management

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

    NT7 Advanced Order Management

    Hello,

    I've added a couple print statements to my Unmanaged strat so I can see what's going on "under the hood"...
    Code:
    protected override void OnOrderUpdate(IOrder o)
    		{
    			zoneCounter++;
    			if (1==1){
    				Print("******************* OnOrderUpdate");	
    				Print("******************* OnPosition: "+Position.MarketPosition.ToString());	
    				Print("******************* zoneCounter: "+zoneCounter.ToString());
    			
    			}
    ...
    and
    Code:
    protected override void OnExecution(IExecution e)
    		{
    			if (1==1){
    				Print("******************* OnExecution");	
    				Print("******************* OnPosition: "+Position.MarketPosition.ToString());	
    				Print("******************* zoneCounter: "+zoneCounter.ToString());
    			
    			}
    			zoneCounter = 0;
    ...
    The results are similar to the following using:
    Code:
    CalculateOnBarClose = true;
    			Unmanaged = true;
    			TraceOrders				= true;
    11/4/2016 07:41:48 Entered internal SubmitOrder() method at 11/4/2016 07:41:48: Action=SellShort OrderType=Limit Quantity=1 Lim
    itPrice=44.65 StopPrice=0 OcoId='' Name='SE'
    ******************* OnOrderUpdate
    ******************* OnPosition: Flat
    ******************* zoneCounter: 1
    v03 Short OnOrderUpdate
    ******************* OnOrderUpdate
    ******************* OnPosition: Flat
    ******************* zoneCounter: 2
    v03 Short OnOrderUpdate
    ******************* OnOrderUpdate
    ******************* OnPosition: Flat
    ******************* zoneCounter: 3
    v03 Short OnOrderUpdate
    ******************* OnOrderUpdate
    ******************* OnPosition: Short
    ******************* zoneCounter: 4
    v03 Short OnOrderUpdate
    ******************* OnExecution
    ******************* OnPosition: Short
    ******************* zoneCounter: 4
    11/4/2016 07:43:15 Entered internal SubmitOrder() method at 11/4/2016 07:43:15: Action=BuyToCover OrderType=Stop Quantity=1 L
    imitPrice=0 StopPrice=44.80 OcoId='' Name='SS'
    11/4/2016 07:43:15 Entered internal SubmitOrder() method at 11/4/2016 07:43:15: Action=BuyToCover OrderType=Limit Quantity=1 L
    imitPrice=44.50 StopPrice=0 OcoId='' Name='ST'
    ******************* OnOrderUpdate
    ******************* OnPosition: Short
    ******************* zoneCounter: 1
    Stop Short OnOrderUpdate
    ******************* OnOrderUpdate
    ******************* OnPosition: Short
    ******************* zoneCounter: 2
    Target Short OnOrderUpdate
    ******************* OnOrderUpdate
    ******************* OnPosition: Short
    ******************* zoneCounter: 3
    Stop Short OnOrderUpdate
    ******************* OnOrderUpdate
    ******************* OnPosition: Short
    ******************* zoneCounter: 4
    Target Short OnOrderUpdate
    ******************* OnOrderUpdate
    ******************* OnPosition: Short
    ******************* zoneCounter: 5
    Target Short OnOrderUpdate

    Can you explain why it appears to run through OnOrderUpdate 4 times and remaining flat before the switch to OnExecution? Then, when it gets to OnExecution to place stop and target, why does it have two runs for the stop and two+ for the target?
    Last edited by zeller4; 11-04-2016, 09:20 AM.

    #2
    Hello zeller4, and thank you for your question.

    An exchange with the orders desk involves several stages, and thus, several messages passed back and forth between NinjaTrader and the orders desk. Each time one of these messages is sent or received, OnOrderUpdate is called.

    The phases an order goes through are documented in the "OrderState Values" section here,



    You can print o.OrderState and e.Order.OrderState to see this conversation in action.

    Please let us know if there are any other ways we can help.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by zeller4 View Post
      Can you explain why it appears to run through OnOrderUpdate 4 times and remaining flat before the switch to OnExecution? Then, when it gets to OnExecution to place stop and target, why does it have two runs for the stop and two+ for the target?
      You'd learn a lot more if you use these Print() statements combined with the ToString() methods,

      Code:
      protected override void OnOrderUpdate(IOrder order)
      {
          Print("OnOrderUpdate: " + order.ToString());
          ... rest of code ...
      }
      
      protected override void OnExecution(IExecution execution)
      {
          Print("OnExecution: " + execution.ToString());
          ... rest of code ...
      }
      
      protected override void OnPositionUpdate(IPosition position)
      {
          Print("OnPositionUpdate: " + position.ToString());
          ... rest of code ...
      }

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by traderqz, Today, 12:06 AM
      3 responses
      6 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by RideMe, 04-07-2024, 04:54 PM
      5 responses
      28 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by f.saeidi, Today, 08:13 AM
      1 response
      8 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by DavidHP, Today, 07:56 AM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_Erick  
      Started by kujista, Today, 06:23 AM
      3 responses
      11 views
      0 likes
      Last Post kujista
      by kujista
       
      Working...
      X