• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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 chazyang, Today, 08:11 AM
      1 response
      2 views
      0 likes
      Last Post NinjaTrader_PatrickG  
      Started by Erwin Beckers, 11-04-2018, 02:39 AM
      6 responses
      77 views
      2 likes
      Last Post koganam
      by koganam
       
      Started by sergey_z, Today, 02:34 AM
      3 responses
      14 views
      0 likes
      Last Post NinjaTrader_PaulH  
      Started by frankduc, Today, 05:24 AM
      4 responses
      16 views
      0 likes
      Last Post frankduc  
      Started by shmarola, Today, 01:01 AM
      0 responses
      4 views
      0 likes
      Last Post shmarola  
      Working...
      X