MonitorEA

Rene's trading Expert Advisors
Post Reply
User avatar
renexxxx
Trader
Posts: 860
Joined: Sat Dec 31, 2011 3:48 am

MonitorEA

Post by renexxxx »

This is a little spin-off project, to partly address a requirement that was discussed in the Stuck in loop and stuck in pause manager???

MonitorEA collects PINGs, sent by other charts, with the purpose of being able to detect that one of these other charts has stopped running (for whatever reason). An EA can stop PINGing if (1) it crashed with a runtime error (eg. zero divide) (2) it is running out or memory (3) it is stuck in an endless loop (4) ... others. Since each chart has only one processing thread, code in the OnTimer() event handler can not run if the thread is stuck in the OnTick() event handler, and vice versa.

It is important to understand that this MonitorEA has a limited use case: It will NOT help you if:
  • Empty4 hangs or crashes (eg. as a result of a faulty EA)
  • Your computer (or VPS) hangs or crashes
  • Your internet is dead
  • Your house is burning down
  • Your EA has sent a 1000 orders resulting in a margin call ...
MonitorEA will only alert you if, the chart(s)/EA(s) you are monitoring has/have a runtime problem, but the chart onto which MonitorEA is installed, is running fine. This is admittedly such a limited use case, that it is hardly worth talking about. It is merely academic and a good programming exercise.

How does it work and what does it do?

It is assumed that the EA's to be monitored, are broadcasting a periodic PING message to all the other charts. An example of how this is done can be seen inside the RogueEA.mq4 file (attached), It only requires a few additional lines, particularly:

Code: Select all

#include <Events.mqh>
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer() {
   static const string message = StringFormat("%I64d|%s|%s(%d)", ChartID(),WindowExpertName(), _Symbol, _Period);
   BroadcastEvent( EVENT_PING, (long)TimeLocal(), 0.0, message );
}
The first time MonitorEA receives a PING from a chart, it makes a note of the chartID, expert name and symbol name. This is now stored inside a little 'watch-list', and it expects regular PINGs for each participating chart. Lack of such updates for a substantial CheckPeriod of time, will be interpreted by MonitorEA as that the chart has a runtime problem. In such case, MonitorEA will alert the user (there are switches for Push Notifications, Email and Alerts) and it can optionally restart the problem-chart and re-load the EA. Incidentally, if the chart to be monitored was closed by the end-user on purpose, MonitorEA will also restart the chart ... so you need to know what you're doing.

Code attached. Have fun.

Update 2016.08.07
There are two small changes to both RogueEA and MonitorEA: RogueEA wasn't sending the full 64-bytes of the long chartID (i.e. the StringFormat was %ld, but should be %I64d). Those 4 early birds should re-download both RogueEA and MonitorEA. It is entirely possible that you would have seen and corrected this already yourself.
You do not have the required permissions to view the files attached to this post.
User avatar
tomele
Administrator
Posts: 1208
Joined: Tue May 17, 2016 3:40 pm
Location: Germany, Forest of Odes, Defending the Limes

MonitorEA

Post by tomele »

Hi Rene,

thanks for another fantastic masterpiece from you. :clap: :clap: :clap:

I will test this along with my Billybots.
Happy pippin, Thomas :-BD

It ain't what you don't know that gets you into trouble.
It's what you know for sure that just ain't so.
(Mark Twain)

Keep the coder going: Donate
User avatar
Boulder
Trader
Posts: 115
Joined: Sun Feb 28, 2016 5:16 pm
Location: Belgium

MonitorEA

Post by Boulder »

Brilliant stuff Rene.. :!!:
WhoKnows
Trader
Posts: 102
Joined: Wed Mar 19, 2014 11:57 pm
Location: North Brisbane, Australia

MonitorEA

Post by WhoKnows »

Thanks again Rene, :clap:

I see the Monitor EA is growing up very fast.
This is admittedly such a limited use case, that it is hardly worth talking about. It is merely academic and a good programming exercise.
I honestly think it is more than that. I could see that in all my cases with EAs being stuck and looping, as explained in the thread you refer to, that there was considerable time between an EA being stuck and the crash of the Empty4 platform. There were even cases where an EA was frozen without crashing Empty4 for two days.
I think most users would not notice a problem before the Empty4 platform itself crashes.

