Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Real time stoploss not working....

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

    #16
    Hello,

    It is not clear just from looking at the code what is going on. You would need to do more detailed debugging, regardless of the length of code of the script. That is the only way to have clarity on the logic of the script.

    Some things to note are:
    • You are submitting exit orders in your custom method with the variable exitContractAmount as the quantity. It is not clear from the logic of the script how that variable is calculated. You should do further debugging related to the logic that goes into calculating this variable for further clarity.
    • You are also submitting some exit orders with just a different variable simply called 'quantity' taken from your custom method. You would need to do further debugging to determine what the quantity actually being supplied to the exit order is.
    • In OnOrderUpdate, you are also submitting exit orders with the 'quantity' parameter taken from OnOrderUpdate. If you want the exit order to use the actual current quantity of the order, use order.Quantity instead.
    Please note it is not within our support model to debug the script on your behalf. Unfortunately, in the support department at NinjaTrader it is against our policy to create, debug, or modify, code or logic for our clients. Further, we do not provide C# programming education services or one on one educational support in our NinjaScript Support department. This is so that we can maintain a high level of service for all of our clients as well as our associates. We are also not able to correct scripts created by an AI, as these generally cannot create valid NinjaScript.

    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.​

    Comment


      #17
      Hey NinjaTrader_Gaby,

      I guess you understand me wrong. I am trying to explain that there is a bug in timing on ninjatrades side...
      I do not want you to debug anything.

      1) I am using the quantity variable provided by the onOrderUpdate of the filled order.
      2) This method provided by Ninjatrader. So the provided quantity parameter is from your backend logic. The order quantity also matched this number.
      3) This code is not generated with AI, so I am unsure where that statement comes from.
      4) All this logic works if I would run it 1 bar later than the order fill. So outside the event method...

      I am saying the timing of fully filled MIT orders and placing a stoploss through the event, has a wrong timing on the Position.Quantity....

      If you would
      1) create a test project
      2) create a limit MIT order
      3) try to set the stoploss through the event onOrderUpdate when it is filled

      Then you will see that the stoploss will not be equal to the order...

      I assume that the event chain for order update happens before Position.Quantity is updated for the exitShort/LongsStopMarket() method.

      I debugged this already really in depth, but I can not look into the backend of Ninjatrader.
      So I suggest this actually gets taken seriously...

      P.S. If I would Async a task that executes a few seconds later, that would also solve it. Actually confirming my premise about the Position.Quanity update in OnOrderUpdate is lacking behind in the event chain with MIT filled orders.

      P.P.S. your comments about education etc are pretty disrespectful when I first told you I have over a 1,5 decade in c# and programming experience.

      P.P.P.S I think I thought the issue here: https://developer.ninjatrader.com/do.../onorderupdate
      Click image for larger version  Name:	image.png Views:	0 Size:	36.1 KB ID:	1340144
      Hence my premise was correct, but I was using the wrong event handling it looks like. Instead of being disrespectful next time about my programming experience it would be helpfull to link to the potential usefull things like this ...​ Literally my premise below...

      Click image for larger version

Name:	image.png
Views:	49
Size:	46.9 KB
ID:	1340146
      Last edited by mw_futures; 04-09-2025, 02:56 PM.

      Comment


        #18
        Moving everything to OnExecutionUpdate() fixed it...

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        116 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        61 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        40 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        44 views
        0 likes
        Last Post TheRealMorford  
        Started by Mindset, 02-28-2026, 06:16 AM
        0 responses
        82 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X