using System;
using System.Text;
using cAlgo.API;
namespace cAlgo.Indicators
{
[Indicator]
public class MarketDepthIndicator : Indicator
{
private MarketDepth _marketDepth;
public override void Calculate(int index){}
protected override void Initialize()
{
// Get Market Depth
_marketDepth = MarketData.GetMarketDepth(Symbol);
// subscribe to event Updated
_marketDepth.Updated += MarketDepthUpdated;
}
void MarketDepthUpdated()
{
// Draw Market Depth Entries in the indicator panel
var se = new StringBuilder();
se.Append("Bid");
se.Append(" ");
se.Append("Ask");
ChartObjects.DrawText("DOM", se.ToString(), StaticPosition.TopLeft, Colors.White);
se.Clear();
se.AppendLine();
se.AppendLine();
foreach (var entry in _marketDepth.BidEntries)
{
double dVolume = Math.Round(entry.Volume / 1000000.0, 2);
string volume = string.Format("{0}{1}", dVolume, "m");
double entryPrice = entry.Price;
string askText = string.Format("{0} {1}", entryPrice.ToString("0.00000"), volume);
se.AppendLine(askText);
}
ChartObjects.DrawText("Bid", se.ToString(), StaticPosition.TopLeft, Colors.Red);
se.Clear();
se.AppendLine();
se.AppendLine();
foreach (var entry in _marketDepth.AskEntries)
{
double dVolume = Math.Round(entry.Volume / 1000000.0, 2);
string volume = string.Format("{0}{1}", dVolume, "m");
double entryPrice = entry.Price;
se.Append(" ");
string bidText = string.Format("{0} {1}", entryPrice.ToString("0.00000"), volume);
se.AppendLine(bidText);
}
ChartObjects.DrawText("Ask", se.ToString(), StaticPosition.TopLeft, Colors.Turquoise);
}
}
}