Stop and Profit Target orders sometimes not created in sim
02.08.2023 05.12

Creating Flexible Strategy Architecture in NinjaTrader 8

NinjaCoding friend

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

Using the Architecture framework with my own entry signals. 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 (3 or more 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?

Though I still don't know why sim has issues, 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);

            }

        }


  • David Eaton
    20.08.2023 02:21

    Hi,

    I just went through your code and noticed it adds print statements to the existing code.

    I noticed that you identified the problem and found a solution.

    "I solved this by adding a line in the OnExecutionUpdate that sets ex.OrderName"


    Would you care to post the solution?


    Thanks in advance.