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

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.

    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 kempotrader, Today, 08:56 AM
      0 responses
      6 views
      0 likes
      Last Post kempotrader  
      Started by kempotrader, Today, 08:54 AM
      0 responses
      4 views
      0 likes
      Last Post kempotrader  
      Started by mmenigma, Today, 08:54 AM
      0 responses
      2 views
      0 likes
      Last Post mmenigma  
      Started by halgo_boulder, Today, 08:44 AM
      0 responses
      1 view
      0 likes
      Last Post halgo_boulder  
      Started by drewski1980, Today, 08:24 AM
      0 responses
      4 views
      0 likes
      Last Post drewski1980  
      Working...
      X