Upon refreshing the chart F5, the indicator is supposed to unsub the event, and when it loads back in, re-subscribe. For some reason, it's not unsubbing so it keeps duplicating the event handler. I tried using Dispatcher, but IIRC that has to do with custom buttons which this indicator does not have. Also tried to print "Unsubbing" to confirm it unsubbed but that print never occurs. Doesn't the indicator go to the temporary state of Terminated when refreshing the chart thus it should run through that bit of code?
else if (State == State.Historical)
{
if (ChartControl != null )
{
lock (Account.All)
userAccount = Account.All.FirstOrDefault(a => a.Name == AccountName);
count = 0;
intrumentName = InstrumentInput.FullName;
ChartControl.Dispatcher.InvokeAsync((Action)(() => {
InitialOrderTransfer(); --> userAccount.ExecutionUpdate += OnExecutionUpdate;
}));
}
else if (State == State.Terminated)
{
if (ChartControl == null)
return;
// Unsubscribe to events
ChartControl.Dispatcher.InvokeAsync((() =>
{
userAccount.ExecutionUpdate -= OnExecutionUpdate;
Print("Unsubing");
}));
}

Comment