Hi
Use the the CopyRates() function for the data of the last incomplete BAR or complete BARS.
https://www.mql5.com/en/docs/series/copyrates
https://www.mql5.com/en/docs/constants/structures/mqlrates
Use the SymbolInfoTick() function for the data of the most recent tick.
https://www.mql5.com/en/docs/marketinformation/symbolinfotick
https://www.mql5.com/en/docs/constants/structures/mqltick
// Info of the last incomplete BAR //--------------------------------- // Rates Structure for the data of the Last (incomplete) BAR MqlRates BarData[1]; CopyRates(Symbol(), Period(), 0, 1, BarData); // Use the variable for your checks. BarData[0].close BarData[0].real_volume BarData[0].time BarData[0].spread // Info of the last tick. //----------------------- // The BID price. static double dBid_Price; // To be used for getting recent/latest price quotes MqlTick Latest_Price; SymbolInfoTick(Symbol() ,Latest_Price); dBid_Price = Latest_Price.bid; // Current Bid price.

- www.mql5.com
Thanks for your reply
I am new in MQL , can you help me how to Alert the latest tick "hour period" high and low price.
Use this example:
// Info of the last incomplete BAR //--------------------------------- // Rates Structure for the data of the Last (incomplete) BAR MqlRates BarData[1]; CopyRates(Symbol(), Period(), 0, 1, BarData); // Copy the data of last (incomplete BAR) // Date and Time variable. //------------------------ MqlDateTime TimePeriod; // MQL time structure. TimeLocal(TimePeriod); // Use current PC time for time variable. Alert("HIGH = ", BarData[0].high, " LOW = ", BarData[0].low, " Hour of the day: ", TimePeriod.hour); // Or use the print() function. Print("HIGH = ", BarData[0].high, " LOW = ", BarData[0].low, " Hour of the day: ", TimePeriod.hour);
Again many lot of thanks ,
but I print this code
Alert("HIGH = ", BarData[0].high, " LOW = ", BarData[0].low, " Hour of the day: ", TimePeriod.hour, " Date Time is : ",TimeToStr(BarData[0].time,TIME_DATE|TIME_SECONDS));
the output is : HIGH = 1.2589 LOW = 1.2557 Hour of the day: 6 Date Time is : 2012.06.14 09:00:00
below the current tick info .. it's not the same .. what is the problem ?
Hi
This piece of code is not correct:
"TimeToStr(BarData[0].time,TIME_DATE|TIME_SECONDS"
read these links:
https://www.mql5.com/en/docs/basis/types/integer/datetime
https://www.mql5.com/en/docs/dateandtime
For example, try:
// Shows the computer time: Alert("HIGH = ", BarData[0].high, " LOW = ", BarData[0].low, " Hour of the day: ", TimePeriod.hour, " time: ", TimeLocal()); // Shows the broker server time: Alert("HIGH = ", BarData[0].high, " LOW = ", BarData[0].low, " Hour of the day: ", TimePeriod.hour, " time: ", TimeCurrent());

- www.mql5.com
again and again many thanks and I am happy that u contact with me
always the hight and low is the same
I run the script all the day and it give me
HIGH = 1.2589 LOW = 1.2557 Hour of the day: 23 time: 1445900717
and in the morning it's the same
HIGH = 1.2589 LOW = 1.2557 Hour of the day: 6 Date Time is : 2012.06.14 09:00:00
find below my code "all Code" should I include something ????
void OnStart()
{
// Info of the last incomplete BAR
//---------------------------------
// Rates Structure for the data of the Last (incomplete) BAR
MqlRates BarData[1];
CopyRates("EURUSD", Period(), 0, 1, BarData); // Copy the data of last (incomplete BAR)
// Date and Time variable.
//------------------------
MqlDateTime TimePeriod; // MQL time structure.
TimeLocal(TimePeriod); // Use current PC time for time variable.
// Alert("HIGH = ", BarData[0].high, " LOW = ", BarData[0].low, " Hour of the day: ", TimePeriod.hour, " Date Time is : ",TimeToStr(BarData[0].time,TIME_DATE|TIME_SECONDS));
Alert("HIGH = ", BarData[0].high, " LOW = ", BarData[0].low, " Hour of the day: ", TimePeriod.hour, " time: ", TimeLocal());
// Or use the print() function.
// Print("HIGH = ", BarData[0].high, " LOW = ", BarData[0].low, " Hour of the day: ", TimePeriod.hour);
}
When I run this code in a custom indicator/file, I receive the correct prices and time.
You use it in a Expert Advisor code/file.
Run this code in a custom indicator. Try if it works.
//+------------------------------------------------------------------+ //| Test.mq5 | //| Copyright 2013, MetaQuotes Software Corp. | //| http://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2013, MetaQuotes Software Corp." #property link "http://www.mql5.com" #property version "1.00" #property indicator_chart_window //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { // Info of the last tick. //----------------------- // The BID price. static double dBid_Price; // To be used for getting recent/latest price quotes MqlTick Latest_Price; SymbolInfoTick(Symbol() ,Latest_Price); dBid_Price = Latest_Price.bid; // Current Bid price. // Info of the last incomplete BAR //--------------------------------- // Rates Structure for the data of the Last (incomplete) BAR MqlRates BarData[1]; CopyRates(Symbol(), Period(), 0, 1, BarData); // Copy the data of last (incomplete BAR) // Date and Time variable. //------------------------ MqlDateTime TimePeriod; // MQL time structure. TimeLocal(TimePeriod); // Use current PC time for time variable. // Shows the computer time: Alert("HIGH = ", BarData[0].high, " LOW = ", BarData[0].low, " Hour of the day: ", TimePeriod.hour, " time: ", TimeLocal()); // Shows the broker server time: Alert("HIGH = ", BarData[0].high, " LOW = ", BarData[0].low, " Hour of the day: ", TimePeriod.hour, " time: ", TimeCurrent()); // Or use the print() function. // Print("HIGH = ", BarData[0].high, " LOW = ", BarData[0].low, " Hour of the day: ", TimePeriod.hour); return(rates_total); } //+------------------------------------------------------------------+

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi every body ,
I tried to use iTime
iTime("EURUSD",PERIOD_H1,0)
it give me 2012.06,14 09:00:00
but I need the current candle information. what I have to do ?