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 habeebft, Today, 07:27 AM
        1 response
        11 views
        0 likes
        Last Post NinjaTrader_ChristopherS  
        Started by AveryFlynn, Today, 04:57 AM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by Max238, Today, 01:28 AM
        4 responses
        37 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by r68cervera, Today, 05:29 AM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by geddyisodin, Today, 05:20 AM
        1 response
        14 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Working...
        X