I think answer is :
datetime dtTime = iTime(_Symbol,_Period, highestPrice);
How to get what is the datetime of the iHigh in format YYYY-mm-dd 03:12:01?
If you already know the shift (bar/candle) of the high that you're interested in, which is necessary if you're calling iHigh, then what you need is to call iTime for that shift to retrieve the datetime value, and then call TimeToString with the 2nd parameters being TIME_DATE|TIME_SECONDS and save it into a string variable, which will look like:
YYYY.mm.dd hh:mm:ss
For the specific format that you want, you would have to do a StringReplace and replace "." with "-"
Another alternative is to use the MqlDateTime struct. This is done by first getting the datettime value, declaring a variable of MqlDateTime type, then calling TimeToStruct to fill the values of the MqlDateTime variable with the datetime value.
This method is recommend if you require more advanced date formatting.
- www.mql5.com
double highestPrice= iHigh(Symbol(),0,iHighest(NULL,0,MODE_HIGH,1900,2)); double lowestPrice= iLow(Symbol(),0,iLowest(NULL,0,MODE_LOW,1900,2)); datetime highestDateTime = iTime(_Symbol,_Period, highestPrice ); // this output 2015.12.01 03:05 datetime lowestDateTime = iTime(_Symbol,_Period, lowestPrice ); // this output 1420141800
How to make lowestDateTime be the same format as highestDateTime?
From the code you posted, highestDateTime is the same format as lowestDateTime. This is because they're both of the datetime type.
datetime values in MQL are seconds elapsed starting from January 1st, 1970.
To convert it to something we can understand, therefore, you must use TimeToString
string highestDate = TimeToString(highestDateTime); // date in format of YYYY.mm.dd hh:mm string lowestDate = TimeToString(lowestDateTime); // date in format of YYYY.mm.dd hh:mm
- www.mql5.com
From the code you posted, highestDateTime is the same format as lowestDateTime. This is because they're both of the datetime type.
datetime values in MQL are seconds elapsed starting from January 1st, 1970.
To convert it to something we can understand, therefore, you must use TimeToString
Thank you very much.
This return the latest 2nd bar time, not return the highest bar time. How to return the highest bar time?
Ok found the solution :
double HighPrice = iHigh(Symbol(),0,iHighest(NULL,0,MODE_HIGH,1900,2)); double LowPrice = iLow(Symbol(),0,iLowest(NULL,0,MODE_LOW,1900,2)); int forHighTime = iHighest( NULL,0,MODE_HIGH,1900); int forLowTime = iLowest( NULL,0,MODE_LOW,1900); datetime highestDateTime = iTime(_Symbol,_Period, forHighTime); datetime lowestDateTime = iTime(_Symbol,_Period, forLowTime);
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
How to get what is the datetime of the iHigh in format YYYY-mm-dd 03:12:01?