Object Oriented Programming + mqh files
Object Oriented Programming
https://www.mql5.com/en/docs/basis/oop
https://www.mql5.com/en/docs/basis/types/classes
(These are just a couple of basic links to documentation. You will also need some educational literature to learn OOP from scratch)
mqh files
Object-oriented programming is intended (among other things) to combine/link/wrap data (your global variable) and methods (your function) into one object.
Start simple - just combine your function and variable into a class or structure object. It's not difficult at all.
class CYourFirstClass { private: bool NFP; public: void initialize(bool a_nfpValue); bool NFPDate(); }; bool CYourFirstClass::NFPDate(void) { //... bool check = false; if(NFP==false) return check; //... return check; } void CYourFirstClass::initialize(bool a_nfpValue) { NFP = a_nfpValue; }
I know nothing about object oriented programming but will look into it thanks for the info
You are ready to start using OOP. Because you have independently come to the need to unite data and the code that works with it. You yourself have just formulated this need.
I started my acquaintance with OOP from a similar situation - I wanted to split the code into files and I had a problem with global variables.
You are ready to start using OOP. Because you have independently come to the need to unite data and the code that works with it. You yourself have just formulated this need.
I started my acquaintance with OOP from a similar situation - I wanted to split the code into files and I had a problem with global variables.
it is nice to hear someone once was in a similar path as me. Thanks for the kind word sir, it has been awhile
Now is the best time for you to do this. Your first task is to combine the NFP variable and the NFPDate function into a class.
Here's a good article to start with, in my opinion:
https://www.mql5.com/en/articles/351
Because you immediately start using OOP to implement a library of functions:
Creating Libraries of Functions
The first and the most simple application of OOP is creating your own libraries of frequently used functions. Of course, you can simply store these functions in an include file (mqh). When you well need a function, simply include a file and call this function. However, if you program long enough you can can collect a huge amount of functions, so that it would be difficult to remember their names and purpose.
You can collect functions in different files, splitting them into categories based on purpose. For example, functions of working with arrays, functions of working with string, functions of calculating orders, etc. In the last sentence the word "category" can be replaced by the word "classes". The meaning remains the same, but we will come closer to the topic - Object-Oriented Programming.
Below is an example of a bad article for a beginner (in my subjective opinion) because the author throughout the article simply describes some complex terms using other complex terms, confusing the beginner and creating the false impression that OOP is very difficult. It's like a student's essay who just combined information from Google without understanding it.
Now is the best time for you to do this. Your first task is to combine the NFP variable and the NFPDate function into a class.
Here's a good article to start with, in my opinion:
https://www.mql5.com/en/articles/351
Because you immediately start using OOP to implement a library of functions:
Below is an example of a bad article for a beginner (in my subjective opinion) because the author throughout the article simply describes some complex terms using other complex terms, confusing the beginner and creating the false impression that OOP is very difficult. It's like a student's essay who just combined information from Google without understanding it.
Learning through it right now, apppreciate it for going this far for some random person

- 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 Experts, I have trade news filters that I think can be better coded for multiple EAs usage.
Currently copy paste for each EAs I am aware it is a bad practice.
Tried doing a library for it but this function required global variable so that does not work
Below is one of the function. In this case NFP is the global variable.
Is there experts experienced something similar maybe can point out my silly mistake
Thanks for your attention
Amir