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 Waxavi, Today, 02:10 AM
        0 responses
        4 views
        0 likes
        Last Post Waxavi
        by Waxavi
         
        Started by TradeForge, Today, 02:09 AM
        0 responses
        10 views
        0 likes
        Last Post TradeForge  
        Started by Waxavi, Today, 02:00 AM
        0 responses
        2 views
        0 likes
        Last Post Waxavi
        by Waxavi
         
        Started by elirion, Today, 01:36 AM
        0 responses
        4 views
        0 likes
        Last Post elirion
        by elirion
         
        Started by gentlebenthebear, Today, 01:30 AM
        0 responses
        4 views
        0 likes
        Last Post gentlebenthebear  
        Working...
        X