You would need to review the code surrounding the two variables being used "sortedDicList" and "cacheDictionary".
You can copy the related code using those variables to accumulate volume into the dictionaries. You would not need the OnRender code, that is just for its custom display. This indicator uses OnMarketData to accumulate the data in realtime, for it to work historically you can use TickReplay for estimating the volume on historical bars. TickReplay does not playback all ask/bid events but only the Last events and the ask/bid at the time of the last so it would not be a complete picture like you get in realtime.
Once you have the accumulated volume in the dictionaries you can later reuse that data from OnBarUpdate in whatever way you wanted. To know which price had the highest volume you would need to add your own logic which iterates the cacheDictionary to find which price had the highest volume. There is some code which sorts the volume already in that script however it is not for the use you are asking about, that logic is shown in OnRender. You can reference that code from OnRender to see how to iterate the dictionary and use the elements in the dictionary. Dictionaries are a part of C# and not specific to NinjaScript so there is a lot of education information that you can find online surrounding how to use dictionaries if that subject is foggy.
To summarize, if you directly copied the code you would need the following areas of code copied to your script to accumulate the volume at price information:
internal class VolumeInfoItem
OnStateChange -> State.DataLoaded code
GetLastBarSessionDate
OnMarketData
The following variables would be needed for the method GetLastBarSessionDate and the OnMarketData code:
private SessionIterator sessionIterator;
private DateTime sessionDateTmp = Globals.MinDate;
private SessionIterator storedSession;
private DateTime cacheSessionEnd = Globals.MinDate;
private DateTime sessionDateTmp = Globals.MinDate;
private List<int> newSessionBarIdx = new List<int>();
private List<Dictionary<double, VolumeInfoItem>> sortedDicList = new List<Dictionary<double, VolumeInfoItem>>();
private Dictionary<double, VolumeInfoItem> cacheDictionary = new Dictionary<double, VolumeInfoItem>();
private DateTime currentDate = Globals.MinDate;
private double bidPrice;
private double askPrice;
Rather than directly copying the code you may find it easier to learn from the concepts shown in OnMarketData because you really only need the data from cacheDictionary. You can further simplify the code being used by eliminating the extra code which is used to render the indicator in its custom way. The concept shown of how to accumulate the volume at price using a dictionary is the important part. The OnMarketData code is how the ask/bid prices and volumes get mapped into a dictionary.
A dictionary uses keys to store data, you can use a key which is a price and then the value for that key is the volume at that price. To simplify the code in that indicator you can remove the class VolumeInfoItem and instead just apply the volume as the value which would be a variable that looks like this:
private Dictionary<double, long> cacheDictionary = new Dictionary<double, long>();
Using a dictionary like this would look like:
if (!cacheDictionary.ContainsKey(price)) cacheDictionary.Add(price, volume);
Comment