How can I get the index position of a specific Datetime?
How can I get the index position of a specific Datetime?
29 Mar 2013, 20:17
Is it any function or an other way to get immediatly the index position of a specific Datetime?
In MT4 i use the function:
iBarShift(NULL,0, time)
So if I want to get for any bar the close price of the 1st bar of the day I use the following code:
datetime CurrentTime = Time[j]; // Current Time
int BarsCurrentTime = iBarShift(NULL,0, CurrentTime); // Bars Current Time
datetime TimeStartOfDay = CurrentTime - CurrentTime % 86400; // Time Start of Day
int BarsStartOfDay = iBarShift(NULL,0, TimeStartOfDay); // Bars Start of Day
MaCounter = BarsStartOfDay - BarsCurrentTime;
close = iClose(NULL, 0, MaCounter )
In cAlgo I can get the first bar of the Day for any bar with the next code:
MarketSeries.OpenTime[index].Date
But how can I convert the Datetime to index position ?
Thanks in Advance
Replies
Spotware
02 Jan 2014, 11:24
You can now access it easier with the GetIndexByTime or GetIndexByExactTime methods:
DateTime date = MarketSeries.OpenTime.LastValue.Date; var firstBarIndex = MarketSeries.OpenTime.GetIndexByTime(date);
/api/reference/timeseries/getindexbytime-9d11
@Spotware
lec0456
01 Apr 2013, 01:36
The index is just :
is the same variable index used to get the open time you are requesting
hope this helps buy maybe I am not understanding you question...
@lec0456