Having this ping system might prevent losing your shirt when the market moves away while the EA is stuck/frozen/looping/etc.
Certainly people with looping alerts like 'Invalid Ticket' and 'failed OrderClose' should consider adding this.

As discussed, I will be moving to a VPS based trading but I might still add 'the ping' as extra security.
Why not just add it to every EA?

But...too bad it is not calling for 'Mama' anymore like the first version. :lol:
I loved the humor in that one. Still saved a screenshot from my testing last Friday.
So I add it here for the sake of posterity.
mama.PNG
Cheers,
Peter
You do not have the required permissions to view the files attached to this post.
Radar
Trader
Posts: 437
Joined: Fri Mar 23, 2012 5:39 pm
Location: Round the bend ;)

MonitorEA

Post by Radar »

Hey Renexxxx,

Beautiful work! :)

Just a couple of ideas...

1. To prevent Mon from restarting a manually stopped EA (client)...
1a. Have the client create a GV with the same naming format to the Ping during de-init.
1b. Have Mon look for the GV and de-register the client.
1c. In the unfortunate circumstance where automatically closing a client/chart causes de-init to trigger and create the GV, have Mon create a flag when restarting (restarting(ChartId, EAName, Symbol)) so that it knows to delete the GV without acting on it.

2. You could delay deleting temporary templates by waiting for x number of pings from the restarted client before calling the DeleteFileW routine (and also remove the restarting flag).

I would code these myself, but they are way beyond my level of incompetence ;)

Have fun!
Radar =8^)
Check out my new, (well, old now), manual trade & automatic scale-in manager,
StackManV2
User avatar
renexxxx
Trader
Posts: 860
Joined: Sat Dec 31, 2011 3:48 am

MonitorEA

Post by renexxxx »

Radar wrote: 1. To prevent Mon from restarting a manually stopped EA (client)...
1a. Have the client create a GV with the same naming format to the Ping during de-init.
1b. Have Mon look for the GV and de-register the client.
1c. In the unfortunate circumstance where automatically closing a client/chart causes de-init to trigger and create the GV, have Mon create a flag when restarting (restarting(ChartId, EAName, Symbol)) so that it knows to delete the GV without acting on it.
Why not create a little deregister-event, that the client/chart sends OnDeinit(). The code for sending events is already there and the MonitorEA just needs to also listen for the deregister event (inside his OnChartEvent()) and run the delPing() function). I will add this to the new version.
Radar wrote: 2. You could delay deleting temporary templates by waiting for x number of pings from the restarted client before calling the DeleteFileW routine (and also remove the restarting flag).
MonitorEA can also run DeleteFileW when the deregister event is received.

One thing to keep in mind though, is that OnDeinit() is also run if/when the user hits F7 and presses OK on the Expert Properties panel. But that's OK, MonitorEA would quickly deregister the chart, delete the template (if it exists) and as soon as the client/chart starts sending new PINGs again, it will re-register the chart. No big deal.

R.
User avatar
renexxxx
Trader
Posts: 860
Joined: Sat Dec 31, 2011 3:48 am

MonitorEA

Post by renexxxx »

I have made a few changes to MonitorEA. Update is in Post 1.

In the end, it wasn't necessary to send a deregister event from RogueEA to inform MonitorEA that it can stop worrying about that particular chart. Instead, MonitorEA goes through all its known charts, and only sends alerts if it hasn't received a PING from charts that still exist. If it still has a chartID in its list of charts, that was closed, it simply removes that chartID from its list, so to not worry about that chart anymore.

The other issue, of the templates not being deleted, has also been resolved. It just does a WINAPI equivalent of a "dir templates\*_restart.tpl', and deletes each template for which there is no open chart.

Let me know if you find any problems.
avan1984
Posts: 2
Joined: Mon Jun 24, 2019 8:13 pm

MonitorEA

Post by avan1984 »

why i cant download the link of the ea that closes on high impact news
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

MonitorEA

Post by SteveHopwood »

avan1984 » Mon Jun 24, 2019 8:24 pm wrote:why i cant download the link of the ea that closes on high impact news
I have sent you my Welcome message and you will find everything here is available to you.

:xm: :rocket:
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
Post Reply

Return to “Auto-trading EA's and EA monitors”