[help]imacd's output is different with macd indicator

 

Hi,

i modified the MACD Sample ea, make's it buy or sell close when macd goes from <0 to >0, sell or buy close when macd goes from >0 to <0.

bool CSampleExpert::LongClosed()
  {
   bool res=false;

         if(m_macd_previous>0 && m_macd_current<0)
           {
            //--- close position
            if(m_trade.PositionClose(Symbol()))
            {
               printf("Long position by %s to be closed",Symbol());
               printf("LongClosed : m_macd_previous=%f,m_macd_current=%f",m_macd_previous,m_macd_current);
            }
            else
               printf("Error closing position by %s : '%s'",Symbol(),m_trade.ResultComment());
            //--- processed and cannot be modified
            res=true;
           }
//---
   return(res);
  }

bool CSampleExpert::LongOpened()
  {
   bool res=false;

         if(m_macd_previous<0 && m_macd_current>0)
           {
            double price=m_symbol.Ask();
            double tp   =0.0;//m_symbol.Bid()+m_take_profit;
            //--- check for free money
            if(m_account.FreeMarginCheck(Symbol(),ORDER_TYPE_BUY,InpLots,price)<0.0)
               printf("We have no money. Free Margin = %f",m_account.FreeMargin());
            else
              {
               //--- open position
               if(m_trade.PositionOpen(Symbol(),ORDER_TYPE_BUY,InpLots,price,0.0,tp))
               {
                  printf("Position by %s to be opened",Symbol());
                  printf("LongOpened : m_macd_previous=%f,m_macd_current=%f",m_macd_previous,m_macd_current);
               }
               else
                 {
                  printf("Error opening BUY position by %s : '%s'",Symbol(),m_trade.ResultComment());
                  printf("Open parameters : price=%f,TP=%f",price,tp);
                 }
              }
            //--- in any case we must exit from expert
            res=true;
           }
//---
   return(res);
  }

but it happens like:

wrong close

then i checked the log, it displays:

RS    0    MACD (EURUSD,D1)    09:32:46    1994.09.02 00:01:00   Long position by EURUSD to be closed

FS    0    MACD (EURUSD,D1)    09:32:46    1994.09.02 00:01:00   LongClosed : m_macd_previous=0.000486,m_macd_current=-0.000098


why indicator's number is 0.001082 but m_macd_current is -0.000098 ?

Files:
macd.mq5  19 kb
 

Can anyone help?

Thanks very much!