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 ScottWalsh, 04-16-2024, 04:29 PM
        7 responses
        34 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by cls71, Today, 04:45 AM
        0 responses
        3 views
        0 likes
        Last Post cls71
        by cls71
         
        Started by mjairg, 07-20-2023, 11:57 PM
        3 responses
        214 views
        1 like
        Last Post PaulMohn  
        Started by TheWhiteDragon, 01-21-2019, 12:44 PM
        4 responses
        546 views
        0 likes
        Last Post PaulMohn  
        Started by GLFX005, Today, 03:23 AM
        0 responses
        3 views
        0 likes
        Last Post GLFX005
        by GLFX005
         
        Working...
        X