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; }
}
}

Comment