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 arvidvanstaey, Today, 02:19 PM
      2 responses
      6 views
      0 likes
      Last Post arvidvanstaey  
      Started by jordanq2, Today, 03:10 PM
      0 responses
      2 views
      0 likes
      Last Post jordanq2  
      Started by traderqz, Today, 12:06 AM
      10 responses
      18 views
      0 likes
      Last Post traderqz  
      Started by algospoke, 04-17-2024, 06:40 PM
      5 responses
      46 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by mmckinnm, Today, 01:34 PM
      3 responses
      6 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Working...
      X