Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Private static variables

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

    Private static variables

    Hi. I have the following class level array definitions in an indicator
    When applying the same indicator to different charts it appears these arrays are sharing the same values
    When the static declaration is removed the sharing stops.

    Is this the behavior you would anticipate ?
    I feel this may be a possible blind spot in my c# skills??
    thx

    Code:
    private static int[] Deco = new int[50];
    private static int[,] SubDeco = new int[100, 25];


    #2
    Originally posted by Bidder View Post
    I feel this may be a possible blind spot in my c# skills??

    Code:
    private static int[] Deco = new int[50];
    private static int[,] SubDeco = new int[100, 25];
    You are correct.

    Have you searched the internet to correct this blind spot?

    Last edited by bltdavid; 07-12-2023, 11:21 PM.

    Comment


      #3
      Thanks for that. Yes I did a due diligence search before posting this question.

      The distinctive is how c# is being implemented by Ninja and the verbiage used by most c# documentation.

      The link uses the nomenclature "among all objects at the class level" - So in Ninjaspeak applying the same indicator to two charts would be two instances of the same class and therefore at the same class level - is how I would translate that.

      Comment


        #4
        Hello Bidder,

        Thanks for your post.

        In general we do not suggest using static in NinjaScript as there are generally no use cases which require that type of development. You can certainly use static in your own development because it is part of C# however static does run against the general design pattern of NinjaScript so there may be some lapses with that use.

        Please see this forum thread where my colleague Jesse details more information about using static variables in NinjaScript: https://forum.ninjatrader.com/forum/...85#post1089585
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment


          #5
          Originally posted by Bidder View Post
          Thanks for that. Yes I did a due diligence search before posting this question.

          The distinctive is how c# is being implemented by Ninja and the verbiage used by most c# documentation.

          The link uses the nomenclature "among all objects at the class level" - So in Ninjaspeak applying the same indicator to two charts would be two instances of the same class and therefore at the same class level - is how I would translate that.
          Your translation is correct.

          ​In lots of ways, 'NinjaScript-Speak' is a superset of 'C#-Speak'.

          -=o=-

          Let's be clear,
          NinjaTrader has not changed the syntax or semantics of the C# language.
          NinjaTrader Desktop is written in C# and uses the .NET Framework.

          The NinjaScript framework is a class library exposed to C# developers
          who would like to extend the NinjaTrader Desktop platform

          Just like a browser, you can write 'plugins', but these are usually written
          using C# and absolutely depend upon the NinjaScript framework.

          These plugins are just C# classes, and have names like Indicator, and
          Strategy, and NTWindow. Most of NinjaScript is a huge class hierarchy
          built to support these 3 main classes.

          The NinjaScript framework is not a standalone class library. It cannot
          be installed via nuget. There is no way to download it separately. The
          only way to get access to the NinjaScript framework is to install
          NinjaTrader.

          Within the NinjaScript framework,
          the entire power of C# and .NET Framework is available to the
          skilled C# developer to do just about whatever they please.

          The verbiage and nomenclature of the C# documentation is designed
          to explain the language and how it's used. The NinjaScript help pages
          focus on API descriptions and examples -- they do not try to teach C#,
          so the verbiage is at a higher level, because the focus is the framework,
          not the language.

          That said, there is a huge crossover between the two. When the NT
          docs say 'class', absolutely everything about a C# class (as decribed
          in the C# language) also applies to that NinjaScript class.

          Just my 2˘.


          Comment


            #6
            Guys, this is good stuff.

            A 2˘ investment with the right compounding is a boatload at the end of the month.

            Thanks to the both of you.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by adilmedarhry, Today, 08:15 AM
            1 response
            44 views
            0 likes
            Last Post bltdavid  
            Started by artsi_lucky, 11-19-2024, 01:20 PM
            8 responses
            142 views
            0 likes
            Last Post artsi_lucky  
            Started by ziponline, Today, 01:39 PM
            8 responses
            34 views
            0 likes
            Last Post ziponline  
            Started by Irukandji, Today, 04:24 PM
            0 responses
            8 views
            0 likes
            Last Post Irukandji  
            Started by FishTrade, Today, 04:10 PM
            0 responses
            5 views
            0 likes
            Last Post FishTrade  
            Working...
            X