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 Mindset, 04-21-2026, 06:46 AM
            0 responses
            88 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by M4ndoo, 04-20-2026, 05:21 PM
            0 responses
            134 views
            0 likes
            Last Post M4ndoo
            by M4ndoo
             
            Started by M4ndoo, 04-19-2026, 05:54 PM
            0 responses
            68 views
            0 likes
            Last Post M4ndoo
            by M4ndoo
             
            Started by cmoran13, 04-16-2026, 01:02 PM
            0 responses
            119 views
            0 likes
            Last Post cmoran13  
            Started by PaulMohn, 04-10-2026, 11:11 AM
            0 responses
            67 views
            0 likes
            Last Post PaulMohn  
            Working...
            X