<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Forex Software — MACD does not really close when Crossing the zero line downward ?]]></title>
	<link rel="self" href="https://forexsb.com/forum/feed/atom/topic/10050/" />
	<updated>2026-03-25T07:21:25Z</updated>
	<generator>PunBB</generator>
	<id>https://forexsb.com/forum/topic/10050/macd-does-not-really-close-when-crossing-the-zero-line-downward/</id>
		<entry>
			<title type="html"><![CDATA[Re: MACD does not really close when Crossing the zero line downward ?]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/83181/#p83181" />
			<content type="html"><![CDATA[<p>You can easily disable the &quot;noise&quot; protection by setting the &quot;sigma&quot; value to 0.</p><p>It is on line 101 of your expert.</p><p>This is the original code:</p><p><span class="postimg"><img src="https://image-holder.forexsb.com/store/macd-xauusd-sigma-settings-mql-editor.png" alt="https://image-holder.forexsb.com/store/macd-xauusd-sigma-settings-mql-editor.png" /></span></p><p>Set it like that:</p><div class="codebox"><pre><code>const double sigma = 0.0;</code></pre></div><br /><p>Backtest the expert in the MetaTrader tester before and after the change and compare the results. <br />I did it on Dukascopy MT5, and it shows no difference.</p><p>It may or may not show differnce in your data.</p><p>...</p><p>If you want, you may slightly modify the closing signal formula. It is on line 370 of your expert.</p><p>Change it from:</p><div class="codebox"><pre><code>void ManageClose(void)
  {
   // MACD (Close, 12, 26, 9)
   double ind2buffer[]; CopyBuffer(indHandlers[0][2][0], 0, 1, 3, ind2buffer);
   double ind2val1  = ind2buffer[2];
   double ind2val2  = ind2buffer[1];
   bool   ind2long  = ind2val1 &lt; 0 - sigma &amp;&amp; ind2val2 &gt; 0 + sigma;
   bool   ind2short = ind2val1 &gt; 0 + sigma &amp;&amp; ind2val2 &lt; 0 - sigma;

   if((posType == OP_BUY  &amp;&amp; ind2long) ||
      (posType == OP_SELL &amp;&amp; ind2short))
      ClosePosition();
  }</code></pre></div><br /><p>To:</p><br /><div class="codebox"><pre><code>void ManageClose(void)
  {
   // MACD (Close, 12, 26, 9)
   double ind2buffer[]; CopyBuffer(indHandlers[0][2][0], 0, 1, 3, ind2buffer);
   double ind2val1  = ind2buffer[2];
   double ind2val2  = ind2buffer[1];
   bool   ind2long  = ind2val1 &lt;= 0.0 &amp;&amp; ind2val2 &gt; 0.0;
   bool   ind2short = ind2val1 &gt;= 0.0 &amp;&amp; ind2val2 &lt; 0.0;

   if((posType == OP_BUY  &amp;&amp; ind2long) ||
      (posType == OP_SELL &amp;&amp; ind2short))
      ClosePosition();
  }</code></pre></div><br /><p>The change is from:</p><div class="codebox"><pre><code>   bool   ind2long  = ind2val1 &lt; 0 - sigma &amp;&amp; ind2val2 &gt; 0 + sigma;</code></pre></div><p>to:</p><div class="codebox"><pre><code>   bool   ind2long  = ind2val1 &lt;= 0.0 &amp;&amp; ind2val2 &gt; 0.0;</code></pre></div><br /><p>After the modification, the signal will sound like: MACD becomes greater than zero after being below or equal to zero.</p>]]></content>
			<author>
				<name><![CDATA[Popov]]></name>
				<uri>https://forexsb.com/forum/user/2/</uri>
			</author>
			<updated>2026-03-25T07:21:25Z</updated>
			<id>https://forexsb.com/forum/post/83181/#p83181</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: MACD does not really close when Crossing the zero line downward ?]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/83172/#p83172" />
			<content type="html"><![CDATA[<p>&gt; 1) if the EA works on EA_STUDIO showing (on the chart of the backtest) continuos opening and closing without missing trades, as user I would think the EA will act the same way on Metatrader in live trading.</p><p>The EA Studio chart shows &quot;Premium&quot; data. These data are composed from tick files from Dukascopy. These are different data from the ones in your MetaTrader 5.<br />You can import the actual MT data into EA Studio to check whether the signal corresponds. Please note that the Premium data quotes XAUUSD to 3 decimal digits, whereas your MT Terminal most likely quotes it to 2 decimal digits.</p><p>I tested all EA Studio indicators against MT. I&#039;m sure EA Studios&#039; MACD matches MT&#039;s MACD to the 10th decimal place.</p><p>&gt; Ok for a technical reason behind the &quot;bug&quot;, but it&#039;s hard to accept in my opinion, for clients seeing</p><p>This is absolutely reasonable!</p><p>The signals, like &quot;X crosses below the zero line&quot;, sound simple and are easy to implement programmatically from programmers&#039; viewpoint.&nbsp; MetaTrader 5 shows MACD up to the 3rd decimal digit. To be sound from the &quot;customers&quot; point of view, the calculations should be up to the 3rd digit as well, but that is not precisely enough.</p><p>There are also discrepancies between the indicator values and the chart&#039;s visual representation. It is because the chart uses rounded pixels after scaling the actual values. </p><p>I chose 6 digits for the signal calculations and a simplified formula as a compromise between speed and precision. But, as I already said, it will be further improved.</p><p>...</p><p>&gt; 2) deactivating the EA but leaving it on the chart, the EA still keeps logging and very frequently (4 logs per second, each pair):</p><p>I almost agree:</p><p>&gt; 4 logs per second</p><p>These are actually 3 logs <img src="https://forexsb.com/forum/img/smilies/smile.png" width="15" height="15" alt="smile" />, but yes, one log would be enough.</p><p>&gt; ...each pair</p><p>This is the correct behaviour. Each expert is independent.</p><p>&gt; deactivating the EA but leaving it on the chart</p><p>You are right here!</p><p>There is no point in waiting 0.1 seconds for the user to enable the trading. I&#039;ll cancel the signal entirely if the trade is disabled.</p><p>Thank you for the report!</p>]]></content>
			<author>
				<name><![CDATA[Popov]]></name>
				<uri>https://forexsb.com/forum/user/2/</uri>
			</author>
			<updated>2026-03-20T07:45:50Z</updated>
			<id>https://forexsb.com/forum/post/83172/#p83172</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: MACD does not really close when Crossing the zero line downward ?]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/83171/#p83171" />
			<content type="html"><![CDATA[<p>Thanks for quick replying even if it&#039;s not clear to me but it&#039;s not your responsability.</p><p>Just adding a couple of things:<br /><strong>1)</strong> if the EA works on EA_STUDIO showing (on the chart of the backtest) continuos opening and closing without missing trades, as user I would think the EA will act the same way on Metatrader in live trading. Without going into technical aspects. </p><p>Ea Studio Closed the trade correctly for the case I talk about in the first post:<br /><span class="postimg"><img src="https://i.postimg.cc/L6ys6JWX/image.png" alt="https://i.postimg.cc/L6ys6JWX/image.png" /></span></p><br /><br /><p>So, I would expect, in general, for all EAs, they will work the same way on MT5 (instead I closed it manually):<br /><span class="postimg"><img src="https://i.postimg.cc/wMnBBTw7/image.png" alt="https://i.postimg.cc/wMnBBTw7/image.png" /></span></p><p>Ok for a technical reason behing the &quot;bug&quot;, but it&#039;s hard to accept in my opinion for clients seeing EA studio opening and closing the trade correctly, believing the EA will work the same on Mt5 and then it won&#039;t.</p><p><strong>2)</strong> deactivating the EA but leaving it on chart, the EA still keep logging and very frequently (4 logs per second each pair):</p><p><em>2026.03.19 23:53:25.561&nbsp; &nbsp; EA Studio Macd Sopra Sotto Zero SL e TP 1279100259 (XAUUSD,M1)&nbsp; &nbsp; Trade context is busy! Waiting...<br />2026.03.19 23:53:30.658&nbsp; &nbsp; EA Studio Macd Sopra Sotto Zero SL e TP 1279100259 (XAGUSD,M1)&nbsp; &nbsp; The waiting limit exceeded!<br />2026.03.19 23:53:30.767&nbsp; &nbsp; EA Studio Macd Sopra Sotto Zero SL e TP 1279100259 (XAGUSD,M1)&nbsp; &nbsp; Order Send retry: 2<br />2026.03.19 23:53:30.767&nbsp; &nbsp; EA Studio Macd Sopra Sotto Zero SL e TP 1279100259 (XAGUSD,M1)&nbsp; &nbsp; Trade context is busy! Waiting...<br />2026.03.19 23:53:55.634&nbsp; &nbsp; EA Studio Macd Sopra Sotto Zero SL e TP 1279100259 (XAUUSD,M1)&nbsp; &nbsp; The waiting limit exceeded!<br />2026.03.19 23:53:55.745&nbsp; &nbsp; EA Studio Macd Sopra Sotto Zero SL e TP 1279100259 (XAUUSD,M1)&nbsp; &nbsp; Order Send retry: 3<br />2026.03.19 23:53:55.745&nbsp; &nbsp; EA Studio Macd Sopra Sotto Zero SL e TP 1279100259 (XAUUSD,M1)&nbsp; &nbsp; Trade context is busy! Waiting...<br />2026.03.19 23:54:00.869&nbsp; &nbsp; EA Studio Macd Sopra Sotto Zero SL e TP 1279100259 (XAGUSD,M1)&nbsp; &nbsp; The waiting limit exceeded!<br />2026.03.19 23:54:00.976&nbsp; &nbsp; EA Studio Macd Sopra Sotto Zero SL e TP 1279100259 (XAGUSD,M1)&nbsp; &nbsp; Order Send retry: 3<br />2026.03.19 23:54:00.976&nbsp; &nbsp; EA Studio Macd Sopra Sotto Zero SL e TP 1279100259 (XAGUSD,M1)&nbsp; &nbsp; Trade context is busy! Waiting...</em></p>]]></content>
			<author>
				<name><![CDATA[poteree]]></name>
				<uri>https://forexsb.com/forum/user/14942/</uri>
			</author>
			<updated>2026-03-19T23:21:06Z</updated>
			<id>https://forexsb.com/forum/post/83171/#p83171</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: MACD does not really close when Crossing the zero line downward ?]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/83170/#p83170" />
			<content type="html"><![CDATA[<p>This is the designed behaviour of the logical rule.</p><p>In your case, MACD does not cross the zero line in two consecutive bars, and the Expert Advisor does not raise a close signal.</p><p>MACD falls below zero after being effectively zero on the previous bar, where &quot;zero&quot; means: |MACD| &lt; 0.000001</p><p>EA Studio computes signals more precisely than MetaQuotes&#039; example formula. At least, we use &quot;sigma&quot;. </p><p><a href="https://image-holder.forexsb.com/store/metatrader-macd-expert-example.png"><span class="postimg"><img src="https://image-holder.forexsb.com/store/metatrader-macd-expert-example-thumb.png" alt="https://image-holder.forexsb.com/store/metatrader-macd-expert-example-thumb.png" /></span></a></p><p>As you see, the given &quot;standard&quot; code example does not manage the case where the values are equal. (m_macd_previous and m_signal_previous in that case). However, there is no strict definition of &quot;equality&quot; for real numbers.</p>]]></content>
			<author>
				<name><![CDATA[Popov]]></name>
				<uri>https://forexsb.com/forum/user/2/</uri>
			</author>
			<updated>2026-03-19T06:40:26Z</updated>
			<id>https://forexsb.com/forum/post/83170/#p83170</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: MACD does not really close when Crossing the zero line downward ?]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/83169/#p83169" />
			<content type="html"><![CDATA[<p>Thanks for replying, but my EA studio licence expired and I have a not functioning EA on MACD, downloaded with my last license.</p><p>As remedy, I believe you should send me via email the functioning version of the EA I shared here, without the bug. </p><p>Thanks!</p><div class="quotebox"><cite>Popov wrote:</cite><blockquote><p>This behaviour results from how EA Studio and the exported Expert Advisors calculate signals.</p><p>Both EA Studio and the Expert Advisors use &quot;sigma&quot; (minimum value) when calculating the signals.</p><p>In this case: &quot;Open Long when Macd Line crosses the zero line upward&quot;.<br />Long&nbsp; signal = MACD[1] &gt; 0 + sigma AND&nbsp; MACD[2] &lt; 0 - sigma<br />Short signal = MACD[1] &lt; 0 - sigma AND&nbsp; MACD[2] &gt; 0 + sigma</p><p>Where:<br /> - MACD[1] - previous bar MACD value<br /> - MACD[2] - prev - previous bar MACD value<br /> - sigma = 0.000001</p><p>This formula is the same in EA Studio and in the experts.</p><p>The purpose of &quot;sigma&quot; is to filter out false signals due to the way computers calculate the fractional numbers.<br />The drawback of this formula is that it ignores signals when crossovers occur with very small indicator values.</p><p>Compared to that, FSB Pro offers more advanced calculations. It goes back through values until it proves or disproves a significant signal. </p><p>We have more precise, but slower computations in FSB Pro. EA Studio is good enough and much faster.</p><p>I&#039;ll try to make both fast and reliable signal formulas in my next backtester.</p></blockquote></div>]]></content>
			<author>
				<name><![CDATA[poteree]]></name>
				<uri>https://forexsb.com/forum/user/14942/</uri>
			</author>
			<updated>2026-03-18T22:20:54Z</updated>
			<id>https://forexsb.com/forum/post/83169/#p83169</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: MACD does not really close when Crossing the zero line downward ?]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/83154/#p83154" />
			<content type="html"><![CDATA[<p>This behaviour results from how EA Studio and the exported Expert Advisors calculate signals.</p><p>Both EA Studio and the Expert Advisors use &quot;sigma&quot; (minimum value) when calculating the signals.</p><p>In this case: &quot;Open Long when Macd Line crosses the zero line upward&quot;.<br />Long&nbsp; signal = MACD[1] &gt; 0 + sigma AND&nbsp; MACD[2] &lt; 0 - sigma<br />Short signal = MACD[1] &lt; 0 - sigma AND&nbsp; MACD[2] &gt; 0 + sigma</p><p>Where:<br /> - MACD[1] - previous bar MACD value<br /> - MACD[2] - prev - previous bar MACD value<br /> - sigma = 0.000001</p><p>This formula is the same in EA Studio and in the experts.</p><p>The purpose of &quot;sigma&quot; is to filter out false signals due to the way computers calculate the fractional numbers.<br />The drawback of this formula is that it ignores signals when crossovers occur with very small indicator values.</p><p>Compared to that, FSB Pro offers more advanced calculations. It goes back through values until it proves or disproves a significant signal. </p><p>We have more precise, but slower computations in FSB Pro. EA Studio is good enough and much faster.</p><p>I&#039;ll try to make both fast and reliable signal formulas in my next backtester.</p>]]></content>
			<author>
				<name><![CDATA[Popov]]></name>
				<uri>https://forexsb.com/forum/user/2/</uri>
			</author>
			<updated>2026-03-12T10:37:08Z</updated>
			<id>https://forexsb.com/forum/post/83154/#p83154</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[MACD does not really close when Crossing the zero line downward ?]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/83135/#p83135" />
			<content type="html"><![CDATA[<p>Dear Popov and Staff,<br />the EA has the following conditions:</p><p>Open Long when Macd Line crosses the zero line upward<br />Close Long when Macd Line crosses the zero line downward</p><p>but it has not closed, I had to close the position manually:</p><p><span class="postimg"><img src="https://i.postimg.cc/wMnBBTw7/image.png" alt="https://i.postimg.cc/wMnBBTw7/image.png" /></span></p><p>PLease find EA studio EA attached.</p><p>Thanks</p>]]></content>
			<author>
				<name><![CDATA[poteree]]></name>
				<uri>https://forexsb.com/forum/user/14942/</uri>
			</author>
			<updated>2026-02-25T08:08:03Z</updated>
			<id>https://forexsb.com/forum/post/83135/#p83135</id>
		</entry>
</feed>
