during development I've noticed that when anything in NT is being recompiled static variables no longer function as expected. I'm just pointing out the issue to others.
Example:
public class StaticTest : Indicator
{
private static string staticText;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Static values test";
Name = "StaticTest";
Calculate = Calculate.OnBarClose;
IsOverlay = false;
DisplayInDataBox = false;
DrawOnPricePanel = false;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = false;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true;
Text = string.Empty;
}
else if (State == State.Configure)
{
}
}
protected override void OnBarUpdate()
{
if(State != State.Realtime) {
return;
}
if(staticText == null) {
staticText = Text;
}
Print(String.Format("Instrument: {0} Text: {1}", Instrument.FullName, staticText));
}
#region Properties
[NinjaScriptProperty]
[Display(Name="Text", Order=1, GroupName="Parameters")]
public string Text
{ get; set; }
#endregion
}
Output:
Instrument: NQ 03-20 Text: 1 Instrument: GC 04-20 Text: 1
Output:
Instrument: NQ 03-20 Text: 1 Instrument: GC 04-20 Text: 2
If this is not preventable people using code with static values should be aware of issues, maybe there is a workaround although I don't thing there needs to be one.
In case such a workaround exists, if logic managing the static values is changed, NT would have to be restarted.
I can imagine that it could be handled via IPC for simple values but passing object references would be more difficult.

Comment