Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

An Exit() method to submit an exit order has been ignored

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

    An Exit() method to submit an exit order has been ignored

    Hi there,

    I am just trying to do a simple strategy for entries with stop loss and take profit. It works well with historical data. However, I get this error in real time after few entries:


    Strategy 'TplRiskMBE/284109888': An Exit() method to submit an exit order at '7/01/2023 7:01:00 AM' has been ignored. Please search on the term 'Internal Order Handling Rules that Reduce Unwanted Positions' in the Help Guide for detailed explanation.
    Entry Price: 11144.25 SL Price: 11143 TP Price: 11146.5
    Exit Profit Long: SubmittedTime: 7/01/2023 7:00:32 AM
    Strategy 'TplRiskMBE/284109888': Error on calling 'OnExecutionUpdate' method on bar 5400: Object reference not set to an instance of an object.
    Strategy Terminated
    Disabling NinjaScript strategy 'TplRiskMBE/284109888'​


    I use OnExecutionUpdate to determine if the entry order, long or short was filled, then I proceed to adjust the SL and TP through the method below.


    private void SetSLTP(Execution execution)
    {

    var entryPrice = execution.Order.AverageFillPrice;
    _entrtPrice = entryPrice;

    if (_currentPosition == CurrentPos.Long)
    {
    _BEpriceTrigger = entryPrice + BeTrigger * TickSize;
    _BEprice = entryPrice + _BEticks * TickSize;
    _stop = entryPrice - _sl * TickSize;
    _profit = entryPrice + _tp * TickSize;
    _profitOrder = ExitLongLimit(0, true, _posSize, _profit, ProfitLong, LongPos);
    _stopOrder = ExitLongStopMarket(0, true, _posSize, _stop, StopLong, LongPos);
    Print("Entry Price: "+ entryPrice +" SL Price: "+_stop + " TP Price: "+_profit);
    Print("Exit Profit Long: " + _profitOrder.OrderState + "Time: " + _profitOrder.Time);
    Print("Exit SL Long: " + _stopOrder.OrderState + "Time: " + _stopOrder.Time);
    //ExitLong()
    }
    else if (_currentPosition == CurrentPos.Short)
    {
    _BEpriceTrigger = entryPrice - BeTrigger * TickSize;
    _BEprice = entryPrice - _BEticks * TickSize;
    _stop = entryPrice + _sl * TickSize;
    _profit = entryPrice - _tp * TickSize;
    _profitOrder = ExitShortLimit(0, true, _posSize, _profit, ProfitShort, ShortPos);
    _stopOrder = ExitShortStopMarket(0, true, _posSize, _stop, StopShort, ShortPos);
    Print("Entry Price: " + entryPrice + " SL Price: " + _stop + " TP Price: " + _profit);
    Print("Exit Profit Short: " + _profitOrder.OrderState + "Time: " + _profitOrder.Time);
    Print("Exit SL Short: " + _stopOrder.OrderState + "Time: " + _stopOrder.Time);

    }

    }


    I think it is not creating the _stopOrder. Initially it is doing it but it fails after few entries. Is it there a better way to do this?

    I appreciate your help.

    #2
    Hello, thanks for writing in. The strategy is breaking one of the order handling rules below:

    Methods that generate orders to exit a position will be ignored if:

    •A position is open and an order submitted by an enter method (EnterLongLimit() for example) is active and the order is used to open a position in the opposite direction

    •A position is open and an order submitted by a set method (SetStopLoss() for example) is active

    These rules are defined here:


    We have an existing example that attaches protetive orders in OCO that you can reference here if you would like to use this as a reference:

    Comment


      #3
      Thanks for your explanation Chris, I have read the rules documentation. I think the profit order is filled, then the entry order is not valid anymore, so it generates the error when trying to create the ExitStopMarket. I will try it in real time again in the next few days.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      56 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      133 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      73 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      45 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      49 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X