HOW TO STOP OTHER/ALL EXPERT ADVISOR BY MY EXPERT ADVISOR
-
I invite all members to solve this thing, especially to the most experienced but I don't mention names
-
I'm not one of those most experienced members, but I guess the only way a EA can operate on another EA is by using terminal variables. Miro and roar would probably can offer more detailed info here.
-
@ambrogio I'm not experienced at all
yet I will write here... found these.
I posted this on your other thread as well, so this is a duplicate.
Maybe someone more experienced can compile a working Custom mql from all these examples. Looking at all these, I guess the chart way is the way.
.................................
@ambrogio I did some documentation and I found all these...There is some code down here, and I'm thinking setting up a boolean if that's possible.
https://docs.mql4.com/runtime/tradepermission
But closing Auto trading feature would terminate the handler EA itself.
So maybe trying to get the magic number of the running EAs and terminate those only would be great. Then in this Handler EA, you could even set up some conditions to check for a certain market context, and make some kind of a Manager EA.
Also, another way to go, would be to close certain charts. Closing the chart with some EA, closes the respective EA as far as I know.
... Or I found this
// Deletes the Expert Advisor form the appropriate chart
bool EXPERT::Remove( const long Chart_ID = 0 );
don't know if this is for mt4 or mt5.
Also...
It says here
https://www.metatrader4.com/en/trading-platform/help/autotrading/experts/experts_remove
that "the expert can be removed from the chart at profile or template change" so there could be a function to change template on some chart, also.
Examples here
https://www.mql5.com/en/docs/chart_operations/chartapplytemplate -
Further digging
I found this library (mt5) for the experts remove function I mentioned.
As I see, this function also needs to specify chart ID.
So... for mt4 and maybe mt5 as well if no libraries, the solution would be to change template (with EA, without EA? - is this possible? or other random template?), then revert to the one with EA (if possible) if market context is favorable (as seen by Manager EA). That would be great
Just some Ideas, didn't had time right now to do the tests and try these out. -
Interesting. Would the 'Apply template' block solve the problem, then?
-
@l-andorrà @ambrogio ... Yes, it seems so
I checked and manually changed the template of a chart with EA, and the EA was removed. Then created a template with EA on it, and changed back and forth with same template without EA and it works
It looks like the Ea is loaded and unloaded, yet it is the same template saved two times, with and without EA.
So yes it seems that block would solve it
Overlooked that block. Thanks. -
@cpxiom the problem is: how to apply a template (by my expert) on the chart that is running the expert to disable
-
@ambrogio Hello. Found and did something

So this (the shared project) changes the template for all open charts to default.tpl
You can make another tpl and change the custom mql code to open that, or save something different as default.
https://fxdreema.com/shared/TsP1m8SibWith a duplicate and some conditions and flags? (didn't work with flags yet, personally) you could enable and disable EAs on all charts.
For further development, it would be great if it were possible to enable and disable selectively, but didn't find yet how are the chart IDs numbered... Or by symbol? don't know.
Anyway, hope this helps
-
This is a very intersting topic. Would you mind developing a bit more? I think this would be a very useful and (maybe) a tutorial-like one.

-
@cpxiom thank you, but i'm not a coder at all

-
@ambrogio But that project (https://fxdreema.com/shared/TsP1m8Sib) already works for all charts, as it is. Closes all EAs, on all open charts, by changing all charts to default template, which is without EA, saved in mt4

The other conditions I was referring to, were in fxdreema (where I'm the one to learn from you :))
For example. In mt4 you can set up a chart without EA, and save template as "DisableEA", and then set up the same chart with EA (the one you said it's not fxdreema), and save that as template as well, and name it "EnableEA".
Then, you can use this project (https://fxdreema.com/shared/YNPLcdZWd) with some conditions. I put here some hours, as example, (didn't test this though).
For the new project, in Custom Mql block, all I did, was to change "default.tpl" where it writes: ChartApplyTemplate(currChart,"default.tpl");
to EnableEA, and DisableEA. Those are the templates you save in mt4.PS: I'm not a coder, also
(I'm a graphic designer as job) and the code for the Mql block is not mine, I found it, as I said. But it's great that it works, and I was so glad I could help 
I started to understand a bit what's going on in mq4 code, but I'm still learning. Managed to modify some indicators, that's all

-
@ambrogio wait... On the new project I shared, the branch with EnableEA will not work... as all charts are changed to DisableEA template.
So the fxdreema EA is discarded as well, so the EnableEA will not get executed.
But keep the other one, and put some other condition, like a time to execute, not range, for example. I guess I'm just tired a bit.So this is the downside that it closes all EAs on all charts... not selectively. But further than this, it is well over my head
Maybe others could help.Also, there is this thread regarding terminal variables as @l-andorrà suggested, but don't know if it works with non fxdreema EAs. https://fxdreema.com/forum/topic/5703/terminate-other-eas
-
@cpxiom thank you, i understood and i'm working on it
I had already read this discussion in the past https://fxdreema.com/forum/topic/5703/terminate-other-eas but it was not helpful -
@CPxiom thank you works very well!!!
-
@ambrogio That's so great

Yesterday I researched a bit some possibilities to change selectively... But had no success.
I did found something that would read the string of the symbol, but honestly, don't know where to put that
so the loop through the open charts would change only the specified symbol.
Another way to go about this, would be to search for a particular indicator with this function. ChartIndicatorName... so you could distinguish some charts by other charts with some indicator, and change the template for only those.But as I said, this is well over my head, and maybe others could help with this.
Because it would be great, to not close all the EAs... in case of maybe having an fxdreema EA that has good conditions and can run nonstop, let's say.
-
A little update. This works for particular chart case.
https://fxdreema.com/shared/oWBuqM6Hd