No order execution, no error

 
I tried creating a MACD expert advisor(EA) of mql5, but it doesnt execute order order and doesn't give any error message. Please, what could have been the cause? 

Below is the code:


***
Descubra novos recursos para o MetaTrader 5 com a comunidade e os serviços MQL5
Descubra novos recursos para o MetaTrader 5 com a comunidade e os serviços MQL5
  • 2022.05.27
  • www.mql5.com
MQL5: linguagem de estratégias de negociação inseridas no Terminal do Cliente MetaTrader 5. A linguagem permite escrever seus próprios sistemas automáticos de negócios, indicadores técnicos, scripts e bibliotecas de funções
 

1. Please, insert code correctly: when editing a post, click    Code and paste your code in the popup window 

I have corrected your code:

//+------------------------------------------------------------------+
//|                                                      MACD EA.mq5 |
//|                                  Copyright 2022, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
//---Declaration of EA Properties
input double               StopLoss      =50;       // Stop Loss in Pips
input double               TakeProfit    =50;       // Take Profit in Pips
input int                  EA_MagicNumber=123406;   // Magic Number
input double               Volume        =0.1;      // Lot Size
input int                  Slippage      =10;
//---Declaration of EA INPUT VARIABLES
input int                  FastEMA       =9;
input int                  SlowEMA       =26;
input int                  MacdSMA       =9;
input ENUM_APPLIED_PRICE   AppliedPrice  =PRICE_CLOSE;
//---Declaration of other global variables
int MacdHandle;
double STP;
double TKP;
datetime m_prev_bars               =0;        // "0" -> D'1970.01.01 00:00';
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---Getting the Indicator handle
   MacdHandle=iMACD(Symbol(),PERIOD_CURRENT,FastEMA,SlowEMA,MacdSMA,AppliedPrice);
//--- checking if valid handle is obtained
   if(MacdHandle<0)
     {
      Alert("Error obtaining indicator handle. Error: ",GetLastError());
      return(INIT_FAILED);
     }
//--- standardizing the currency digits
   STP=StopLoss*Point();
   TKP=TakeProfit*Point();
   if(Digits() == 5 || Digits() == 3)
     {
      STP=STP*10.0;
      TKP=TKP*10.0;
     }
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- releasing indicator handle
   IndicatorRelease(MacdHandle);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- we work only at the time of the birth of new bar
   datetime time_0=iTime(Symbol(),Period(),0);
   if(time_0==m_prev_bars)
      return;
   m_prev_bars=time_0;
//--- checking if we have open trades
   if(PositionsTotal()>0)
      return;
//---
// defining MQL structures to be used for trading
   MqlTick latest_price;            //To be used to get the latest price information
   MqlTradeRequest mrequest;        //To be used in send trade requeste
   MqlTradeResult mresult;          //To be used in accessing trade results
   ZeroMemory(mrequest);
//---
   double MainLine[];
   double SignalLine[];
//--- setting our arrays to the as series flag
   ArraySetAsSeries(MainLine,true);
   ArraySetAsSeries(SignalLine,true);
//--- checking if we have the latest price quote
   if(!SymbolInfoTick(Symbol(),latest_price))
     {
      Alert("Error getting latest price quote. Error: ",GetLastError());
      m_prev_bars=0;
      return;
     }
//--- copy and check indicator values
   if((CopyBuffer(MacdHandle,MAIN_LINE,0,3,MainLine)!=3) || (CopyBuffer(MacdHandle,SIGNAL_LINE,0,3,SignalLine)!=3))
     {
      Alert("Error copying the indicator buffers. Error: ",GetLastError());
      m_prev_bars=0;
      return;
     }
//--- buy position condition
   if((MainLine[1]>SignalLine[1]) && (MainLine[0]<SignalLine [0]))
     {
      mrequest.action=TRADE_ACTION_DEAL;
      mrequest.price=NormalizeDouble(latest_price.ask,Digits());
      mrequest.sl=NormalizeDouble(latest_price.ask - STP,Digits());
      mrequest.tp=NormalizeDouble(latest_price.ask + TKP,Digits());
      mrequest.symbol=Symbol();
      mrequest.volume=Volume;
      mrequest.magic=EA_MagicNumber;
      mrequest.type=ORDER_TYPE_BUY;
      mrequest.type_filling=ORDER_FILLING_FOK;
      mrequest.deviation=Slippage;
      bool result=OrderSend(mrequest,mresult);
      //---Getting the trade results
      if(mresult.retcode == 10009 || mresult.retcode == 10008)
        {
         Alert("A buy order has been successfully placed with ticket# :",mresult.order,"!!");
        }
      else
        {
         Alert("A buy order could not be placed - Error: ",GetLastError());
        }
     }
//--- sell position condition
   if((MainLine[1]<SignalLine[1]) && (MainLine[0]>SignalLine [0]))
     {
      mrequest.action=TRADE_ACTION_DEAL;
      mrequest.price=NormalizeDouble(latest_price.bid,Digits());
      mrequest.sl=NormalizeDouble(latest_price.bid + STP,Digits());
      mrequest.tp=NormalizeDouble(latest_price.bid - TKP,Digits());
      mrequest.symbol=Symbol();
      mrequest.volume=Volume;
      mrequest.magic=EA_MagicNumber;
      mrequest.type=ORDER_TYPE_SELL;
      mrequest.type_filling=ORDER_FILLING_FOK;
      mrequest.deviation=Slippage;
      bool result=OrderSend(mrequest,mresult);
      //---Getting the trade results
      if(mresult.retcode == 10009 || mresult.retcode == 10008)
        {
         Alert("A sell order has been successfully placed with ticket# :",mresult.order,"!!");
        }
      else
        {
         Alert("A sell order could not be placed - Error: ",GetLastError());
        }
     }
  }
//+------------------------------------------------------------------+
MQL5.community - User Memo
MQL5.community - User Memo
  • www.mql5.com
You have just registered and most likely you have questions such as, "How do I insert a picture to my a message?" "How do I format my MQL5 source code?" "Where are my personal messages kept?" You may have many other questions. In this article, we have prepared some hands-on tips that will help you get accustomed in MQL5.community and take full advantage of its available features.
Files:
MACD_EA.mq5  6 kb
 
Good day Boss, thanks for your prompt response and it worked very fine. I really appreciate. I am sincerely grateful