Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Execution while the market is closed

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

    Execution while the market is closed

    Hi,
    I'm trying a pretty simple strategy, with these setups. The strategy is designed to leave positions open until they reach the profit target/stoploss, without exiting at session close. This means that trades can be closed while the market is open. NQ has "a daily maintenance period from 5:00 p.m. - 6:00 p.m. ET (4:00 p.m. - 5:00 p.m. CT)" so no market orders can be traded during that time, and limit orders can´t get a fill. I'm not sure if limit orders can be entered at that time, and perhaps NT is taking the best ask/best bid price, and closing the trade for that reason.

    I am attaching screenshots with the executed prices on a sim account, so you can see that it is not in the traded price range on the chart, either time (5:54 both trades, EST time). This is not expected behavior on a real account.

    Thank you.​


    Calculate = Calculate.OnBarClose;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = false;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.ImmediatelySubmitSynchronizeAccount;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = false;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 12000;​

    --------------------

    if ( ((EMA1[0] > EMA2[0])
    && (Close[0]>smaSlow[0])
    && ((ToTime(Times[0][0]) >= StopTime && ToTime(Times[0][0]) <= StartTime) == false)
    && ((ToTime(Times[0][0]) >= StopTime2 && ToTime(Times[0][0]) <= StartTime2) == false)
    && Position.MarketPosition == MarketPosition.Flat
    (some other logic here with the emas)


    )
    {

    SetStopLoss(@"LE_", CalculationMode.Price, Close[0] - (Stop * TickSize), false);
    SetProfitTarget("LE_", CalculationMode.Price, Close[0] + (Limit * TickSize));
    EnterLong(Convert.ToInt32(LotsSize), @"LE_");

    }
    Attached Files

    #2
    Hello rocker84,

    Thank you for your post.

    To understand why the script is behaving as it is, such as placing orders or not placing orders when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

    In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar.

    This will print to the output window. Backtest the script and when the output from the output window appears save this by right-clicking the output window and selecting Save As... -> give the output file a name and save -> then attach the output text file to your reply.

    Output from prints will appear in the NinjaScript Output window.
    NT8: New -> NinjaScript Output

    The prints should include the time of the bar and should print all values from all variables and all hard coded values in all conditions that must evaluate as true for this action to be triggered. It is very helpful to include labels and operators in the print to understand what is being compared in the condition sets.

    Below I am providing a link to videos that demonstrate adding prints to a script to get further information about the behavior of the script.
    NT8 —



    If you are using the Strategy Builder in NinjaTrader 8, you can also build prints in the Actions window under Misc -> Print.
    NT8 Strategy Builder —



    It is also helpful to set TraceOrders to true in State.Configure as well as print the order object in OnOrderUpdate().
    TraceOrders will output to the NinjaScript Output window a message when orders are being submitted, ignored, cancelled, or rejected.
    Printing the order object in OnOrderUpdate() will allow you to track the progression of the order from submitted, to working, to filled, cancelled, or rejected.
    These tools will let you know what happens to the order.
    TraceOrders - https://ninjatrader.com/support/help...raceorders.htm
    OnOrderUpdate() - https://ninjatrader.com/support/help...rderupdate.htm

    I'm also including a link to a forum post with further suggestions on debugging a script.


    Save the output from the output window to a text file. Let me know if you need assistance creating a print or enabling TraceOrders.

    I am happy to assist with analyzing the output from prints and TraceOrders.​

    Comment


      #3
      Originally posted by NinjaTrader_Gaby View Post
      Hello rocker84,

      Thank you for your post.

      To understand why the script is behaving as it is, such as placing orders or not placing orders when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

      In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar.

      This will print to the output window. Backtest the script and when the output from the output window appears save this by right-clicking the output window and selecting Save As... -> give the output file a name and save -> then attach the output text file to your reply.

      Output from prints will appear in the NinjaScript Output window.
      NT8: New -> NinjaScript Output

      The prints should include the time of the bar and should print all values from all variables and all hard coded values in all conditions that must evaluate as true for this action to be triggered. It is very helpful to include labels and operators in the print to understand what is being compared in the condition sets.

      Below I am providing a link to videos that demonstrate adding prints to a script to get further information about the behavior of the script.
      NT8 —



      If you are using the Strategy Builder in NinjaTrader 8, you can also build prints in the Actions window under Misc -> Print.
      NT8 Strategy Builder —



      It is also helpful to set TraceOrders to true in State.Configure as well as print the order object in OnOrderUpdate().
      TraceOrders will output to the NinjaScript Output window a message when orders are being submitted, ignored, cancelled, or rejected.
      Printing the order object in OnOrderUpdate() will allow you to track the progression of the order from submitted, to working, to filled, cancelled, or rejected.
      These tools will let you know what happens to the order.
      TraceOrders - https://ninjatrader.com/support/help...raceorders.htm
      OnOrderUpdate() - https://ninjatrader.com/support/help...rderupdate.htm

      I'm also including a link to a forum post with further suggestions on debugging a script.


      Save the output from the output window to a text file. Let me know if you need assistance creating a print or enabling TraceOrders.

      I am happy to assist with analyzing the output from prints and TraceOrders.​
      Hello Gaby, the strategy is as simple as can be. It sets a profit target and does not change it at all. There are two days that it did it at the same time stamp, but there are days that it didn't. I suspect it must be a problem with the "live" connection, which is already known to have quite a few problems. Now I am doing it with CQG connection. Thank you.

      P.S. I responded on Thu, Jun 13 to the Case: #04458865 email but I think the email did not arrive.​

      Comment


        #4
        Hello,

        I am not aware of any issues with live connections at this time. It would be necessary to debug the script in order to clearly see the why the script is behaving this way. If there are any bugs it would be clearly illustrated by the output.

        I am not seeing any replies to the case number you have referenced as well, please re-send your response if you would like to continue with that inquiry.

        Comment


          #5
          Originally posted by NinjaTrader_Gaby View Post
          Hello,

          I am not aware of any issues with live connections at this time. It would be necessary to debug the script in order to clearly see the why the script is behaving this way. If there are any bugs it would be clearly illustrated by the output.

          I am not seeing any replies to the case number you have referenced as well, please re-send your response if you would like to continue with that inquiry.
          Hello Gaby, I was able to replicate the error by entering a long manually just before EOD, in a sim account on MNQ, with very tight profit target and stoploss. As you can see the order is executed off price and when the market is closed 2/4/2025 5:52 EST (closed from 5 to 6pm).
          Attached Files

          Comment


            #6
            NinjaTrader_Gaby

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            85 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            47 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            29 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            32 views
            0 likes
            Last Post TheRealMorford  
            Started by Mindset, 02-28-2026, 06:16 AM
            0 responses
            67 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Working...
            X