Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Incorrect DefaultValue Showing in Properties

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

    Incorrect DefaultValue Showing in Properties

    I am not getting the intended response or Look-and-Feel from my Indicator Properties, when using [DefaultValue(x)]. I set a value, but in the user UI under indicator Properties, it shows up as 0 (zero), to start, not the default value.
    I can “force it” using either a private double variable, or setting it under State.SetDefaults, however, this seems dangerous to me as there would be a possibility that the value used for either method could be different than the [DefaultValue(x)], and therefore inconsistent.
    Is there a (simple) fix to getting the Properties field to populate with the proper default value?


    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class Test_DefaultValueFix : Indicator
    {
    //private double upperLevel1 = 40;
    //private double lowerLevel1 = -10;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = "Test for proper default values in UI";
    Name = "Test_DefaultValueFix";
    Calculate = Calculate.OnBarClose;
    IsOverlay = false;

    // Explicitly set the default value for Level
    //UpperLevel4 = 40;

    }
    }

    protected override void OnBarUpdate()
    {
    // Just output to test
    //Print("UpperLevel1: " + UpperLevel1);
    //Print("LowerLevel1: " + LowerLevel1);
    }

    [Range(-1000, 1000)]
    [DefaultValue(40)]
    [NinjaScriptProperty]
    [Display(Name = "Upper Level 4", GroupName = "Upper Values", Order = 1)]
    public double UpperLevel4 { get; set; }

    }
    }​

    #2
    Hello tradeologist,

    The code [DefaultValue(40)] is not valid code, you need to use State.SetDefaults to set defaults for a script. After changing that code you need to remove the script from where it was applied and then re apply it.

    Code:
    if (State == State.SetDefaults)
    {
          UpperLevel4 = 40;
    }

    Comment


      #3
      Well Drats -- Thanks Jesse.
      I had tried that, and it was commented out in my code.

      And I also wonder why I can't get on the right side of a trade too...
      Thanks for your help!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      647 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      368 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      108 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      571 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      573 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X