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 haas88, 03-21-2024, 02:22 AM
      19 responses
      220 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by ZeroKuhl, Yesterday, 04:31 PM
      4 responses
      29 views
      0 likes
      Last Post ZeroKuhl  
      Started by cupir2, Yesterday, 07:44 PM
      3 responses
      21 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by reynoldsn, Yesterday, 07:26 PM
      2 responses
      16 views
      0 likes
      Last Post reynoldsn  
      Started by MartinT, 05-17-2023, 06:00 AM
      18 responses
      175 views
      0 likes
      Last Post flybuzz
      by flybuzz
       
      Working...
      X