Pause expert before news time

 

Hi guys I'm writing an expert and I need it to stop opening positions and close all positions and orders 1hour before important news time how can I do it?

I searched a lot, all is about using MQLcalendar but there is not such a file named "MqlCalendar.mqh" in my metatrader5 I tried to reinstall and for different brokers but still missing!

could you help me how should I do it exactly? 

here is the code but I get error can't open "...\MQL5\Include\MqlCalendar.mqh" include file

I searched the file in all folders but no such file found.

#include <MqlCalendar.mqh>
void OnTick()
{

    string symbol = Symbol();

    datetime currentTime = TimeCurrent();

    int stopTradingBeforeNews = 3600; // 1 hour
    
    int resumeTradingAfterNews = 3600; // 1 hour
    
    MqlCalendarValue calendarValues[];
    if(CalendarValueHistory(calendarValues, currentTime, currentTime + 86400, symbol))
    {
        for(int i = 0; i < ArraySize(calendarValues); i++)
        {
            if(calendarValues[i].importance == CALENDAR_IMPORTANCE_HIGH)
            {
                // Check if the current time is within the time window before or after the news event
                if(currentTime >= calendarValues[i].time - stopTradingBeforeNews && currentTime <= calendarValues[i].time + resumeTradingAfterNews)
                {
                    // Stop trading
                    return;
                }
            }
        }
    }    
}
 
sepidezare:

Hi guys I'm writing an expert and I need it to stop opening positions and close all positions and orders 1hour before important news time how can I do it?

I searched a lot, all is about using MQLcalendar but there is not such a file named "MqlCalendar.mqh" in my metatrader5 I tried to reinstall and for different brokers but still missing!

could you help me how should I do it exactly? 

here is the code but I get error can't open "...\MQL5\Include\MqlCalendar.mqh" include file

I searched the file in all folders but no such file found.


What do you expect from the file "MqlCalendar.mqh"??

I have not heard of such file jet. It doesn't seem to be required for the code you have shown. Try asking chatGPT why she wants that file in "your" code.


 
Dominik Egert #:

What do you expect from the file "MqlCalendar.mqh"??

I have not heard of such file jet. It doesn't seem to be required for the code you have shown. Try asking chatGPT why she wants that file in "your" code.


it's needded for getting calendarValues

so tell me how can I get news times and stop expert before news?! 

 
sepidezare #:

it's needded for getting calendarValues

so tell me how can I get news times and stop expert before news?! 

You don't need it.

In MQL5 it is already supported, for MQL4 you need something from codebase or from the forum to integrate some calendar access into your EA.

Have you asked chatGPT why she wants that file in your code?
 
Dominik Egert #:
You don't need it.

In MQL5 it is already supported, for MQL4 you need something from codebase or from the forum to integrate some calendar access into your EA.

Have you asked chatGPT why she wants that file in your code?

Are you trying to help or what??!! I tried to get help from it but it doesn't work so I'm here to ask people!

if you don't know how to do it or just don't want to help save your energy please and don't waste my time

 
sepidezare #:

Are you trying to help or what??!! I tried to get help from it but it doesn't work so I'm here to ask people!

if you don't know how to do it or just don't want to help save your energy please and don't waste my time

Nope... That's not how it works. Attitude adjustment please.

Maybe I havent stated precisely what I meant.

With "You don't need it" I was referring to the file MqlCalendar.mqh. You don't need that file for MQL5, it is built-in. See documentation please:


For MQL4, you need some implementation from a "third-party", which you can find on the forum (here somewhere) or in Code-Base, please do a search to find an economic calendar implementation that suits your needs.

But, either way, I have still no idea what MqlCalendar.mqh you (or the code you provided) is referring to, as it is not commonly known...

 
Dominik Egert #:
Nope... That's not how it works. Attitude adjustment please.

Maybe I havent stated precisely what I meant.

With "You don't need it" I was referring to the file MqlCalendar.mqh. You don't need that file for MQL5, it is built-in. See documentation please:


For MQL4, you need some implementation from a "third-party", which you can find on the forum (here somewhere) or in Code-Base, please do a search to find an economic calendar implementation that suits your needs.

But, either way, I have still no idea what MqlCalendar.mqh you (or the code you provided) is referring to, as it is not commonly known...

yeah thanks I resolved it with  economic calendar

Reason: