Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    Kate W.NinjaTrader Customer Service

    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.
        Kate W.NinjaTrader Customer Service

        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
            Brandon H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by judysamnt7, 03-13-2023, 09:11 AM
            4 responses
            59 views
            0 likes
            Last Post DynamicTest  
            Started by ScottWalsh, Yesterday, 06:52 PM
            4 responses
            36 views
            0 likes
            Last Post ScottWalsh  
            Started by olisav57, Yesterday, 07:39 PM
            0 responses
            7 views
            0 likes
            Last Post olisav57  
            Started by trilliantrader, Yesterday, 03:01 PM
            2 responses
            22 views
            0 likes
            Last Post helpwanted  
            Started by cre8able, Yesterday, 07:24 PM
            0 responses
            10 views
            0 likes
            Last Post cre8able  
            Working...
            X