I would really like to learn how to modularize my code more which is why I am trying with something so simple as the above. But apparrently it's not simple enough for my brain. Any help would be greatly appreciated.
I have not the time to look in detail today but you are not really creating a separate module because you are declaring variables for the data in the EA but trying to populate them in the include
Hi Paul,
Thanks so much for the feedback! It's great to have access to a community that is willing to assist. To give a bit more context, what I'm ultimately trying to achieve is to get the MACD values and pass them to an external Python script for further analysis. The goal isn't just to generate signals within the EA, but to capture and analyze the data externally.
Given that, I was thinking of keeping the values in a modular format so that they can be sent outside of MetaTrader to Python using http. Do you think creating a class for this would still work, or would you recommend another approach for easy transfer of those values?
Looking forward to your thoughts!
EDIT*Let me clarify my broader goal. The reason I'm separating the MACD module (and eventually other indicators) is because I want to collect their data for post-processing in Python. Instead of using the indicator signals directly within MetaTrader, I’m aiming to send the raw values (like the MACD line, signal line, and histogram) to an external Python script for further analysis.
In this context, I’m trying to modularize the MACD logic so that it can easily feed data to Python, but it seems like the current approach isn’t fully achieving that separation. Would you recommend creating a class for this purpose, even if my end goal is to funnel the indicator data out for Python processing? If so, how would you structure the process for sending this data outside of MetaTrader efficiently if I wanted to keep each indicator as a separate module?
Thank you for your time in reading and replying, I really appreciate it.
Hi Paul,
Thanks so much for the feedback! It's great to have access to a community that is willing to assist. To give a bit more context, what I'm ultimately trying to achieve is to get the MACD values and pass them to an external Python script for further analysis. The goal isn't just to generate signals within the EA, but to capture and analyze the data externally.
Given that, I was thinking of keeping the values in a modular format so that they can be sent outside of MetaTrader to Python using http. Do you think creating a class for this would still work, or would you recommend another approach for easy transfer of those values?
Looking forward to your thoughts!
EDIT*Let me clarify my broader goal. The reason I'm separating the MACD module (and eventually other indicators) is because I want to collect their data for post-processing in Python. Instead of using the indicator signals directly within MetaTrader, I’m aiming to send the raw values (like the MACD line, signal line, and histogram) to an external Python script for further analysis.
In this context, I’m trying to modularize the MACD logic so that it can easily feed data to Python, but it seems like the current approach isn’t fully achieving that separation. Would you recommend creating a class for this purpose, even if my end goal is to funnel the indicator data out for Python processing? If so, how would you structure the process for sending this data outside of MetaTrader efficiently if I wanted to keep each indicator as a separate module?
Thank you for your time in reading and replying, I really appreciate it.
if all you are doing is gathering the MACD data to send to python what is the purpose of the include file? MACD calcs are already separated in an indicator, just get the values from the indicator in your EA and send them to your python, seems you are adding an extra step for no gain
if all you are doing is gathering the MACD data to send to python what is the purpose of the include file? MACD calcs are already separated in an indicator, just get the values from the indicator in your EA and send them to your python, seems you are adding an extra step for no gain
Hi Paul,
Thanks again for your input, I really appreciate the time you're taking to help me out!
Based on what you’ve said, it makes sense to call the MACD data directly within the EA and send it to Python without adding any extra steps. I’ve streamlined my approach as you suggested, and it’s working well for now.
However, I wanted to get your thoughts on something else — would this approach still be efficient and sustainable if I were working with 20 or 30 different indicators? If I were to call all the values directly from within the EA and send them to Python, do you think that could potentially overload the system, or would it be fine?
In my experience with Python, I typically modularize the code by breaking files apart to make it more scalable and reusable across different contexts. I’m still new to MQL5, though, so I’m wondering if it would be better to keep things as they are in a single EA or if it might make sense to separate the indicators into various include files for the sake of clarity and scalability, even if the only goal is to gather data for external analysis in Python.
Looking forward to hearing your thoughts!
Best regards,
Jacques
Hi Paul,
Thanks again for your input, I really appreciate the time you're taking to help me out!
Based on what you’ve said, it makes sense to call the MACD data directly within the EA and send it to Python without adding any extra steps. I’ve streamlined my approach as you suggested, and it’s working well for now.
However, I wanted to get your thoughts on something else — would this approach still be efficient and sustainable if I were working with 20 or 30 different indicators? If I were to call all the values directly from within the EA and send them to Python, do you think that could potentially overload the system, or would it be fine?
In my experience with Python, I typically modularize the code by breaking files apart to make it more scalable and reusable across different contexts. I’m still new to MQL5, though, so I’m wondering if it would be better to keep things as they are in a single EA or if it might make sense to separate the indicators into various include files for the sake of clarity and scalability, even if the only goal is to gather data for external analysis in Python.
Looking forward to hearing your thoughts!
Best regards,
Jacques
splitting your code into mulptile files via includes will make no performance difference, the includes are compiled into the same ex5. but if you wan to spearate and tidy then use classes as mentioned before, but also as I said before I see little point when you are simply after indicator data.
indicators will run in their own thread so calling them from the EA is fine, the only other choice you have is to mod the indicator to send the data directly to your python.
what you really need to think about is when you are doing this, is it a one-off run to populate python or are you planning sending data realtime every tick or new bar and design accordingly
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hey everyone,
I'm facing an issue that’s been driving me a bit mad, and I’m hoping someone here can shed some light. I have a simple Expert Advisor (EA) where I'm using the MACD indicator. When I run the MACD inside my core module, everything works as expected. The MACD values are retrieved successfully, and the logic performs as intended.
However, when I attempt to modularize the MACD logic into a separate file (to keep things cleaner and more organized), the MACD no longer works. Specifically, the handle initializes successfully, but it fails to retrieve MACD values. It seems as though the MACD isn’t being properly called or calculated when moved outside the core module.
I know it’s likely something small that I’m overlooking or a minor misunderstanding in how the code is structured or how MT5 handles the indicator across modules. But I can’t even figure out what to search for because I don’t fully understand why this isn’t working when it should.
Here’s the self-contained version of the code where everything is in the same module and works fine:
And then here is my attempt to modularize it:
Core Module:
MACDTest.mqh
As you can see, I've butchered the code by adding extreme logging features, but I've still not been able to figure out where the flow of data is breaking. It seems as if the indicator is not really initializing properly.
I would really like to learn how to modularize my code more which is why I am trying with something so simple as the above. But apparrently it's not simple enough for my brain. Any help would be greatly appreciated.