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 Jonker, Today, 01:19 PM
      0 responses
      1 view
      0 likes
      Last Post Jonker
      by Jonker
       
      Started by futtrader, Today, 01:16 PM
      0 responses
      5 views
      0 likes
      Last Post futtrader  
      Started by Segwin, 05-07-2018, 02:15 PM
      14 responses
      1,791 views
      0 likes
      Last Post aligator  
      Started by Jimmyk, 01-26-2018, 05:19 AM
      6 responses
      844 views
      0 likes
      Last Post emuns
      by emuns
       
      Started by jxs_xrj, 01-12-2020, 09:49 AM
      6 responses
      3,296 views
      1 like
      Last Post jgualdronc  
      Working...
      X