Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to Make a NinjaScript Strategy Disable Itself?

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

    How to Make a NinjaScript Strategy Disable Itself?

    I'm coding a NinjaScript strategy in NT8, and I'm looking for a way that the strategy can use to disable itself. Per the NT8 Help Guide the CloseStrategy procedure does three things, as follows: (1) it cancels all working orders, (2) it closes existing positions, and (3) it disables the strategy. I'd like my strategy to do just 1 & 3, or 3 only. Do I need to override CloseStrategy to accomplish this, or is there some other approach that I could use? If I'll need to override CloseStrategy, then what NinjaScript code fragment would I use to accomplish part 3 (that is, to disable the strategy)?

    Thank you very much in advance for any guidance you might provide.

    #2
    Hello NtFan,

    Thank you for your post.

    Yes, you would need to override Close Strategy to accomplish this and would not want to call the default close action at all, since that's the bit that cancels working orders and closes existing positions. You could do something like the below, replacing // custom close logic with your own logic to simply cancel the working orders. Once that's done then you can call CloseStrategy from OnBarUpdate and your custom logic will execute before the strategy disables.

    public override void CloseStrategy(string signalName)
    {
    Print("Executing Custom Close Logic");
    // custom close logic


    }

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

    Comment


      #3
      Is it possible to execute a stop on the strategy based on current P/L for that strategy? For example if P/L is more than -$40 stop running

      Comment


        #4
        Hello authenticx,

        Thank you for your reply.

        Here's two examples from the help guide of how you can control your strategy taking trades based on your PNL:





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

        Comment


          #5
          I understand the part where we need to override the method but do you have any hints how to disable the strategy (Part 3 of the original question)?
          I don't find anything in the reference guide.

          Thanks!

          Comment


            #6
            Hello davidfrechette,

            Thanks for your notes.

            CloseStrategy() could be used to cancel all working orders, close any existing positions, and finally disable the strategy as noted by NinjaTrader_Kate in post # 2.

            See this help guide page for more information about CloseStrategy() and sample code: https://ninjatrader.com/support/help...sestrategy.htm
            <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Today, 05:17 AM
            0 responses
            52 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
            70 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