Iterating Bars object between two datetime's.
Iterating Bars object between two datetime's.
20 Apr 2021, 15:18
How can I loop between two datetime’s to get the Highest ClosePrice?
For example, in the OnBar() event, on a 1Min Backtest I want to say "get the Highest Bar ClosePrice between 6am today and 10am today".
Paul
Replies
rdebacker
22 Jul 2023, 22:06
Hello, Thank you for your answer.
I am looking for something similar but the date has to be the current day, and show this result standard for every maximum number of days in the past, for backtesting purposes .I know it is sometimes though to convert between times, timespan and datetimes and am awhere off all the functions and tricks to handle this, but
the difficulty lies within working with the ctrader algo.api.
Any ideas are very welcome.
Thanks in advance
Rafael
@rdebacker
firemyst
22 Apr 2021, 09:12
Rough pseudo logic:
DateTime startTime = new DateTime(2021,4,22,6,0,0);
int startTimeIndex = Bars.OpenTimes.GetIndexByTime(startTime);
DateTime endTime = new DateTime(2021,4,22,10,0,0);
int endTimeIndex = Bars.OpenTimes.GetIndexByTime(endTime);
double highestPrice = 0;
for (int x= startTimeIndex; x <= endTimeIndex; x++)
{
if (Bars.HighPrices[x] > highestPrice)
highestPrice = Bars.HighPrices[x];
}
@firemyst