View Full Version : OnMarketDepth max level size?
RedDuke
07-01-2008, 10:05 AM
Hello,
What is the most efficient way to figure out which level on DOM has the largest size for bid and ask? I have the following logic within OnMarketDepth event (ask example):
maxValue=0;
maxAskSizeLevel=0;
for(int i=0; i<5; i++)
{
if (e.MarketDepth.Ask[i].Volume > maxValue)
maxValue = e.MarketDepth.Ask[i].Volume;
maxAskSizeLevel = i;
}
But I am afraid that with all the changes that take place it might be too slow. Is there anyway to get this data with some kind of max function?
Thanks,
redduke
NinjaTrader_Ray
07-01-2008, 10:13 AM
You are on the right track but instead of looping through each level, just check the incoming event against your stored variables. The looping is not necessary.
Create some variables local to your indicator/strategy.
private int maxAskValue = 0;
private int maxAskPosition = 0;
then...
if (e.MarketDataType == MarketDataType.Ask && e.Volume > maxAskValue)
{
maxAskValue = e.Volume;
maxAskPosition = e.Position;
}
RedDuke
07-01-2008, 01:36 PM
Hi Ray,
Thanks for this info. This logic would work if all I needed was the largest value ever. If this logic is put in place, and lets say that is a huge number that appears only once on ask of 10,000 contracts, this number would constantly be displayed until I stop and restart since no other number will top it.
What I need is the max value at this point of time, which changes many times during even 1 second. The for loop does the job but many times it can not catch up with all DOM changes.
Is there any other way?
Thanks,
redduke
NinjaTrader_Ray
07-01-2008, 01:42 PM
Ah..got it.
Not sure what you mean too slow. Your logic should be fine.
RedDuke
07-01-2008, 01:57 PM
It works fine when DOM updates are less frequent, but as soon as updates intensify, it many times shows the wrong value, eventually corrects and then the cycle renews.
Thanks,
redduke
NinjaTrader_Ray
07-01-2008, 02:07 PM
Best build your own book then. The depth object is multi-threaded and the values you are accessing can already be updated as a new event comes in. You are guaranteed to get all events though.
Here is a reference - http://www.ninjatrader-support.com/vb/showthread.php?t=3478
RedDuke
07-01-2008, 02:24 PM
Ray,
Thanks. I will experiment with it.
Regards,
redduke
RedDuke
07-02-2008, 08:26 AM
I figured out what the issue was. It had nothing to do with frequent updates, I got a bit confused in the beginning when I started looking for the error. All it was just missing brackets on if statement (I highlighted them in bold). Without them, the last (fifth) level data was always selected. I tested the code this morning, and it worked fine even during very fast market conditions.
maxValue=0;
maxAskSizeLevel=0;
for(int i=0; i<5; i++)
{
if (e.MarketDepth.Ask[i].Volume > maxValue)
{
maxValue = e.MarketDepth.Ask[i].Volume;
maxAskSizeLevel = i;
}
}
Regards,
redduke