Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Global variables

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

    Global variables

    Hello,
    I have an indicator that is used in market analyzer .
    This indicator reads an external file and does some processing.
    I would like the reading of the file to occur only once . What I see is that the file is read for each instrument listed in the market analyzer .
    I tried defining a varaibale as "int" or "bool" without the private decleration , hoping that it will be a global varaible, however I see that the variable gets initialized on each call of the indicator.
    So is there a way to define a global variable ? alternatively how can I pass a variable that can be used by all instruments using this indicator?
    Thanks

    #2
    Hello Leope,

    Thank you for your post.

    You could use a Static Class and return a value that indicates the file was already read. This way every instance of the indicator (each instrument is running an instance) would not try to read the file. However, this would work globally across all windows in NinjaTrader. So any other charts or Market Analyzers would also see the file as being read already.

    Please let me know if you have any questions.

    Comment


      #3
      Hello,
      Thanks for your answer !
      Is there some sample code I can look at ?
      Thanks!

      Comment


        #4
        Hello Leope,

        Thank you for your response.

        You can actually do this in the UserDefinedMethods: http://ninjatrader.com/support/helpG...ed_methods.htm

        For example; under Tools > Edit NinjaScript > Indicator > User Defined Methods > Edit:
        Code:
        namespace NinjaTrader.Indicator
        {
            /// <summary>
            /// This file holds all user defined indicator methods.
            /// </summary>
            partial class Indicator
            {
        		public bool read = false;
        Then in your indicator:
        Code:
        			if (read == false)
        			{
        				// run your read logic
        				read = true;
        			}
        Please let me know if you have any questions.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by WHICKED, Today, 12:56 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by cre8able, Today, 01:16 PM
        0 responses
        1 view
        0 likes
        Last Post cre8able  
        Started by chbruno, 04-24-2024, 04:10 PM
        2 responses
        47 views
        0 likes
        Last Post chbruno
        by chbruno
         
        Started by WHICKED, Today, 12:45 PM
        1 response
        11 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by samish18, Today, 01:01 PM
        0 responses
        5 views
        0 likes
        Last Post samish18  
        Working...
        X