Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Transition Into State.Realtime Cause Order Resubmission

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

    Transition Into State.Realtime Cause Order Resubmission

    Context: I am building a simple EMA crossover strategy and try to test how nt8 works. My strategy is simple: If the close price of the candle close above the 21 EMA, I go long, set takeprofit and stoploss 50 ticks away from the current price; If then the close price of the candle close below the 21 EMA, I then close out my long with market order and go short, set takeprofit and stoploss 50 ticks away from the current price.

    The problem: when the strategy ran through all the historical data and start shifting into the real time phase, it resubmit an order I didn't have a chance to cancel from the historical data. (Which they couldn't be cancel anyway since I used GetRealtimeOrder() function and there wasn't a realtime position, so I assume that will return null and CancelOrder(null) will not do anything)

    If you run the code I provided in playback mode, it had 2 oco orders after the strategy got transition into the Realtime phase, which there should be only 1. (if you look at the output panel or the pic1 I attached, nt8 automatically resubmit an oco bracket that should not be there or should be cancelled already)

    Thank you for your helps, It stuck me days already
    Attached Files
    Last edited by Curerious; 10-30-2024, 12:42 PM.

    #2
    Hello Curerious,

    To assist we need debugging output from prints and TraceOrders.

    Below is a link to a support article on adding debugging prints to understand behavior.



    "Which they couldn't be cancel anyway since I used GetRealtimeOrder() function and there wasn't a realtime position"

    This doesn't make sense. If an entry order has not filled and is still working and has transitioned to real-time, it can be cancelled.

    "so I assume that will return null and CancelOrder(null) will not do anything"

    If the order was submitted in historical, did not fill, and is still working when the script transitions to real-time, it will not be null.

    You can add prints to confirm if the order is null and the <order>.OrderState.

    "If you run the code I provided in playback mode, it had 2 oco orders after the strategy got transition into the Realtime phase, which there should be only 1."

    You should run the script and provide the debugging print output showing the issue.

    If you do not want to debug the script yourself, you can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.





    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Sorry Chelsea B, this is my first time posting so please excuse my lack of understanding about the procedure.

      The actual problem happened because I put the OCO order within the OnOrderUpdate() function, where if my entry order got filled I then submit an OCO , this action creates a problem when nt8 is transitioning into live position, where the OCO order will submit twice, once within the strategy position and once when it got into the live position. Is not that I didn't do debugging, is that I do not understand why this OCO will be submitting twice during the transition (even though I used StartBehavior.WaitUntilFlat), I do not have the underlying source code of what nt8 will do when it start the transition from strategy position into live position, so that I could not be debugging it.

      After I put the OCO order within the OnExecutionUpdate() function, the problem solved. Still, thank you for taking time to respond.
      Last edited by Curerious; 10-30-2024, 07:15 PM.

      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
      132 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