MQL Calendar value

 

The exact valueHey all, 

I would like to ask how to get the exact values of mql calendar ?  I already got the value and divided it with 1 million as suggested, but it is still rounding up. I tried typecasting as well but still the same. In this case, the exact value is 46.5, but it keeps producing 46 as the value.

long prevValue(){
MqlCalendarEvent event;
MqlCalendarValue values[];
string name = EventToString(eventName);
long prev= 0;
datetime startTime = TimeTradeServer() - PeriodSeconds(PERIOD_D1);
datetime endTime = TimeTradeServer() + PeriodSeconds(PERIOD_D1);
int valuesTotal = CalendarValueHistory(values,startTime,endTime,NULL,NULL);

   for (int i = 0; i < valuesTotal; i++){
       MqlCalendarEvent event;
       CalendarEventById(values[i].event_id,event);
        if(values[i].time >= startTime && values[i].time <= endTime){
            if(event.name == EventToString(eventName)){
               prev = (values[i].prev_value)/1000000;
               }
         }
     }
   return prev;
}
Documentation on MQL5: Math Functions / MathFloor
Documentation on MQL5: Math Functions / MathFloor
  • www.mql5.com
The function returns integer numeric value closest from below. Parameters val [in]  Numeric value. Return Value A numeric value representing...
 
donnacitra98:

Hey all, 

I would like to ask how to get the exact values of mql calendar ?  I already got the value and divided it with 1 million as suggested, but it is still rounding up. I tried typecasting as well but still the same. In this case, the exact value is 46.5, but it keeps producing 46 as the value.

Try to cast to double before division or simply make the constant double:

(values[i].prev_value)/1000000.0
Also change the type of prev (and the return of the function itself) to double from long.
 
Stanislav Korotky #:

Try to cast to double before division or simply make the constant double:

Also change the type of prev (and the return of the function itself) to double from long.

Thank you for your response. Before you response, I also tried using GetPreviousValue() and it works as well. However, when I get the valued needed, why is some value so different with other sources ? Is the value reliable in MQLCalendar ? 

 
donnacitra98 #:

Thank you for your response. Before you response, I also tried using GetPreviousValue() and it works as well. However, when I get the valued needed, why is some value so different with other sources ? Is the value reliable in MQLCalendar ? 

Please, show an example of the problem.