(Actually) trim the bids / asks to configured number of levels
This commit is contained in:
parent
5603353cc5
commit
479bbfd791
@ -97,6 +97,7 @@ namespace NinjaTrader.NinjaScript.Indicators
|
||||
}
|
||||
|
||||
ProcessMarketDepthMessage(message.Trim());
|
||||
TrimMarketDepth(maxLevels);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -158,6 +159,42 @@ namespace NinjaTrader.NinjaScript.Indicators
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void TrimMarketDepth(int maxLevels)
|
||||
{
|
||||
if (maxLevels <= 0)
|
||||
return;
|
||||
|
||||
if (Asks.Count > maxLevels)
|
||||
{
|
||||
var sortedLevels = Asks.Keys.OrderBy(x => x).ToList();
|
||||
if (sortedLevels.Count > maxLevels)
|
||||
{
|
||||
// Remove the highest asks.
|
||||
var levelsToRemove = sortedLevels.Skip(maxLevels).ToList();
|
||||
foreach (var level in levelsToRemove)
|
||||
{
|
||||
int value;
|
||||
Asks.TryRemove(level, out value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Bids.Count > maxLevels)
|
||||
{
|
||||
var sortedLevels = Bids.Keys.OrderBy(x => x).ToList();
|
||||
if (sortedLevels.Count > maxLevels)
|
||||
{
|
||||
// Remove the lowest bids.
|
||||
var levelsToRemove = sortedLevels.Take(sortedLevels.Count - maxLevels).ToList();
|
||||
foreach (var level in levelsToRemove)
|
||||
{
|
||||
int value;
|
||||
Bids.TryRemove(level, out value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class MarketDepth : Indicator
|
||||
|
Loading…
Reference in New Issue
Block a user