using System.Windows.Media;
using NinjaTrader.Gui.Chart;
using NinjaTrader.NinjaScript;
using NinjaTrader.NinjaScript.DrawingTools;
using GuiTools = NinjaTrader.Gui.Tools;
namespace NinjaTrader.NinjaScript.Indicators
{
public class PriceLevelCounter : Indicator
{
private Dictionary<double, int> tickCounts;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = "Price Level Counter";
Name = "PriceLevelCounter";
IsOverlay = false;
DisplayInDataBox = true;
Calculate = Calculate.OnPriceChange;
}
else if (State == State.DataLoaded)
{
tickCounts = new Dictionary<double, int>();
}
}
protected override void OnBarUpdate()
{
if (tickCounts.ContainsKey(Close[0]))
{
tickCounts[Close[0]]++;
}
else
{
tickCounts.Add(Close[0], 1);
}
}
protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
{
int count = 0;
foreach (var kvp in tickCounts)
{
double priceLevel = kvp.Key;
count++;
string text = string.Format("{0}: {1}", priceLevel, kvp.Value);
Draw.TextFixed(this, "Count" + count, text, TextPosition.BottomRight, Brushes.White, new GuiTools.SimpleFont("Arial", 8), Brushes.Transparent, Brushes.Transparent, 0);
}
}
}
}
-------------------------------------------------------------------------------------
i am plan to design my indicator is each price level how many time LTP repeated and repeated count
but price and repeated count overlap . (for your clear view i put in 300px).pls how to solve this overlap
i want this type of output in my chart
5040 304
5041 234
5043 221
5044 231
5045 199
....... .....
....... .....
....... .....
....... .....
....... .....

Comment