Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unmanaged: Reversing positions

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

    Unmanaged: Reversing positions

    The typical way to do it is first with an order to exit the old position, Stops and then submitting the order for the new position with its stops. Due to market dynamics and following the logic of confirmations and filling orders, sometimes the queue of the bid-Ask could make you miss the opportunity to open the new position; so my question:

    - Does NT accept to open and reverse position, under unmanaged approach ONLY with OrderAction.Buy and OrderAction.Sell ?, I mean: if I could code it, will NT allow this without any error? I wouldn't care much not having a flat position until ExitOnClose

    - If I use just OrderAction.Buy and OrderAction.Sell, once the position has been exited and begins to open the new one, the Market.Position is updated immediately from its old status ? Within the OnExecution() method, I'd like to know the internal logic of NT handling the fills and updating Market.Position and Position.Quantity after fills

    Allow me explain with this sample:
    Code:
    protected override void OnExecution(IExecution execution)					
    {					
    	if (lEntryOrder != null && lEntryOrder == execution.Order)				
    	{				
    		if (lEntryOrder.OrderState == OrderState.Filled || lEntryOrder.OrderState == OrderState.PartFilled || (lEntryOrder.OrderState == OrderState.Cancelled && lEntryOrder.Filled > 0))			
    		{			
    			if (Position.MarketPosition == MarketPosition.Flat || Position.Quantity == 0 )		
    			{		
    				// Do your stuff if flat
                             }
                    }
              }
    }
    After lEntryOrder fills, there's a condition to know about actual Position and its quantity; imagine that with the last fill, the position really went Flat, so would that condition
    if (Position.MarketPosition == MarketPosition.Flat || Position.Quantity == 0 )
    be evaluated with the position and quantity already updated after the last fill ? I magine Yes, Of course, but I have some doubt cause in Log files the updating process takes some time


    Besides the answers, any ideas or suggestions for experience will be highly appreciated.
    Last edited by pstrusi; 12-22-2013, 08:02 AM.

    #2
    So far, testing reversing with ONLY buy and sell orders effectively reverse position without any error. However I'm looking forward for your answers, thus I could get better the Script procedures.

    Comment


      #3
      There is nothing in the unmanaged approach that would prevent you from reversing positions using the order actions you mentioned.

      The IPosition object should be updated immediately when the position changes, however how soon your strategy is aware of the position change ultimately depends on where you're checking for it.

      If you would like to immediately know when your position has changed, you should be checking for positions in OnPositionUpdate. This will give you a change in Quantity, or overall market position.

      MatthewNinjaTrader Product Management

      Comment


        #4
        I check the changes in Position.Market and Position.Quantity, immediately after a Filled, PartFilled or Cancelled with PartFilled has occurred. I imagine that this should be good enough. So far in the testings I have not had any problem about this.

        Thanks for the suggestion, I'll have in mind if necessary, perhaps in wild volatility markets.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by AHamxa, Today, 11:17 PM
        0 responses
        2 views
        0 likes
        Last Post AHamxa
        by AHamxa
         
        Started by Spiderbird, 07-27-2018, 07:52 PM
        12 responses
        9,240 views
        2 likes
        Last Post Mountain_cast  
        Started by chrischongpdx, Today, 09:39 PM
        0 responses
        7 views
        0 likes
        Last Post chrischongpdx  
        Started by Mountain_cast, Today, 12:41 PM
        2 responses
        10 views
        0 likes
        Last Post Mountain_cast  
        Started by dontpanic, 04-07-2015, 04:42 AM
        4 responses
        1,322 views
        0 likes
        Last Post BeachTrader11807  
        Working...
        X