I need get the time of a bar and price on an indicator when user clicks.
I'm triyng with this code
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "RulerIsraIndicator";
Calculate = Calculate.OnBarClose;
IsOverlay = false;
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.Realtime)
{
if (ChartControl != null)
{
foreach (ChartScale scale in ChartPanel.Scales)
{
outputLog(scale.ScaleJustification.ToString());
if (scale.ScaleJustification == ScaleJustification)
chartScale = scale;
}
ChartControl.MouseDown += OnChartMouseDown;
ChartControl.MouseUp += OnChartMouseUp;
}
}
else if (State == State.Terminated)
{
if (ChartControl != null)
{
ChartControl.MouseDown -= OnChartMouseDown;
ChartControl.MouseUp -= OnChartMouseUp;
}
}
}
private void OnChartMouseDown(object sender, MouseButtonEventArgs e)
{
// Detecta si el botón del medio del ratón fue presionado
if (e.ChangedButton == MouseButton.Left && sender is ChartControl chartControl)
{
if (chartControl != null)
{
// Obtén la posición del ratón relativa al ChartPanel
Point mousePosition = e.GetPosition(chartControl);
// Obtén el tiempo en función de la coordenada X
startTime = chartControl.GetTimeByX((int)mousePosition.X);
// Obtén el precio en función de la coordenada Y (necesita la escala de precios)
double startY = chartScale.GetValueByY( (int)mousePosition.Y);
// Registra la información de tiempo y precio
outputLog($"Coordenadas MouseDown: X={(int)mousePosition.X} Tiempo={startTime}, Precio={startY}");
}
}
}
Any idea?
Thanks

Comment