facing new issue on indicator not showing real time value repeated count it show's same random number . i am attact screenshot for you ref . pls tell how to solve this
-------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Windows.Media;
using NinjaTrader.NinjaScript;
using NinjaTrader.NinjaScript.DrawingTools;
using NinjaTrader.NinjaScript.Indicators;
namespace NinjaTrader.NinjaScript.Indicators
{
public class TickRepetitionCounter : Indicator
{
private Dictionary<double, int> tickCounts;
private double lastTickValue;
private DateTime lastTradingDate;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = "Tick Repetition Counter";
Name = "TickRepetitionCounter";
Calculate = Calculate.OnEachTick;
IsOverlay = true;
tickCounts = new Dictionary<double, int>();
}
}
protected override void OnBarUpdate()
{
DateTime currentTradingDate = Time[0].Date;
if (currentTradingDate != lastTradingDate)
{
tickCounts.Clear();
lastTradingDate = currentTradingDate;
}
double currentTickValue = Close[0];
int currentTickCount = tickCounts.ContainsKey(currentTickValue) ? tickCounts[currentTickValue] : 0;
tickCounts[currentTickValue] = currentTickCount + 1;
lastTickValue = currentTickValue;
PrintTickCounts();
}
private void PrintTickCounts()
{
RemoveDrawObjects();
int yOffset = 0;
foreach (KeyValuePair<double, int> tickCount in tickCounts)
{
string label = "Value: " + tickCount.Key + "\tNumber of Times Repeated: " + tickCount.Value;
Draw.Text(this, label, yOffset.ToString(), 0, tickCount.Key, Brushes.White);
yOffset -= 15;
}
}
}
}
Comment