ChartMouseEventArgs.BarIndex
property · ChartMouseEventArgs · cAlgo.API
DesktopCLICloud
Gets the exact bar index of the mouse event.
Environment behaviour
CLI — not supported. Never raised in the CLI: the events that pass it never fire there (ChartArea.MouseDown, ChartArea.MouseEnter, ChartArea.MouseLeave and more).
Cloud — not supported. Never raised in the cloud: the events that pass it never fire there (ChartArea.MouseDown, ChartArea.MouseEnter, ChartArea.MouseLeave and more).
Definition
public double BarIndex {get;}
chartMouseEventArgs.BarIndex: float
Returns double
Examples
protected override void OnStart()
{
Chart.MouseDown += OnChartMouseDown;
}
private void OnChartMouseDown(ChartMouseEventArgs args)
{
var barIndex = (int)Math.Round(args.BarIndex);
Chart.DrawVerticalLine("clickedBar", barIndex, Color.Yellow);
Print("Exact bar index: {0}, nearest bar: {1}", args.BarIndex, barIndex);
}
def on_start(self):
api.Chart.MouseDown += self.on_chart_mouse_down
def on_chart_mouse_down(self, args):
bar_index = int(round(args.BarIndex))
api.Chart.DrawVerticalLine("clickedBar", bar_index, Color.Yellow)
api.Print(f"Exact bar index: {args.BarIndex}, nearest bar: {bar_index}")