Add the ability to configure the maximum width of the indicator

This commit is contained in:
moshferatu 2024-04-09 08:08:11 -07:00
parent 93b8f4e557
commit fe3644749d

View File

@ -170,7 +170,8 @@ namespace NinjaTrader.NinjaScript.Indicators
DrawVerticalGridLines = false;
PaintPriceMarkers = false;
ScaleJustification = ScaleJustification.Right;
IsSuspendedWhileInactive = true;
IsSuspendedWhileInactive = false;
MaxWidth = 500;
}
else if (State == State.Configure)
{
@ -201,7 +202,7 @@ namespace NinjaTrader.NinjaScript.Indicators
float price = Ask.Key;
int volume = Ask.Value;
int length = (int)((double)volume / maxVolume * 500);
int length = (int)((double)volume / maxVolume * MaxWidth);
int y = chartScale.GetYByValue(price);
DrawHorizontalLine((ChartPanel.X + ChartPanel.W) - length, ChartPanel.X + ChartPanel.W, y, new Stroke(Brushes.Red, DashStyleHelper.Solid, 3));
@ -212,7 +213,7 @@ namespace NinjaTrader.NinjaScript.Indicators
float price = Bid.Key;
int volume = Bid.Value;
int length = (int)((double)volume / maxVolume * 500);
int length = (int)((double)volume / maxVolume * MaxWidth);
int y = chartScale.GetYByValue(price);
DrawHorizontalLine((ChartPanel.X + ChartPanel.W) - length, ChartPanel.X + ChartPanel.W, y, new Stroke(Brushes.LimeGreen, DashStyleHelper.Solid, 3));
@ -236,6 +237,11 @@ namespace NinjaTrader.NinjaScript.Indicators
{
get { return Name; }
}
[NinjaScriptProperty]
[Display(Name = "Max Width", Description = "The maximum width of the market depth lines in pixels", Order = 1, GroupName = "Market Depth")]
public int MaxWidth
{ get; set; }
}
}
@ -246,18 +252,18 @@ namespace NinjaTrader.NinjaScript.Indicators
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
{
private MarketDepth[] cacheMarketDepth;
public MarketDepth MarketDepth()
public MarketDepth MarketDepth(int maxWidth)
{
return MarketDepth(Input);
return MarketDepth(Input, maxWidth);
}
public MarketDepth MarketDepth(ISeries<double> input)
public MarketDepth MarketDepth(ISeries<double> input, int maxWidth)
{
if (cacheMarketDepth != null)
for (int idx = 0; idx < cacheMarketDepth.Length; idx++)
if (cacheMarketDepth[idx] != null && cacheMarketDepth[idx].EqualsInput(input))
if (cacheMarketDepth[idx] != null && cacheMarketDepth[idx].MaxWidth == maxWidth && cacheMarketDepth[idx].EqualsInput(input))
return cacheMarketDepth[idx];
return CacheIndicator<MarketDepth>(new MarketDepth(), input, ref cacheMarketDepth);
return CacheIndicator<MarketDepth>(new MarketDepth(){ MaxWidth = maxWidth }, input, ref cacheMarketDepth);
}
}
}
@ -266,14 +272,14 @@ namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
{
public Indicators.MarketDepth MarketDepth()
public Indicators.MarketDepth MarketDepth(int maxWidth)
{
return indicator.MarketDepth(Input);
return indicator.MarketDepth(Input, maxWidth);
}
public Indicators.MarketDepth MarketDepth(ISeries<double> input )
public Indicators.MarketDepth MarketDepth(ISeries<double> input , int maxWidth)
{
return indicator.MarketDepth(input);
return indicator.MarketDepth(input, maxWidth);
}
}
}
@ -282,14 +288,14 @@ namespace NinjaTrader.NinjaScript.Strategies
{
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
{
public Indicators.MarketDepth MarketDepth()
public Indicators.MarketDepth MarketDepth(int maxWidth)
{
return indicator.MarketDepth(Input);
return indicator.MarketDepth(Input, maxWidth);
}
public Indicators.MarketDepth MarketDepth(ISeries<double> input )
public Indicators.MarketDepth MarketDepth(ISeries<double> input , int maxWidth)
{
return indicator.MarketDepth(input);
return indicator.MarketDepth(input, maxWidth);
}
}
}