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

Strategy execution delay

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

    Strategy execution delay

    I have a strategy that executes on bar close. Shortly after the cash open of the S&P around 9.43 EST a short signal was generated. There seemed to be a delay of around 10 bars before the strategy entered a short position (in simulation mode). Please see attached image where the signal detection is denoted by 'SP2 = 0.808 DIV MT7'. The image shows the approximate where entry should have occurred and where entry actually occurred leading to a losing simulation trade in this case.

    Im using explicit order management using the OnExecutionUpdate() event. There was a brief period of market volatility during this period. is there a way to minimize the impact of market volatility on the ability of a strategy to enter a position?
    ​​​​​​​ Click image for larger version

Name:	Strategy execution delay.png
Views:	182
Size:	23.4 KB
ID:	1164859

    #2
    Hello mballagan,

    Thanks for your question.

    There are random delays added to simulation orders to mimic slippage. It is possible that there was a delay in order states long enough to pass that many bars if we are looking at a volatile instrument. It appears that these are tick/range bars that depend on market movement and do not depend on time, so this may be what had happened.

    The Playback Connection does not incorporate these delays between order states. If you reproduce the trade in Playback and the entry occurs sooner than what you have seen using Sim, this would explain the case.

    Otherwise, I would suggest reproducing the occurrence with prints and TraceOrders enabled so you can see if the order was ignored due to an internal rule of the Managed Approach (where it would then be submitted later when conditions allowed) and to confirm the correct order method is reached when your entry signal becomes true.

    I also assume this is a market order, is that correct? We should note that if an order type other than a market order is used, the entry may be a few bars later. A Stop Limit order will also convert to a limit order once the stop price is reached, so this may be another possibility.

    For the thread's reference, I have included some helpful debugging information below.

    Debugging Tips - https://ninjatrader.com/support/help...script_cod.htm

    TraceOrders - https://ninjatrader.com/support/help...aceorders2.htm

    Playback Connection - https://ninjatrader.com/support/help...connection.htm

    Let us know if there is anything else we can do to help.
    JimNinjaTrader Customer Service

    Comment


      #3
      Jim,

      Thanks for your reply.

      I am using market orders for entry using EnterLong(), EnterShort() functions.


      The exit is done using the following code called from OnExecutionUpdate()

      private void SetStopProfit(Execution execution)
      {
      var entryPrice = execution.Order.AverageFillPrice;

      if (_currentPosition == CurrentPos.Long)
      {
      _stop = entryPrice - StopTicks * TickSize;
      _profit = entryPrice + ProfitTicks * TickSize;

      _profitOrder = ExitLongLimit(0, true, _posSize, _profit, ProfitLong, EnterLongName);
      _stopOrder = ExitLongStopMarket(0, true, _posSize, _stop, StopLong, EnterLongName);

      }
      else if (_currentPosition == CurrentPos.Short)
      {
      _stop = entryPrice + StopTicks * TickSize;
      _profit = entryPrice - ProfitTicks * TickSize;

      _profitOrder = ExitShortLimit(0, true, _posSize, _profit, ProfitShort, EnterShortName);
      _stopOrder = ExitShortStopMarket(0, true, _posSize, _stop, StopShort, EnterShortName);

      }


      }

      Comment


        #4
        Hello mballagan,

        Did you test this in Playback with Market Replay data to confirm if the delay was from the Sim account's random delays added to switching order states? You would not see the delay in Playback.

        As we are referring to market orders, it would either come down to delays on the Sim account, or that the condition to submit the market order did not become true until the later bar.
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by usazencort, Today, 01:16 AM
        0 responses
        1 view
        0 likes
        Last Post usazencort  
        Started by kaywai, 09-01-2023, 08:44 PM
        5 responses
        603 views
        0 likes
        Last Post NinjaTrader_Jason  
        Started by xiinteractive, 04-09-2024, 08:08 AM
        6 responses
        23 views
        0 likes
        Last Post xiinteractive  
        Started by Pattontje, Yesterday, 02:10 PM
        2 responses
        22 views
        0 likes
        Last Post Pattontje  
        Started by flybuzz, 04-21-2024, 04:07 PM
        17 responses
        230 views
        0 likes
        Last Post TradingLoss  
        Working...
        X