Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

private static variables are shared?

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

    private static variables are shared?

    I have a bug which seems to go away when I change
    private static int varx;
    to
    private int varx;
    but only if the same indicator is used in another chart.
    varx seems to pick up the values of varx in any other chart having that indicator after a while, even if I reset varx to 0 on FirstTickOfBar in each instance.
    Is the static area shared between multiple instances of the same indicator in different charts?
    I know that this might still be my bug in other ways, but the issue is very repeatable and can be made to show up in the output window.
    I do not actually need the "static" property one way or the other for the code to otherwise work. It was an artifact of earlier design.
    I am using version 6.5.15 but has happened in earlier versions.

    #2
    roland_nt, using static / global variables in C# is unfortunately beyond what we can offer support for, however aspects and ways how to proceed have been discussed already here on our forums -

    Comment


      #3
      Originally posted by roland_nt View Post
      ...Is the static area shared between multiple instances of the same indicator in different charts?...
      Yes, this is correct, or even more precisely: A static variable is shared by all instances of the same class. Use a static element only when really needed.

      Regards
      Ralph

      Comment


        #4
        Thanks

        Ralph:
        Thanks for confirming my suspicion. It helps me to improve other indicators I have written as well and to understand exactly when "static" attribute might be properly used for an indicator. Really appreciate your stopping by to comment.
        Roland

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        134 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        75 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        119 views
        2 likes
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        114 views
        1 like
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        92 views
        0 likes
        Last Post CarlTrading  
        Working...
        X