If I am modifying some object data within the same script but under different methods, should I introduce lock object for multithreading safety or they are fine? I understand that NT8 uses multithreading internally for different methods, but I didn't see much of the built-in indicators uses any lock objects.
public class TestIndicator2 : Indicator
{
private Data _data;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "TestIndicator2";
Calculate = Calculate.OnEachTick;
IsOverlay = false;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
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;
}
else if (State == State.DataLoaded)
{
_data = new Data();
}
}
protected override void OnBarUpdate()
{
_data.Set_Data(1,0.1);
}
protected override void OnMarketDepth(MarketDepthEventArgs marketDepthUpdate)
{
base.OnMarketDepth(marketDepthUpdate);
_data.Set_Data(1, 0.1);
}
private class Data
{
private SortedDictionary<double, double> _Data;
public void Set_Data(double key, double value)
{
if (this._Data.ContainsKey(key))
this._Data[key] += value;
else
this._Data[key] = value;
}
public Data()
{
this._Data = new SortedDictionary<double, double>();
}
}
}

Comment