Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unmanaged Stop and Profit Target Orders Sometimes Not Created in Sim

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

    Unmanaged Stop and Profit Target Orders Sometimes Not Created in Sim

    The market orders, stop order and profit targets are placed on the chart fine in playback, but in realtime sim the market orders are always placed, but the stop and profit target orders sometimes (two to six times a day) don't appear on the chart and are not in trace orders. I run it on a 1 minute chart, which has an added 3 min dataseries for a Keltner indicator. The entries that misbehave are using BarsInProgress == 0.
    What might cause this to happen in realtime sim and not in playback?

    A search of the NinjaScript help suggests using OnOrderUpdate for assigning StopLoss orders:
    " // Assign stopLossOrder in OnOrderUpdate() to ensure the assignment occurs when expected.
    // This is more reliable than assigning Order objects in OnBarUpdate,
    // as the assignment is not guaranteed to be complete if it is referenced immediately after submitting"

    https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?realtimeerrorhandlin g.htm
    Last edited by BruceK; 08-04-2023, 03:14 PM.

    #2
    Hello BruceK,

    Thank you for your post.

    For running the strategy in realtime I suggest adding print statements to print all values used in the conditions for the stops and targets both outside of and inside of the condition. This can help to understand if the condition was met or not. For more details about using prints to debug your script:


    Otherwise, you could certainly consider using OnOrderUpdate() and OnExecutionUpdate() to submit your stop and target orders. There is a reference sample demonstrating this concept here:


    Please let us know if we may be of further assistance.

    Comment


      #3
      Emily, thank you for your reply. I have Print statements in the sections of code that are reached and not reached when the sim stop orders are not issued. The stop and target orders are being submitted in OnExecutionUpdate.

      8/8/23: I found the solution and note it below. Just keeping this question posted in case anyone else runs into this issue.

      Though I still don't know why sim has issues not exhibited in Market Replay, by using Print statements, I did find that each time the stop and profit targets were not executed ex.Order.Name was not matching the EnterLongName or EnterShortName. I solved this by adding a line in the OnExecutionUpdate that sets ex.OrderName to the appropriate EnterLongName or EnterShortName.
      Both normal and truncated order sequences reach the private void SetStopLossTicks, which I check by printing to the Output window:
      private void SetStopLossTicks(Execution ex)
      {
      if (PrintDebug) Print("..... reached first line of SetStopLossTicks, ex.Order.Name = " + ex.Order.Name + ", EnterLongName = " + EnterLongName + ", EnterShortName = " + EnterShortName);
      var size = StopLossValueTicks * TickSize;


      if (ex.Order.Name == EnterLongName)
      {
      _stop = ex.Order.AverageFillPrice - size;


      SetStopOrders(true, ExitLongStopName);
      if (PrintDebug) Print("..... SetStopLossTicks after SetStopOrders, " + "ExitLongStopName = " + ExitLongStopName + ", _stop = " + _stop);
      }
      else if (ex.Order.Name == EnterShortName)
      {
      _stop = ex.Order.AverageFillPrice + size;


      SetStopOrders(false, ExitShortStopName);
      if (PrintDebug) Print("..... SetStopLossTicks after SetStopOrders, " + "ExitShortStopName = " + ExitShortStopName + ", _stop = " + _stop);
      }
      }

      Comment


        #4
        Hello BruceK,

        Thank you for your reply.

        Are you using order signals as well as tracking order objects with OnOrderUpdate() and OnExecutionUpdate()? The ex.Order.Name would be set to the entry or exit signal name in your order method. Additionally, it is important to remember to call GetRealtimeOrder() to update historical order references to live as needed:These concepts are fully demonstrated in the SampleOnOrderUpdate strategy reference sample that is posted in the help guide here:
        Please let us know if we may be of further assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        50 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        126 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        69 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        42 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        46 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X