This is the code:
region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Gui.Tools;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion
//This namespace holds Indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators
{
public class TPOC : Indicator
{
private double tpoc;
private int tpocVolume;
private int tickSize;
private List<double> tpocValues;
private Plot MyPlot;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Time Point Of Value";
Name = "TPOC";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true;
}
else if (State == State.Configure)
{
tpocValues = new List<double>();
MyPlot = CreatePlot(Brushes.Blue, "TPoC");
}
}
protected override void OnBarUpdate()
{
if (CurrentBar == 0)
return;
tpoc = 0;
tpocVolume = 0;
Dictionary<double, int> priceCount = new Dictionary<double, int>();
for (int i = CurrentBar == 1 ? BarsRequiredToPlot : CurrentBar; i >= 0; i--)
{
double price = Close[i];
if (priceCount.ContainsKey(price))
priceCount[price]++;
else
priceCount[price] = 1;
}
int maxCount = 0;
double maxPrice = 0;
foreach (KeyValuePair<double, int> kvp in priceCount)
{
if (kvp.Value > maxCount)
{
maxCount = kvp.Value;
maxPrice = kvp.Key;
}
}
tpoc = maxPrice;
tpocValues.Add(tpoc);
Values[0][0] = tpocValues.Last();
MyPlot.Set(Values[0][0]);
}
}
}

Comment