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

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 love2code2trade, 04-17-2024, 01:45 PM
        4 responses
        36 views
        0 likes
        Last Post love2code2trade  
        Started by alifarahani, Today, 09:40 AM
        2 responses
        13 views
        0 likes
        Last Post alifarahani  
        Started by junkone, Today, 11:37 AM
        3 responses
        15 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by pickmyonlineclass, Today, 12:23 PM
        0 responses
        1 view
        0 likes
        Last Post pickmyonlineclass  
        Started by frankthearm, Yesterday, 09:08 AM
        12 responses
        44 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Working...
        X