GUI variables resetting to defaults

I’m really confused, here.

I have several variables being set within the GUI, using the standard code.

	[Display(Name = "Parameter A", Description = "Set Parameter A", Order = 1, GroupName = "Parameters")]
	public bool prmA
	{ get; set; }

But, the program is ignoring the GUI settings and changing the variables back to their defaults every OnBarUpdate.

Here is the output from Output 1:

Start Time 1 = 4/10/2026 6:30:20 AM, Current Time = 4/10/2026 6:30:20 AM
Parameters active: A = True, B = True, C = False, D = True
Start Time 1 = 4/10/2026 6:30:20 AM, Current Time = 4/10/2026 6:30:20 AM
Parameters active: A = True, B = True, C = True, D = True

This is bothersome for two reasons: 1. OnBarUpdate seems to be running twice on the same bar, and 2. as you can see, Parameter C was false, as it was set in the GUI in this test case, but then, on the same bar and in complete opposition to the user settings, it changes Parameter C to true.

???

Without seeing the rest of the code involved and considering you have 2 print output lines for the same bar with different values, my first guess would be that you have two instances of the indicator running.

If that’s not the problem, the indicator lifecycle docs explain how and when indicators go through their various states and might give you a clue where your problem lies.


For some reason I can’t post a link to the docs. Just search for “NinjaScript Lifecycle” and you should get a link to the NT8 help guide.

1 Like

Okay, I read that. It seems to indicate that the purpose of SetDefaults is to retrieve values for posting in the GUI window when the Indicator is first loaded. That makes sense, and it seems to work that way in every other Indicator I’ve ever written.

What doesn’t make sense is that those variables would ever be set to anything other than the setting specified in the GUI, after the Indicator has already been set up. There is no code anywhere that assigns other values to those Parameters.

	namespace NinjaTrader.NinjaScript.Indicators
	{
		[Gui.CategoryOrderAttribute("Parameters",1)]

Then…

	protected override void OnStateChange()
	{
		if (State == State.SetDefaults)
		{
			........
			prmA										= true;
			prmB										= true;
			prmC										= true;
			prmD										= true;
		}

And, finally,

	#region Properties

	[Display(Name = "Parameter A", Description = "Use Parameter A", Order = 1, GroupName = "Parameters")]
	public bool prmA
	{ get; set; }
	
	[Display(Name = "Parameter B", Description = "Use Parameter B", Order = 2, GroupName = "Parameters")]
	public bool prmB
	{ get; set; }
	
	[Display(Name = "Parameter C", Description = "Use Parameter C", Order = 3, GroupName = "Parameters")]
	public bool prmC
	{ get; set; }
	
	[Display(Name = "Parameter D", Description = "Use Parameter D", Order = 4, GroupName = "Parameters")]
	public bool prmD
	{ get; set; }

Every time I load the GUI, it still shows the last settings I applied, so it’s only changing them in background. And it appears that the defaults are getting loaded every bar, and then changing every bar.

Might this have something to do with the fact that I have three Data Series with different time frames on my chart? I ran into problems with that a long time ago, and the only way I was able to solve it was by having a completely separate window for one Indicator and having it draw global lines.

Multiple data series could explain why you have duplicate prints but values Set in the parameter grid by the user should persist, you must be over writing them somewhere. But it’s impossible to tell from these snippets.

Are you sure you haven’t got the indicator loaded in multiple tabs or something writing to the output window at the same time? the fact values change from 1 print to the next suggests something like this

I have multiple indicators writing to the output screen, and they all have user-specified values, but this is the only one that’s acting this way.

And other than State.SetDefaults, there is no assignment to those variables anywhere. I don’t even have similarly named variables in other indicators.