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

Setting an initial value for one int and one double

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

    Setting an initial value for one int and one double

    I'm writing a new strategy in which I need to set initial values for an int I'll identify as Counter and a double I'll identify as InitialThreshold. I understand one way I can set their initial values is by defining them as Variables - for example, private int counter = 0; private double initialThreshold = 15.0. However, I don't foresee changing those initial values in the future, because my strategy will reset them at the end of each day to 0 and 15.0, respectively.

    So, other than defining them as Variables, what code can I write in the body of my strategy to initially set Counter to 0 and InitialThreshold to 15.0?

    The strategy will increment Counter by 1 each time market has met certain conditions (but not necessarily on each pass through the strategy). It will use InitialThreshold to "remember" the initial value of SignalThreshold, another variable I've defined, which will change whenever market has met other conditions.

    #2
    Hello Longhornmark,

    Thanks for your post.

    This is more of a general C# item than a NinjaScript question.

    If "Counter" is an int and "InitialThreshold" is a double, these would already be variables. If the a new value is not needed you could use a constant instead. If you want to set these to a certain value, you can do so with the = assignment operator. OnStartUp() happens at the beginning of the script's life and is a good place to assign initial values that require calculation. Otherwise, I think you will be ok declaring your variables with initial values, and to set them/reset them to new values in your OnBarUpdate logic.

    I may suggest checking various other NinjaScripts to see how variables are used there, and you may wish to reference some external C# resources on using variables for even more direction there.

    Our Help Guide for NinjaTrader 7 has some light programming education, but the more indepth Soft Steel Solutions tutorials that are linked therein can also be helpful.

    Programming Concepts - https://ninjatrader.com/support/help...g_concepts.htm

    OnStartUp() - https://ninjatrader.com/support/help.../onstartup.htm

    Please let us know if we can be of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      Thanks Jim. I followed the latter path by defining those initial values as variables.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by lju45, Today, 04:54 AM
      0 responses
      1 view
      0 likes
      Last Post lju45
      by lju45
       
      Started by SuneSorgenfrei, Today, 04:47 AM
      0 responses
      5 views
      0 likes
      Last Post SuneSorgenfrei  
      Started by lakman184, Today, 03:09 AM
      2 responses
      12 views
      0 likes
      Last Post lakman184  
      Started by romintrio, Today, 02:16 AM
      1 response
      4 views
      0 likes
      Last Post NinjaTrader_Jason  
      Started by SCC74, Today, 01:32 AM
      1 response
      10 views
      0 likes
      Last Post NinjaTrader_Jason  
      Working...
      X