• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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:
    [Range(1, double.MaxValue)]
    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#:

    https://softwareengineering.stackexc...private-fields
    https://softwareengineering.stackexc...le-vs-property
    https://docs.microsoft.com/en-us/dot...structs/fields

    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 futurenick, Today, 06:26 AM
      1 response
      7 views
      0 likes
      Last Post nkhoi
      by nkhoi
       
      Started by NinjaCustomer, Today, 12:29 PM
      0 responses
      1 view
      0 likes
      Last Post NinjaCustomer  
      Started by Steve L, Today, 11:32 AM
      0 responses
      2 views
      0 likes
      Last Post Steve L
      by Steve L
       
      Started by prabbala, Today, 10:41 AM
      0 responses
      2 views
      0 likes
      Last Post prabbala  
      Started by bebbus, Today, 10:36 AM
      0 responses
      3 views
      0 likes
      Last Post bebbus
      by bebbus
       
      Working...
      X