Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

initializing a varable

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

    initializing a varable

    Hi,

    I need a counter in the following example code.

    if(......)
    {
    count=count+1;
    }

    However I need to give the varable count an initial value otherwise I get an error. But putting int count=1; above the code does not work, because every time count is reset to 1. Putting int count=1; in the initialize section does not work either, neither the statements
    int count;
    if (currentBar==1) count=1;

    I am a newbie to NT but have experience with other programming languages and EL.

    Any help will be appreciated

    #2
    Not sure I follow. Why can't you declare your variable like this:
    Code:
    int count = 0;
    This code will compile fine. The variable will be set to 0 every time you e.g. throw an indicator or strategy on you chart.
    DierkNinjaTrader Customer Service

    Comment


      #3
      Please make sure you declare the variable outside of the OnBarUpdate() method. Since you likely want the scope of this variable to be for the indicator and not local to any method (function) you will then need to declare it for the class itself. Look for the "Variables" section and put the variable there.

      private int count = 0;

      then you can use this variable in any method within the indicator.
      RayNinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by michaelsh, Today, 04:28 PM
      0 responses
      4 views
      0 likes
      Last Post michaelsh  
      Started by Bmatarese, Today, 03:13 PM
      1 response
      6 views
      0 likes
      Last Post NinjaTrader_ChrisL  
      Started by sdauteuil, Today, 12:32 PM
      4 responses
      17 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by Gaterz, 09-27-2020, 05:52 PM
      10 responses
      51 views
      0 likes
      Last Post tcea9
      by tcea9
       
      Started by derivtrader, Today, 12:04 PM
      1 response
      8 views
      0 likes
      Last Post NinjaTrader_Spencer  
      Working...
      X