Skip to content

TimeSeries.GetIndexByExactTime

method · TimeSeries · cAlgo.API

DesktopCLICloud

Find the index in the different time frame series.

Definition

int GetIndexByExactTime(DateTime dateTime)
timeSeries.GetIndexByExactTime(dateTime: DateTime) -> int

Parameters

Name C# type Python type Description
dateTime DateTime DateTime The open time of the bar at this index

Returns int — Exact index of bar at passed time

Examples

var hourlyBars = MarketData.GetBars(TimeFrame.Hour);
var hourlyIndex = hourlyBars.OpenTimes.GetIndexByExactTime(Bars.OpenTimes.LastValue);
if (hourlyIndex >= 0)
    Print("Hourly bar with the same open time: {0}", hourlyBars[hourlyIndex].Close);
else
    Print("No hourly bar opened exactly at {0}", Bars.OpenTimes.LastValue);
hourlyBars = api.MarketData.GetBars(TimeFrame.Hour)
hourlyIndex = hourlyBars.OpenTimes.GetIndexByExactTime(api.Bars.OpenTimes.LastValue)
if hourlyIndex >= 0:
    api.Print(f"Hourly bar with the same open time: {hourlyBars[hourlyIndex].Close}")
else:
    api.Print(f"No hourly bar opened exactly at {api.Bars.OpenTimes.LastValue}")