I'm a bit new to NinjaScript, and trying to figure out how to plot contract volume on a chart.
I was able to create a template with the wizard that plots a line, and now I need to calculate max volume at any given price in order to incert that value into this template.
I was looking at the VolumeProfile indicator for ideas, but not certain how to convert this function to return the price level with maximum recorded volume for the duration of the contract.
private void OnMarketData(object sender, MarketDataEventArgs e) { if (e.MarketDataType == MarketDataType.Ask) { askPrice = e.Price; return; } else if (e.MarketDataType == MarketDataType.Bid) { bidPrice = e.Price; return; } else if (e.MarketDataType != MarketDataType.Last || ChartControl == null || askPrice == 0 || bidPrice == 0) return; if (allHours == 0) { if (ChartControl.SessionBegin.Hour == 0 && ChartControl.SessionBegin.Minute == 0 && ChartControl.SessionEnd.Hour == 0 && ChartControl.SessionEnd.Minute == 0) allHours = 1; else allHours = 2; } if (allHours == 2) { long currentTimeTicks = DateTime.Now.TimeOfDay.Ticks; if (currentTimeTicks < ChartControl.SessionBegin.TimeOfDay.Ticks || currentTimeTicks > ChartControl.SessionEnd.TimeOfDay.Ticks) return; } double price = e.Price; int volume = e.Volume; if (!volumeInfo.ContainsKey(price)) volumeInfo.Add(price, new VolumeInfoItem()); VolumeInfoItem volumeInfoItem = volumeInfo[price]; if (price >= askPrice) volumeInfoItem.up += volume; else if (price <= bidPrice) volumeInfoItem.down += volume; else volumeInfoItem.neutral += volume; }
Comment