Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Adding a script into a strategy built in strategy builder

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

    Adding a script into a strategy built in strategy builder

    Hi ! Having this error when running my strategy live due to volatility: Sim101 Stop price can't be changed above market.

    I've read on another post that I can implement a script to keep my strategy running even if there's an error, I guess it would close my trade because on the error and then keep the strategy up and running for the next trade, here is the post with the script to bypass error: https://ninjatrader.com/support/help...orhandling.htm

    My question is where or how can I implement that script into my already built with the strategy builder strategy ?

    Thanks !

    #2
    Hello RebelRoby,

    Thank you for your post.

    The example script from the help guide page for RealTimeErrorHandling involves scripting inside of the OnOrderUpdate() method. This is not possible from the Strategy Builder; you would need to unlock your script in order to manually add the code to OnOrderUpdate() via the NinjaScript Editor.

    Please let us know if we may be of further assistance.

    Comment


      #3
      Hi ! Thanks for the quick answer !

      So even If I unlock the script there is no way to simply copy paste it at the right place in the script ?

      Comment


        #4
        Hello RebelRoby,

        Thank you for your reply.

        It would be possible to copy and paste the logic into the unlocked script; that is still considered a manual change in the NinjaScript Editor. I apologize if there was any confusion from my wording. What I would recommend to create a test script to unlock as well as keep your original script in the Strategy Builder is to create a copy with these steps:
        • Go to Control Center > New > Strategy Builder
        • In the Strategy dropdown menu, hover your mouse over the strategy you would like to copy
          • Select Save As and save the copy under a new name (you could add something like 'Unlocked' or 'Test' to the end of the name)
        • Click Next in the Strategy Builder, then Unlock Code > Yes
        • This will open your copied strategy in the NinjaScript Editor. You can now adjust the RealtimeErrorHandling in State.Configure and add the desired logic for OnOrderUpdate() in the unlocked copy of the script, then save it by pressing F5 or right-clicking and selecting Compile
        As noted in the help guide page for RealtimeErrorHandling, user defined rejection handling is advanced. The snippet of code from the help guide just leaves an example of how to trap a rejected order, but does not have logic that will close your position as you mentioned in your original post. Here is one portion of the block of code in the help guide example:

        if (order.OrderState == OrderState.Rejected)
        {
        // Stop loss order was rejected !!!!
        // Do something about it here
        }

        You would still have to write code for what to do when an order is rejected. My colleague has created an example that will print "Order rejected!" and then ExitLong to exit the open long position. His example may be found here:

        Is there a way to solve the problem of stop order rejection in NT8? This can be done in RTrader Pro with a market if order rejected option. I want to do something similar in ninja trader


        Depending on your strategy, you may have a long or a short position and should adjust the logic for what to do if an order is rejected accordingly.

        Please let us know if we may be of further assistance.

        Comment


          #5
          Great ! thanks for all the information !

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          54 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          130 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          72 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          44 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