Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

where is the private variable for the property

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

    where is the private variable for the property

    I am old school and always had a private variable for the properties exposed via get;set; you can see
    Testparameter is not referenced by any private variable.
    maybe programming has changed but when I sit back and looked at this code, I did not understand how this works without a private variable.

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class MyCustomIndicator1 : Indicator
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "MyCustomIndicator1";
    Calculate = Calculate.OnBarClose;
    IsOverlay = false;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
    //See Help Guide for additional information.
    IsSuspendedWhileInactive = true;
    Testparameter = 1;
    }
    else if (State == State.Configure)
    {
    }
    }

    protected override void OnBarUpdate()
    {
    //Add your custom indicator logic here.
    }

    #region Properties
    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name="Testparameter", Order=1, GroupName="Parameters")]
    public int Testparameter
    { get; set; }
    #endregion

    }
    }

    #2
    Hello junkone,

    The private backing field for a public property is a concept in C#, this can be used or not it is up to the developer. That is just used as a storage unit for your public property but if you don't have any logic in the public property there is really no point in doing that, its just extra code.

    If you have a specific reason to need a body in the get/set you can use a private backing field or other variables. To learn more about this concept you could search online for "C# private backing field" or "C# public properties and backing fields".

    https://docs.microsoft.com/en-us/dot...structs/fields

    There is specifically an example of when a backing field is used on the following page:
    https://docs.microsoft.com/en-us/dot...cts/properties


    When you have just {get;set;} you can think of that as essentially the same as both making a public property and having a variable.



    I look forward to being of further assistance.

    Comment


      #3
      well i learned something today.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      649 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      370 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      109 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      574 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      576 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X