Problem to Getting Actual Value of an Event each day

 

Hello Everyone! 


I need a code that print the actual number of a specific news event on opening of every candle. But it always returns "0.0"!!

Where exactly did I make mistake?


#property copyright "Copyright 2024, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+


MqlCalendarValue values[];
MqlCalendarValue value;
MqlCalendarEvent v;
double printval;
int LTFbarstotal = iBars(NULL,PERIOD_D1) ;


int OnInit()
  {
//---

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
// Check if bar is new
      int LTFbars = iBars(NULL,PERIOD_D1);
      if(LTFbarstotal != LTFbars){
      LTFbarstotal = LTFbars;



 
// Get Value by ID
      CalendarValueById(144520       ,value);
      CalendarEventById(144520   ,v);
      
      
      //Print(value.HasActualValue());
      Print("id is:", value.actual_value);
      Print("id is:" , v.id); 
  }}
//+------------------------------------------------------------------+
 
Search for "news trader" and filter (left side) for articles, CodeBase and Forum - you'll find lots of examples you can use!
 
Carl Schreiber #:
Search for "news trader" and filter (left side) for articles, CodeBase and Forum - you'll find lots of examples you can use!
Thank you so much! But I search again and find nothing! My code is so simple. Could it be problem of the server? I've checked with Amarkets and MetaQuets.
 
AlitheTrader:

I need a code that print the actual number of a specific news event on opening of every candle. But it always returns "0.0"!!

Where exactly did I make mistake?

How did you get the magic number 144520? NB. You should not never use magic numbers in your code except for magic numbers in orders for EAs ;-)

The ID in CalendarValueById is an ID of a value (specific news event record).

The ID in CalendarEventById is an ID of an event type (general/repetitive/continuous news set with the same nature, for example NFP, GDP, etc).

Both should be obtained from the calendar database, and can be equal only as a meaningless coincidence.

You can find examples of retrieval of calendar news in the docs or in the book.

The value 0 in actual_value means that the event is not yet happen (in future).

Documentation on MQL5: Economic Calendar / CalendarValueById
Documentation on MQL5: Economic Calendar / CalendarValueById
  • www.mql5.com
Get an event value description by its ID. Parameters value_id [in]  Event value ID. value [out] MqlCalendarValue type variable for receiving...
 
Stanislav Korotky #:

The value 0 in actual_value means that the event is not yet happen (in future).

Correction: The value 0 in actual_value means that the event is not indicative (not of the type CALENDAR_TYPE_INDICATOR). For future quantitative events "no value" is specified by storing LONG_MIN (-9223372036854775808) in the field.