Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to debug this problem

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

    How to debug this problem

    I've been developing a managed strategy and am encountering an odd problem. It amounts to a long stop order being executed to get into a trade and then followed by placing a trailing stop in OnExecutionUpdate. I have Print statements in OnBarUpdate, OnOrderUpdate and OnExecutionUpdate to track all activity. Everything progresses well until the ExitLongStopMarket is executed and then nothing else happens until session close. Nothing enters into OnOrderUpdate after executing ExitLongStopMarket, which is very confusing. Here's a snippet of the print statements:

    **** 12/11/2022 4:43:00 PM OnBarUpdate() - EnterShortStopMarket at 1.224
    ++++ 12/11/2022 4:43:00 PM OnOrderUpdate() - EnterShortStopMarket accepted at 1.224
    ---- 12/11/2022 4:44:00 PM OnOrderUpdate() - EnterShortStopMarket cancelled.
    **** 12/11/2022 4:46:00 PM OnBarUpdate() - EnterLongStopMarket at 1.22446
    ++++ 12/11/2022 4:46:00 PM OnOrderUpdate() - EnterLongStopMarket accepted at 1.22446
    ++++ 12/11/2022 4:46:00 PM OnOrderUpdate() - EnterLongStopMarket filled at 1.22446
    ++++ 12/11/2022 4:46:00 PM OnExecutionUpdate() - ExitLongStopMarket at 1.22429882352941 for 1000 numLots
    **** 12/12/2022 2:30:00 PM OnOrderUpdate() - Exit on session close Submitted
    **** 12/12/2022 2:30:00 PM OnOrderUpdate() - Exit on session close Accepted
    **** 12/12/2022 2:30:00 PM OnOrderUpdate() - Exit on session close Working
    **** 12/12/2022 2:30:00 PM OnOrderUpdate() - Exit on session close Filled

    ​The value of the stopPrice is perfectly outside the data range and not too close. Here's how the exit statement is written:

    ExitLongStopMarket(BarsInProgress, false, execution.Order.Quantity, stopPrice, exitLongStopName, enterLongOrderName);​

    I've also performed it without the BIP and GTC arguments and that makes no difference.

    I'm baffled how to debug this since the program never enters OnOrderUpdate or OnExecutionUpdate thereafter except when the session closes. Why nothing appears in OnOrderUpdate after the ExitLongStopMarket is executed is most baffling. My previous strategy developments always did. I've used both Print statements and the debugger within Visual Studio with breaks set in those methods. Any suggestion on how I might debug this?

    #2
    Hi dweems, thanks for writing in. We have a full example that exemplifies advanced order management. Please make sure your code follows this pattern closely:



    Kind regards,
    -ChrisL
    Last edited by NinjaTrader_ChrisL; 12-16-2022, 01:43 PM.

    Comment


      #3
      I made some minor changes to reflect what you have in the example. I note that even though ExitLongStopMarket does not return a value according to the language reference, your code expects a return value referencing an order. So I added that but I notice that the value returned is null. Should it? If not, what can I do to determine why it is null?

      Comment


        #4
        Hi dweems, thanks for the follow up. The order method ExitLongStopMarket should not return null. The method reference describes the return value:

        Code:
        Method Return Value
        An Order read-only object that represents the order.​


        The exit orders are set up in OnExecutionUpdate, when the entry order fills. You should not be seeing this return null from the example linked above.

        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