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

Using a property without a "set;" ? What does it mean?

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

    Using a property without a "set;" ? What does it mean?

    First of all, I'm NOT really familiar with C#. I didn't find any info about this. What happens if a C# property has a get but does NOT have a set? Sample code from @RSI.CS:
    Code:
    		public Series<double> Avg
    		{
    			get { return Values[1]; }
    		}
    
    		public Series<double> Default
    		{
    			get { return Values[0]; }
    		}
    The code in RSI does write them:
    Code:
    			Default[0]		= value0;
    			Avg[0]		= constant1 * value0 + constant2 * Avg[1];
    So what is happening up there? Just to understand, it is something like the below C++ code?
    Code:
    double& Avg(int index)
    {
        return Values[index+1];
    }
    Certainly, in C++ you would use Avg(1) instead of Avg[1] since it is a function, I'm just curious what the logic actually does in @RSI.cs. Is the get in this case is like a reference so it can also write values via the get or is the set is auto-implemented so writing and reading the above properties is accessing a completely different index or even variable?

    Also, is it standard C# (to not use a set), or is it something that NinjaTrader changed about C#? I don't know if ninjascript is just C# or does it have differences? (C# vs. ninjascript syntax)
    Last edited by accordtrader; 03-04-2018, 06:40 AM.

    #2
    https://www.dotnetperls.com/property may be instructive.

    Comment


      #3
      Hello accordtrader,

      With a get and no set, this will return that object directly, without trying to set the value from the setter.

      This basically gets the first series in the Values collection and returns that whole series.

      That object can then be directly manipulated.


      The brackets indicate an index of a collection, series, or array.

      NinjaScript is C#. These are scripts that inherit from pre-made classes that have methods NInjaTrader will trigger with data behind the scenes.
      Chelsea B.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by kujista, Today, 05:44 AM
      1 response
      8 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by elderan, Yesterday, 08:03 PM
      1 response
      12 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by samish18, Yesterday, 08:57 AM
      8 responses
      25 views
      0 likes
      Last Post samish18  
      Started by DJ888, 04-16-2024, 06:09 PM
      3 responses
      10 views
      0 likes
      Last Post NinjaTrader_Erick  
      Started by RookieTrader, Today, 07:41 AM
      0 responses
      4 views
      0 likes
      Last Post RookieTrader  
      Working...
      X