Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Set Input Parameter Upon Termination

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

    Set Input Parameter Upon Termination

    Hi,

    Does anyone know how to set an Input Value when a strategy terminates. I have been trying to set an input variable within OnTermination() without any success. In essence, I would like to use the parameter dialog box to manually set an input variable. But then when the strategy is run and then the strategy terminates, I would like to set the input variable to a certain value progammatically.

    Any help would be greatly appreciated.

    #2
    Hi maltese,

    Thank you for your post.

    I am uncertain what you are trying to do.

    If you are adding code to the OnTermination() this will run when the script is disabled. At that point no input values will be used.

    If you want to set an input value, this must be done with a public variable and can be set in Initialize() which is run before the script begins running.

    Can you clarify what you are trying to achieve? If the script is disabled, the script stops running and no further code is executed after OnTermination. What input are you trying to set?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hi maltese,

      Thank you for your post.

      I am uncertain what you are trying to do.

      If you are adding code to the OnTermination() this will run when the script is disabled. At that point no input values will be used.

      If you want to set an input value, this must be done with a public variable and can be set in Initialize() which is run before the script begins running.

      Can you clarify what you are trying to achieve? If the script is disabled, the script stops running and no further code is executed after OnTermination. What input are you trying to set?
      Hi Chelsea and thank you for your response.

      As an example, I have an input variable that defaults to a value of 0. I would like to be able to manually set this variable to let's say 10 using the parameter dialog box.

      Then when I run the strategy, the code would perform it's logic based on the input variable's value of 10.

      However, when the strategy is terminated (i.e., stop hit, target hit, manually turned off), I would like to automatically reset the input variable back to 0 and have the value of 0 be reflected in the parameter dialog box instead of the value of 10. I hope that makes sense.


      Regards

      Comment


        #4
        Hello maltese,

        If you want to set the default value to 0, do this when you create the public variable and private variable, similar to how the Fast and Slow public variables in the SampleMACrossOver strategy are used.

        The default values can be overwritten manually after a script is added but before it is enabled.

        Take a look at the SampleMACrossOver. (Tools -> Edit NinjaScript -> Strategy... -> SampleMACrossOver -> OK)

        I also recommend you watch the video on strategy creation to see how setting defaults works.
        https://www.youtube.com/watch?v=Maaq...56536A44DD7105
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by maltese View Post
          Hi Chelsea and thank you for your response.

          As an example, I have an input variable that defaults to a value of 0. I would like to be able to manually set this variable to let's say 10 using the parameter dialog box.

          Then when I run the strategy, the code would perform it's logic based on the input variable's value of 10.

          However, when the strategy is terminated (i.e., stop hit, target hit, manually turned off), I would like to automatically reset the input variable back to 0 and have the value of 0 be reflected in the parameter dialog box instead of the value of 10. I hope that makes sense.


          Regards
          From your description, this input is publicly exposed and available from the PropertyGrid?

          Comment


            #6
            Originally posted by koganam View Post
            From your description, this input is publicly exposed and available from the PropertyGrid?
            Yes. The input is publicly exposed and available from the properties grid.

            Comment


              #7
              Originally posted by NinjaTrader_ChelseaB View Post
              Hello maltese,

              If you want to set the default value to 0, do this when you create the public variable and private variable, similar to how the Fast and Slow public variables in the SampleMACrossOver strategy are used.

              The default values can be overwritten manually after a script is added but before it is enabled.

              Take a look at the SampleMACrossOver. (Tools -> Edit NinjaScript -> Strategy... -> SampleMACrossOver -> OK)

              I also recommend you watch the video on strategy creation to see how setting defaults works.
              https://www.youtube.com/watch?v=Maaq...56536A44DD7105
              Chelsea, I already know how to initialize the public variable. My question is how do I reset the variable back to 0 automatically using code when the strategy is terminated and have the reset value be reflected back into the properties grid.

              Comment


                #8
                Hello,

                It is not possible to dynamically change values in the parameters.

                If you remove and add the script the values reset to the defaults.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by maltese View Post
                  Yes. The input is publicly exposed and available from the properties grid.
                  Just put the [XmlIgnore] ignore attribute on the property. That should usually prevent serializing the input, so any changes will not be persisted.

                  Comment


                    #10
                    Originally posted by koganam View Post
                    Just put the [XmlIgnore] ignore attribute on the property. That should usually prevent serializing the input, so any changes will not be persisted.
                    Thank you koganam. I will try that

                    Comment


                      #11
                      Thanks Chelsea for your time and effort.

                      Comment


                        #12
                        maltese,

                        The [XmlIgnore()] will keep the values from being saved with a template or a workspace (meaning if you close and open the workspace, these values will be reset), but this will not reset the values if you disable the strategy and then re-enable it.

                        I mention this, because you have initially asked to have this reset in the OnTermination(), which sounds like you want to be able to disable and re-enable to have these values reset.

                        I think there may be some unsupported way of doing this with a type converter but this is not supported by NinjaTrader and I cannot assist with this.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_ChelseaB View Post
                          maltese,

                          The [XmlIgnore()] will keep the values from being saved with a template or a workspace (meaning if you close and open the workspace, these values will be reset), but this will not reset the values if you disable the strategy and then re-enable it.

                          I mention this, because you have initially asked to have this reset in the OnTermination(), which sounds like you want to be able to disable and re-enable to have these values reset.

                          I think there may be some unsupported way of doing this with a type converter but this is not supported by NinjaTrader and I cannot assist with this.
                          Thank you for that information.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          650 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          370 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by Mindset, 02-09-2026, 11:44 AM
                          0 responses
                          109 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                          0 responses
                          574 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          577 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X