Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 -

    BertrandNinjaTrader Customer Service

    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 lorem, Today, 09:18 AM
        0 responses
        2 views
        0 likes
        Last Post lorem
        by lorem
         
        Started by hazylizard, Today, 08:38 AM
        4 responses
        11 views
        0 likes
        Last Post hazylizard  
        Started by geddyisodin, Today, 05:20 AM
        2 responses
        18 views
        0 likes
        Last Post geddyisodin  
        Started by Max238, Today, 01:28 AM
        5 responses
        47 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by giulyko00, Yesterday, 12:03 PM
        3 responses
        13 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Working...
        X