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 canzana, Today, 12:10 AM
      0 responses
      1 view
      0 likes
      Last Post canzana
      by canzana
       
      Started by thebionukerlife, Yesterday, 11:41 PM
      0 responses
      1 view
      0 likes
      Last Post thebionukerlife  
      Started by thebionukerlife, Yesterday, 11:40 PM
      0 responses
      1 view
      0 likes
      Last Post thebionukerlife  
      Started by KirkHammett, Yesterday, 11:15 PM
      0 responses
      3 views
      0 likes
      Last Post KirkHammett  
      Started by soon123, Yesterday, 11:12 PM
      0 responses
      2 views
      0 likes
      Last Post soon123
      by soon123
       
      Working...
      X