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 helpwanted, Today, 03:06 AM
        1 response
        7 views
        0 likes
        Last Post sarafuenonly123  
        Started by Brevo, Today, 01:45 AM
        0 responses
        7 views
        0 likes
        Last Post Brevo
        by Brevo
         
        Started by aussugardefender, Today, 01:07 AM
        0 responses
        5 views
        0 likes
        Last Post aussugardefender  
        Started by pvincent, 06-23-2022, 12:53 PM
        14 responses
        242 views
        0 likes
        Last Post Nyman
        by Nyman
         
        Started by TraderG23, 12-08-2023, 07:56 AM
        9 responses
        385 views
        1 like
        Last Post Gavini
        by Gavini
         
        Working...
        X