<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Eye Algo</title>
    <description>The latest articles on DEV Community by Eye Algo (@eyealgo).</description>
    <link>https://dev.to/eyealgo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4251821%2F758bf436-c952-421b-935e-37b6ce95620b.png</url>
      <title>DEV Community: Eye Algo</title>
      <link>https://dev.to/eyealgo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/eyealgo"/>
    <language>en</language>
    <item>
      <title>EA stopped trading? How to detect it: heartbeat and watchdog</title>
      <dc:creator>Eye Algo</dc:creator>
      <pubDate>Wed, 18 Nov 2026 11:57:27 +0000</pubDate>
      <link>https://dev.to/eyealgo/ea-stopped-trading-how-to-detect-it-heartbeat-and-watchdog-534e</link>
      <guid>https://dev.to/eyealgo/ea-stopped-trading-how-to-detect-it-heartbeat-and-watchdog-534e</guid>
      <description>&lt;p&gt;An Expert Advisor can stop trading and still look healthy: the smiley face is on, the terminal is connected, the Experts tab shows no error. You often find out days later, because nothing "happened". This article explains how to tell a quiet market from a stopped EA, and how to be alerted the same day.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why an EA goes quiet without an error
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Entry conditions never become true&lt;/strong&gt; after a change in the market, a broker setting or a symbol property (for example a maximum-spread filter that is now always exceeded).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The terminal restarted.&lt;/strong&gt; Variables kept in memory are reset. An EA that depends on state built up over earlier ticks can wait for a condition that will never be rebuilt.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No ticks on the chart symbol.&lt;/strong&gt; The EA code only runs on a tick, so a symbol with a closed or frozen feed does not run it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Trading is blocked&lt;/strong&gt; by the account, the broker or a disabled "algo trading" button, while the EA stays attached.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Do not rely on trade count alone
&lt;/h2&gt;

&lt;p&gt;"No trade for three days" can be a real signal gap or a failure. Counting trades alone gives false alarms in quiet weeks and misses a dead EA during busy ones. Check two separate things instead: &lt;strong&gt;is the EA still running&lt;/strong&gt;, and &lt;strong&gt;is it still taking the trades it should&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. A heartbeat for "is it still running"
&lt;/h2&gt;

&lt;p&gt;Let the EA write the current time on a timer, and let another program read it. Inside the EA, set a timer in &lt;code&gt;OnInit&lt;/code&gt; and update a global variable in &lt;code&gt;OnTimer&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nc"&gt;OnInit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;EventSetTimer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;INIT_SUCCEEDED&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nc"&gt;OnTimer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nc"&gt;GlobalVariableSet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"hb_"&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nc"&gt;AccountInfoInteger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;ACCOUNT_LOGIN&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;double&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nc"&gt;TimeLocal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A timer runs even when no tick arrives, so the heartbeat does not depend on market activity. Use local time for the heartbeat, because &lt;code&gt;TimeCurrent()&lt;/code&gt; only moves when quotes arrive.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. A watchdog that checks the heartbeat
&lt;/h2&gt;

&lt;p&gt;Attach a small second EA to another chart in the same terminal, with its own &lt;code&gt;EventSetTimer(10)&lt;/code&gt; in &lt;code&gt;OnInit&lt;/code&gt;. If the heartbeat is older than a limit you choose, it sends a notification:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nc"&gt;OnTimer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"hb_"&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nc"&gt;AccountInfoInteger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;ACCOUNT_LOGIN&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nc"&gt;GlobalVariableCheck&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nc"&gt;TimeLocal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nc"&gt;GlobalVariableGet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="nc"&gt;SendNotification&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"EA heartbeat is stale on account "&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nc"&gt;AccountInfoInteger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;ACCOUNT_LOGIN&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Push notifications need your MetaQuotes ID set in the terminal. For a more reliable setup, send the heartbeat to an outside service or a Telegram bot with &lt;code&gt;WebRequest&lt;/code&gt;, so you are alerted even if the whole VPS is down. The URL must be added to the allowed list in the terminal options.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. A last-trade check for "is it taking trades"
&lt;/h2&gt;

&lt;p&gt;Compare the time of the last deal with the longest quiet period that is normal for your strategy. Select history with &lt;code&gt;HistorySelect&lt;/code&gt;, read the newest deal time, and alert only when the gap is longer than your own normal maximum. Set that limit from the EA's real history, not a guess, and apply it only during the hours the EA is allowed to trade.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Log the reason, not only the trade
&lt;/h2&gt;

&lt;p&gt;Many "silent" EAs are not broken; they are filtering. Have the EA write one line every hour with its state: last evaluation time, current spread, which filter blocked entry. A log that says "blocked by max spread" for three days tells you the cause at once. Ask for this when you write your &lt;a href="https://eyealgo.com/blog/brief-an-ea-developer" rel="noopener noreferrer"&gt;brief&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Check the basics first: algo trading enabled, trading allowed for the account, the right symbol and timeframe, and enough margin. The &lt;a href="https://eyealgo.com/blog/ea-not-opening-trades" rel="noopener noreferrer"&gt;EA not opening trades&lt;/a&gt; guide has the full checklist.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  On a VPS
&lt;/h2&gt;

&lt;p&gt;A VPS keeps the terminal running while your PC is off, but a VPS being "up" does not mean the EA is working. That is why the heartbeat belongs inside the EA. See &lt;a href="https://eyealgo.com/blog/ea-vps-setup" rel="noopener noreferrer"&gt;EA VPS setup&lt;/a&gt; for the setup itself.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where we can help
&lt;/h2&gt;

&lt;p&gt;We can add a heartbeat, a last-trade alert and a state log to an existing EA, or include them when we build a new one. See &lt;a href="https://eyealgo.com/services/changes" rel="noopener noreferrer"&gt;changes to existing code&lt;/a&gt;. These checks tell you when something stops; they do not make a strategy profitable, and trading carries risk.&lt;/p&gt;

&lt;h2&gt;
  
  
  Frequently asked questions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Can I use trade count to detect a stopped EA?
&lt;/h3&gt;

&lt;p&gt;Only as a second check. A quiet market looks the same as a dead EA. A heartbeat tells you the EA is running; a last-trade gap longer than your normal maximum tells you it may not be trading.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why use a timer instead of OnTick?
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;OnTick&lt;/code&gt; only runs when a quote arrives. On a symbol with no ticks for a while (for example before a late session open) it would show "stopped" when nothing is wrong. A timer keeps running.&lt;/p&gt;

&lt;h3&gt;
  
  
  Do I need a second terminal for the watchdog?
&lt;/h3&gt;

&lt;p&gt;No. A second chart in the same terminal is enough to start. A separate machine or an outside service gives better coverage, because it also catches a frozen terminal or a failed VPS.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://eyealgo.com/blog/ea-stopped-trading-monitoring" rel="noopener noreferrer"&gt;Eye Algo&lt;/a&gt;. We build custom MT5 EAs and TradingView Pine Script indicators for traders. Trading carries risk.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>mql5</category>
      <category>trading</category>
      <category>metatrader</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
