Add configuration property for setting the maximum number of market depth levels to display

This commit is contained in:
moshferatu 2024-04-10 18:50:38 -07:00
parent fe3644749d
commit 4c2eacedf8

View File

@ -48,7 +48,7 @@ namespace NinjaTrader.NinjaScript.Indicators
{"12", "Z"}
};
public static async Task StreamMarketDepth(Instrument instrument)
public static async Task StreamMarketDepth(Instrument instrument, int maxLevels)
{
string symbol = GetIQFeedSymbol(instrument);
@ -86,7 +86,10 @@ namespace NinjaTrader.NinjaScript.Indicators
if (message.Contains("S,SERVER CONNECTED"))
{
await SendCommand(stream, "S,SET PROTOCOL,6.2");
await SendCommand(stream, "WPL," + symbol + ",200");
string command = "WPL," + symbol + ",";
if (maxLevels > 0)
command += maxLevels.ToString();
await SendCommand(stream, command);
continue;
}
@ -171,6 +174,7 @@ namespace NinjaTrader.NinjaScript.Indicators
PaintPriceMarkers = false;
ScaleJustification = ScaleJustification.Right;
IsSuspendedWhileInactive = false;
MaxLevels = 0;
MaxWidth = 500;
}
else if (State == State.Configure)
@ -178,7 +182,7 @@ namespace NinjaTrader.NinjaScript.Indicators
}
else if (State == State.DataLoaded)
{
Task.Run(() => MarketDepthProcessor.StreamMarketDepth(Instrument));
Task.Run(() => MarketDepthProcessor.StreamMarketDepth(Instrument, MaxLevels));
}
else if (State == State.Historical)
{
@ -239,7 +243,11 @@ namespace NinjaTrader.NinjaScript.Indicators
}
[NinjaScriptProperty]
[Display(Name = "Max Width", Description = "The maximum width of the market depth lines in pixels", Order = 1, GroupName = "Market Depth")]
[Display(Name = "Max Levels", Description = "The maximum number of levels to display (0 for unlimited)", Order = 1, GroupName = "Market Depth")]
public int MaxLevels { get; set; }
[NinjaScriptProperty]
[Display(Name = "Max Width", Description = "The maximum width of the market depth levels in pixels", Order = 2, GroupName = "Market Depth")]
public int MaxWidth
{ get; set; }
}
@ -252,18 +260,18 @@ namespace NinjaTrader.NinjaScript.Indicators
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
{
private MarketDepth[] cacheMarketDepth;
public MarketDepth MarketDepth(int maxWidth)
public MarketDepth MarketDepth(int maxLevels, int maxWidth)
{
return MarketDepth(Input, maxWidth);
return MarketDepth(Input, maxLevels, maxWidth);
}
public MarketDepth MarketDepth(ISeries<double> input, int maxWidth)
public MarketDepth MarketDepth(ISeries<double> input, int maxLevels, int maxWidth)
{
if (cacheMarketDepth != null)
for (int idx = 0; idx < cacheMarketDepth.Length; idx++)
if (cacheMarketDepth[idx] != null && cacheMarketDepth[idx].MaxWidth == maxWidth && cacheMarketDepth[idx].EqualsInput(input))
if (cacheMarketDepth[idx] != null && cacheMarketDepth[idx].MaxLevels == maxLevels && cacheMarketDepth[idx].MaxWidth == maxWidth && cacheMarketDepth[idx].EqualsInput(input))
return cacheMarketDepth[idx];
return CacheIndicator<MarketDepth>(new MarketDepth(){ MaxWidth = maxWidth }, input, ref cacheMarketDepth);
return CacheIndicator<MarketDepth>(new MarketDepth(){ MaxLevels = maxLevels, MaxWidth = maxWidth }, input, ref cacheMarketDepth);
}
}
}
@ -272,14 +280,14 @@ namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
{
public Indicators.MarketDepth MarketDepth(int maxWidth)
public Indicators.MarketDepth MarketDepth(int maxLevels, int maxWidth)
{
return indicator.MarketDepth(Input, maxWidth);
return indicator.MarketDepth(Input, maxLevels, maxWidth);
}
public Indicators.MarketDepth MarketDepth(ISeries<double> input , int maxWidth)
public Indicators.MarketDepth MarketDepth(ISeries<double> input , int maxLevels, int maxWidth)
{
return indicator.MarketDepth(input, maxWidth);
return indicator.MarketDepth(input, maxLevels, maxWidth);
}
}
}
@ -288,14 +296,14 @@ namespace NinjaTrader.NinjaScript.Strategies
{
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
{
public Indicators.MarketDepth MarketDepth(int maxWidth)
public Indicators.MarketDepth MarketDepth(int maxLevels, int maxWidth)
{
return indicator.MarketDepth(Input, maxWidth);
return indicator.MarketDepth(Input, maxLevels, maxWidth);
}
public Indicators.MarketDepth MarketDepth(ISeries<double> input , int maxWidth)
public Indicators.MarketDepth MarketDepth(ISeries<double> input , int maxLevels, int maxWidth)
{
return indicator.MarketDepth(input, maxWidth);
return indicator.MarketDepth(input, maxLevels, maxWidth);
}
}
}