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 Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        599 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        344 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        103 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        558 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        557 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X