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

Why default values are not possible?

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

    Why default values are not possible?

    hi.
    I saw nice solution to set values inline (without scattering variables across different places):

    How do you give a C# auto-property an initial value? I either use the constructor, or revert to the old syntax. Using the Constructor: class Person { public Person() { Name = "


    however, that seems impossible in NT IDE, gives error:

    Code:
    Invalid token '=' in class, struct, or interface member declaration

    even another answer, like :
    Code:
    [System.ComponentModel.DefaultValue(true)]
    public bool DefaultValueBool { get; set; }

    is not being understood in NT...

    #2
    Hello TazoTodua,

    This would be custom c# code that is not documented by NinjaTrader or supported by the NinjaTrader Support staff.

    However, this thread will remain open for any community members that would like to assist.

    You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our business development follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I've seen now, cTrader supports the "DefaultValue" parameter. Very nice declarations there:


      [Parameter(DefaultValue = 70)]
      public int My_Level { get; set; }


      probably i am not too good in C#, otherwise there should be some "override" or ability to create special attribute for NT to do that with custom programming. Just i dont know how to do that.
      Last edited by ttodua; 08-14-2018, 01:05 PM.

      Comment


        #4
        Hello TazoTodua,

        I think what you are trying to use is part of c# 6 and higher.

        NinjaTrader 8 targets .NET 4.5 which is c# 5.

        Likely what you are after is not available in this version of .NET.

        Instead, set the defaults in State.SetDefaults. This is important for NinjaTrader as the defaults are pulled and applied in a specific way from OnStateChange at specific times.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CortexZenUSA, Today, 12:53 AM
        0 responses
        1 view
        0 likes
        Last Post CortexZenUSA  
        Started by CortexZenUSA, Today, 12:46 AM
        0 responses
        1 view
        0 likes
        Last Post CortexZenUSA  
        Started by usazencortex, Today, 12:43 AM
        0 responses
        5 views
        0 likes
        Last Post usazencortex  
        Started by sidlercom80, 10-28-2023, 08:49 AM
        168 responses
        2,265 views
        0 likes
        Last Post sidlercom80  
        Started by Barry Milan, Yesterday, 10:35 PM
        3 responses
        12 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X