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

transcript code N7 / N8

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

    transcript code N7 / N8

    Good morning,
    attached a document to ask you how to transcribe this part of code from Ninja7 to Ninja8.
    I'm waiting.
    Thank you.
    Roberto
    Attached Files

    #2
    Hello,

    Thank you for the post.

    If you are referring to the two private variables pictured, this is actually a C# concept you are seeing and nothing NinjaScript specific. There is some public information which I will link below, here is a short explanation of what you have run into.

    What you have shown is a public property, the left in NT7 is a public property with a backing field:

    Code:
    private double rangeLong;
    
    public double RangeLong
    {
    get { return rangeLong; }
    set { rangeLong = Math.Max(1, value); }
    }
    In NT8, this was generated to start as a public property in the form of an "auto property" or a property that has no backing field:

    Code:
    public double RangeLong
    { get; set; }
    Both work virtually the same, except in your case the NT7 property actually does use the public properties set body for math logic. The set body is setting the value to the max between the input value and 1.

    In NT8, you are using an Attribute to achieve the Math.Max process so there is no set body needed:

    Code:
    [B][Range(1, double.MaxValue)][/B]
    public double RangeLong
    { get; set; }

    In this situation, you don't need a backing field because there is no need for logic in the get or set's body. Because of that, the property can be converted into an auto property which is shown in the NT8 code.

    If you did need to add logic to the get or set body, you would instead form it like how it looks in NT7 where you have a body for both get and set along with a private variable.

    Here is some publically available information on public properties and backing fields in C#:

    The codebase I'm working in now has the convention of using private fields and public properties. For example, most classes have their members defined like this: // Fields private double _foo; pri...

    When setting a value to a variable inside of a class most of the time we are presented with two options: private string myValue; public string MyValue { get { return myValue; } set { myValue =

    A field in C# is a variable of any type that is declared directly in a class or struct. Fields are members of their containing type.


    As a side note, I have not pictured the other attributes ( the items between [ and ] above the property) in these examples. You would still want to use the attributes generated with the NT8 syntax even if you use a backing field. You can find more information on these attributes here: https://ninjatrader.com/support/help...sub=attributes

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thank you Jesse.
      Roberto

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by algospoke, Yesterday, 06:40 PM
      2 responses
      19 views
      0 likes
      Last Post algospoke  
      Started by ghoul, Today, 06:02 PM
      3 responses
      14 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by jeronymite, 04-12-2024, 04:26 PM
      3 responses
      45 views
      0 likes
      Last Post jeronymite  
      Started by Barry Milan, Yesterday, 10:35 PM
      7 responses
      20 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by AttiM, 02-14-2024, 05:20 PM
      10 responses
      181 views
      0 likes
      Last Post jeronymite  
      Working...
      X