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

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.
    JesseNinjaTrader Customer Service

    Comment


      #3
      well i learned something today.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by burtoninlondon, Today, 12:38 AM
      0 responses
      4 views
      0 likes
      Last Post burtoninlondon  
      Started by AaronKoRn, Yesterday, 09:49 PM
      0 responses
      12 views
      0 likes
      Last Post AaronKoRn  
      Started by carnitron, Yesterday, 08:42 PM
      0 responses
      11 views
      0 likes
      Last Post carnitron  
      Started by strategist007, Yesterday, 07:51 PM
      0 responses
      13 views
      0 likes
      Last Post strategist007  
      Started by StockTrader88, 03-06-2021, 08:58 AM
      44 responses
      3,982 views
      3 likes
      Last Post jhudas88  
      Working...
      X