title: How to code a MACD in an expert advisor that uses EMA instead of SMA for the signal line
body: <pre><code>#include &lt;MovingAverages.mqh&gt;
  
  input int fast = 7;
  input int slow = 26;
  input int signallength =9;
  input int closeoropen = 1; //close=0, open=1
  input int movingavglength =114;
  double ema, macd, signal;
  double ind_buffer1[26], ind_buffer2[26];
  bool sellsignaldone  = false;
  bool buysignaldone = false;
  
  void OnTick()
    { 
     ema = iMA(NULL,0,movingavglength,0,MODE_EMA,PRICE_CLOSE,1);
  
  //---- macd counted in the 1-st buffer
     for(int i=0; i&lt;slow-1; i++)
        ind_buffer1[i]=iMA(NULL,0,fast,0,MODE_EMA,closeoropen,i)-iMA(NULL,0,slow,0,MODE_EMA,closeoropen,i);
  //---- signal line counted in the 2-nd buffer
     for(int i=0; i&lt;slow-1; i++)
        ind_buffer2[i]=iMAOnArray(ind_buffer1,0,signallength,0,MODE_EMA,i);
  
      macd = ind_buffer1[1];
      signal = ind_buffer2[1];
     
     if (macd &gt; signal &amp;&amp; macd&lt;0 &amp;&amp; Close[1]&gt;ema &amp;&amp; !buysignaldone &amp;&amp; OrdersTotal()==0) {
        buysignaldone = true;
        OrderSend(NULL, OP_BUY,1/Ask, Ask, 3, Ask-(Ask*0.004), Ask+(Ask*0.008), &quot;Buy Order&quot;,0,0,clrGreen);
        
     }
     if (macd &lt; signal) {
        buysignaldone = false;
     }
     
     if (macd &lt; signal &amp;&amp; macd&gt;0 &amp;&amp; Close[1]&lt;ema &amp;&amp; !sellsignaldone &amp;&amp; OrdersTotal()==0) {
        sellsignaldone = true;
        OrderSend(NULL, OP_SELL,1/Bid, Bid, 3, Bid+(Bid*0.004), Bid-(Bid*0.008), &quot;Sell Order&quot;,0,0,clrRed);
     }
     
     if (macd &gt; signal) {
        sellsignaldone = false;
     }
     
    }
  </code></pre>
  <p>You can't use <code>iMACD</code> for this. I'm not sure what I've done wrong but the signals are in the wrong place</p>
  <p><a href="https://i.stack.imgur.com/8yj7G.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8yj7G.png" alt="enter image description here" /></a></p>
  <p>Crossover is here</p>
  <p><a href="https://i.stack.imgur.com/sbA6c.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sbA6c.png" alt="enter image description here" /></a></p>