My expert advisor doesnot open live Trades Please help me out

 
This is the code to my Expert Advsor
//+------------------------------------------------------------------+
//|                                                  masterpiece.mq4 |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                       
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
    
#property version   "1.00"
#property strict
#define SIGNAL_NONE 0
#define SIGNAL_BUY   1
#define SIGNAL_SELL  2
#define SIGNAL_CLOSEBUY 3
#define SIGNAL_CLOSESELL 4

extern int   HMA_Period=35;
extern int   HMA_Mode=3;
extern int    Amplitude= 1;
extern int  Sensetive= 150;
extern int  DeadZonePip=30;
extern int  ExplosionPower=15;
extern int  TrendPower=15;
extern double MaxRiskPerTrade =2;
extern int TrailingStop = 30;
extern bool TrailingStopMode = True;
extern bool StopLossMode = True;
 double StopLossLevel, TakeProfitLevel;
 extern bool TakeProfitMode = True;
int MaxTrades = 2;
int main_magic;
int Total, Ticket;
double LotSize=0.01;
double StopLoss =1.5*iATR(NULL,0,14,0);
double TakeProfit=iATR(NULL,0,14,0);
double Slippage=5;      //Slippage in pips

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
enum Enum_Hour
  {
   h00=00,     //00:00
   h01=01,     //01:00
   h02=02,     //02:00
   h03=03,     //03:00
   h04=04,     //04:00
   h05=05,     //05:00
   h06=06,     //06:00
   h07=07,     //07:00
   h08=08,     //08:00
   h09=09,     //09:00
   h10=10,     //10:00
   h11=11,     //11:00
   h12=12,     //12:00
   h13=13,     //13:00
   h14=14,     //14:00
   h15=15,     //15:00
   h16=16,     //16:00
   h17=17,     //17:00
   h18=18,     //18:00
   h19=19,     //19:00
   h20=20,     //20:00
   h21=21,     //21:00
   h22=22,     //22:00
   h23=23,     //23:00
  };
input Enum_Hour StartHour=h01;      //Start opearation hour
input Enum_Hour LastHour=h23;
double StopLevel;
int init() {
    main_magic=36711750 + func_TimeFrame_Const2Val(Period()) + GetSymbolConstant(Symbol());
   StopLevel = MarketInfo(Symbol(), MODE_STOPLEVEL) + MarketInfo(Symbol(), MODE_SPREAD);

   return(0);
}

int deinit() {
   return(0);
}
bool CheckActiveHours()
  {
//Set by default the operations disabled
   bool OperationsAllowed=false;
//Check if the current hour is between the allowed hours of operations, if so I return true
   if(StartHour==LastHour && Hour()==StartHour) OperationsAllowed=true;
   if(StartHour<LastHour && Hour()>=StartHour && Hour()<=LastHour) OperationsAllowed=true;
   if(StartHour>LastHour && ((Hour()>=LastHour && Hour()<=23) || (Hour()<=StartHour && Hour()>0))) OperationsAllowed=true;
   return OperationsAllowed;
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start() {
 if(CheckActiveHours()){
         Comment("Time for trade has not come else!");
 }
  int Order = SIGNAL_NONE;
   Total = OrdersTotal();
   Order = SIGNAL_NONE;
     
     
   //+------------------------------------------------------------------+
   //| Variable Begin                                                   |
   //+------------------------------------------------------------------+
     double hma0 = iCustom(Symbol(), Period(), "Hull moving average", HMA_Period, HMA_Mode, 0, 2, 0);
      double hma1 = iCustom(Symbol(), Period(), "Hull moving average", HMA_Period, HMA_Mode, 0, 2, 1);
      double hma2 = iCustom(Symbol(), Period(), "Hull moving average", HMA_Period, HMA_Mode, 0, 2, 2);
      double Buy1_1=(hma0>hma1 && hma1>hma2);
      double Sell1_1=(hma0<hma1 && hma1<hma2);
      double hf0 = iCustom(Symbol(), Period(), "HalfTrend-1.02",Amplitude,0,0);
      double hf1 = iCustom(Symbol(), Period(), "HalfTrend-1.02",Amplitude,0,1);
      double Buy1_2=(hf0>hf1);
      double Sell1_2=(hf0<hf1);
      double wah0 = iCustom(Symbol(), Period(), "Waddah_Attar_Explosion", Sensetive,DeadZonePip,ExplosionPower,TrendPower,0,0);
      double wah1 = iCustom(Symbol(), Period(), "Waddah_Attar_Explosion", Sensetive,DeadZonePip,ExplosionPower,TrendPower,0,1);
      double wah2 = iCustom(Symbol(), Period(), "Waddah_Attar_Explosion", Sensetive,DeadZonePip,ExplosionPower,TrendPower,0,2);
      double wah3 = iCustom(Symbol(), Period(), "Waddah_Attar_Explosion", Sensetive,DeadZonePip,ExplosionPower,TrendPower,0,3);
      double Buy1_3=(wah0>wah2 && wah2>wah3);
      double Sell1_3=(wah1>wah2 && wah2>wah3);
       //Check position
       bool IsTrade = False;
      for (int i = 0; i < Total; i ++) {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if(OrderType() <= OP_SELL &&  OrderSymbol() == Symbol()) {
         IsTrade = True;
         if(OrderType() == OP_BUY) {
            //Close

            //+------------------------------------------------------------------+
            //| Signal Begin(Exit Buy)                                           |
            //+------------------------------------------------------------------+
  
  if (hma0 < hma1 && hma1<hma2) Order = SIGNAL_CLOSEBUY;



            //+------------------------------------------------------------------+
            //| Signal End(Exit Buy)                                             |
            //+------------------------------------------------------------------+

            if (Order == SIGNAL_CLOSEBUY) {
               OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);
               IsTrade = False;
               continue;
            }
            //Trailing stop
            if(TrailingStopMode && TrailingStop > 0) {                 
               if(Bid - OrderOpenPrice() > Point * TrailingStop) {
                  if(OrderStopLoss() < Bid - Point * TrailingStop) {
                     OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);
                    
                     continue;
                  }
               }
            }
         } else {
            //Close

            //+------------------------------------------------------------------+
            //| Signal Begin(Exit Sell)                                          |
            //+------------------------------------------------------------------+

                 if (hma0>hma1 && hma1>hma2) Order = SIGNAL_CLOSESELL;



            //+------------------------------------------------------------------+
            //| Signal End(Exit Sell)                                            |
            //+------------------------------------------------------------------+

            if (Order == SIGNAL_CLOSESELL) {
               OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);
               IsTrade = False;
               continue;
            }
            //Trailing stop
            if(TrailingStopMode && TrailingStop > 0) {                 
               if((OrderOpenPrice() - Ask) > (Point * TrailingStop)) {
                  if((OrderStopLoss() > (Ask + Point * TrailingStop)) || (OrderStopLoss() == 0)) {
                     OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TrailingStop, OrderTakeProfit(), 0, DarkOrange);
                    
                     continue;
                  }
               }
            }
         }
      }
   }        
    //+------------------------------------------------------------------+
   //| Signal Begin(Entry)                                              |
   //+------------------------------------------------------------------+
         if (Buy1_1 > Sell1_1 && Buy1_2 > Sell1_2 && Buy1_3 > Sell1_3) Order = SIGNAL_BUY;

         if (Sell1_1 > Buy1_1 && Sell1_2 > Buy1_2 && Sell1_3 > Buy1_3) Order = SIGNAL_SELL;
         
   //+------------------------------------------------------------------+
   //| Signal End                                                       |
   //+------------------------------------------------------------------+  
   
   
   //Buy
   if (Order == SIGNAL_BUY && MaxTrades<2) {
      if(!IsTrade) {
         //Check free margin
         if (AccountFreeMargin() < (100 * LotSize)) {
            Print("We have no money. Free Margin = ", AccountFreeMargin());
            return(0);
         }

         if (StopLossMode) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0;
         if (TakeProfitMode) TakeProfitLevel = Ask + TakeProfit * Point; else TakeProfitLevel = 0.0;

         Ticket = OrderSend(Symbol(), OP_BUY, LotSize, Ask, Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + main_magic + ")", main_magic, 0, DodgerBlue);
         if(Ticket > 0) {
            if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
                                Print("BUY order opened : ", OrderOpenPrice());
               
                        } else {
                                Print("Error opening BUY order : ", GetLastError());
                        }
         }
       
         return(0);
      }
   }

   //Sell
   if (Order == SIGNAL_SELL && MaxTrades<2 ) {
      if(!IsTrade) {
         //Check free margin
         if (AccountFreeMargin() < (100 * LotSize)) {
            Print("We have no money. Free Margin = ", AccountFreeMargin());
            return(0);
         }

         if (StopLossMode) StopLossLevel = Bid + StopLoss * Point; else StopLossLevel = 0.0;
         if (TakeProfitMode) TakeProfitLevel = Bid - TakeProfit * Point; else TakeProfitLevel = 0.0;

         Ticket = OrderSend(Symbol(), OP_SELL, LotSize, Bid, Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + main_magic + ")", main_magic, 0, DeepPink);
         if(Ticket > 0) {
            if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
                                Print("SELL order opened : ", OrderOpenPrice());
                
                        } else {
                                Print("Error opening SELL order : ", GetLastError());
                        }
         }
        
         return(0);
      }
   }  
         
return(0);
}
int GetSymbolConstant(string symbol) 
  {


   if(symbol=="EURUSD" || symbol=="mEURUSD" || symbol=="EURUSDm") 
     {
      return(1);

        } else if(symbol=="GBPUSD" || symbol=="GBPUSDm") { return(2);

        } else if(symbol=="USDCHF" || symbol=="USDCHFm") {   return(3);

        } else if(symbol=="USDJPY" || symbol=="USDJPYm") {   return(4);

        } else if(symbol=="USDCAD" || symbol=="USDCADm") {   return(5);

        } else if(symbol=="AUDUSD" || symbol=="AUDUSDm") {   return(6);

        } else if(symbol=="CHFJPY" || symbol=="CHFJPYm") {   return(7);

        } else if(symbol=="EURAUD" || symbol=="EURAUDm") {   return(8);

        } else if(symbol=="EURCAD" || symbol=="EURCADm") {   return(9);

        } else if(symbol=="EURCHF" || symbol=="EURCHFm") {   return(10);

        } else if(symbol=="EURGBP" || symbol=="EURGBPm") {   return(11);

        } else if(symbol=="EURJPY" || symbol=="EURJPYm") {   return(12);

        } else if(symbol=="GBPCHF" || symbol=="GBPCHFm") {   return(13);

        } else if(symbol=="GBPJPY" || symbol=="GBPJPYm") {   return(14);

        } else if(symbol=="AUDCHF" || symbol=="AUDCHFm") {   return(15);

        } else if(symbol=="CADJPY" || symbol=="CADJPYm") {   return(16);

        } else if(symbol=="AUDNZD" || symbol=="AUDNZDm") {   return(17);

        } else if(symbol=="AUDJPY" || symbol=="AUDJPYm") {   return(18);

        } else if(symbol=="NZDJPY" || symbol=="NZDJPYm") {   return(19);

        } else if(symbol=="NZDUSD" || symbol=="NZDUSDm") {   return(20);

        } else if(symbol=="XAGUSD" || symbol=="XAGUSDm") {   return(21);

        } else if(symbol=="XAUUSD" || symbol=="XAUUSDm") {   return(22);

        } else if(symbol=="NZDCAD" || symbol=="NZDCADm") {   return(23);

        } else if(symbol=="NZDCHF" || symbol=="NZDCHFm") {   return(24);

        } else if(symbol=="GBPCAD" || symbol=="GBPCADm") {   return(25);

        } else if(symbol=="GBPAUD" || symbol=="GBPAUDm") {   return(26);

        } else if(symbol=="EURNZD" || symbol=="EURNZDm") {   return(27);

        } else if(symbol=="CADCHF" || symbol=="CADCHFm") {   return(28);

        } else if(symbol=="XRPUSD" || symbol=="XRPUSDm") {   return(29);

        } else {Print("Error: Unexpected symbol."); return(0);

     }

  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int func_TimeFrame_Const2Val(int period) 
  {
   switch(period) 
     {
      case 1:  // M1
         return(1);
      case 5:  // M5
         return(2);
      case 15:
         return(3);
      case 30:
         return(4);
      case 60:
         return(5);
      case 240:
         return(6);
      case 1440:
         return(7);
      case 10080:
         return(8);
      case 43200:
         return(9);
     }
   return(0);
  }
//+------------------------------------------------------------------+

            
 
  1. double StopLoss =1.5*iATR(NULL,0,14,0);
    double TakeProfit=iATR(NULL,0,14,0);
    Global and static variables work exactly the same way in MT4/MT5/C/C++.
    1. They are initialized once on program load.
    2. They don't update unless you assign to them.
    3. In C/C++ you can only initialize them with constants, and they default to zero. In MTx you should only initialize them with constants. There is no default in MT5 (or MT4 with strict which you should always use.)

      MT4/MT5 actually compiles with non-constants, but the order that they are initialized is unspecified and don't try to use any price or server related functions in OnInit (or on load,) as there may be no connection/chart yet:

      1. Terminal starts.
      2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
      3. OnInit is called.
      4. For indicators OnCalculate is called with any existing history.
      5. Human may have to enter password, connection to server begins.
      6. New history is received, OnCalculate called again.
      7. New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.
    4. Unlike indicators, EAs are not reloaded on chart change so you must reinitialize them, if necessary.
                external static variable - Inflation - MQL4 programming forum

  2. Why did you post your MT4 question in the Root / MT5 EA section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  3. double Buy1_2=(hf0>hf1);
    What does double= bool mean?

  4.       for (int i = 0; i < Total; i ++) {
          OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
          if(OrderType() <= OP_SELL &&  OrderSymbol() == Symbol()) {
             IsTrade = True;
     
  5. Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
              Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 programming forum
              MagicNumber: "Magic" Identifier of the Order - MQL4 Articles

  6. In the presence of multiple orders (one EA multiple charts, multiple EAs, manual trading,) while you are waiting for the current operation (closing, deleting, modifying) to complete, any number of other operations on other orders could have concurrently happened and changed the position indexing:
    1. For non-FIFO (non-US brokers), (or the EA only opens one order per symbol,) you can simply count down, in a position loop, and you won't miss orders. Get in the habit of always counting down.
                Loops and Closing or Deleting Orders - MQL4 programming forum
      For In First Out (FIFO rules-US brokers,) and you (potentially) process multiple orders per symbol, you must find the earliest order, close it, and on a successful operation, reprocess all remaining positions.
                CloseOrders by FIFO Rules - Strategy Tester - MQL4 programming forum - Page 2 #16

    2. and check OrderSelect in case earlier positions were deleted.
                What are Function return values ? How do I use them ? - MQL4 programming forum
                Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
    3. and if you (potentially) process multiple orders, must call RefreshRates() after server calls if you want to use, on the next order / server call, the Predefined Variables (Bid/Ask) or (be direction independent and use) OrderClosePrice().
  7. Don't double post! You already had this thread open.
              General rules and best pratices of the Forum. - General - MQL5 programming forum
 
Tyrell254:
This is the code please help out

Several issues with this code. You need to fix them one by one and run it in a tester for debugging. If you don't know how to program, post a job in the freelance section. https://www.mql5.com/en/job

  1. MaxTrades is set to 2 and stays this value, yet only trades will open if it's <2 which is never true. There's a counter missing to count all open trades, say OpenTrades, and then instead of MaxTrades<2 you need to place OpenTrades<MaxTrades (although on a 2nd look I think the code will only work with 1 open trade.)
  2. Replace the keywords extern, init/deinit and start with input, OnInit/OnDeinit and OnTick.
  3. The check for OperationsAllowed is wrong when StartHour > LastHour. Should be:
      if(StartHour>LastHour && (Hour()>=StartHour || Hour()<=LastHour)) OperationsAllowed=true;
    
  4. This belongs into OnInit(). Do not initialize StopLoss together with the global variables.
    StopLoss =1.5*iATR(NULL,0,14,0);
    TakeProfit=iATR(NULL,0,14,0);

      There are some more issues but fix this first.

Trading applications for MetaTrader 5 to order
Trading applications for MetaTrader 5 to order
  • www.mql5.com
i need the service of Forex expert to create Trade copier with the following function Fully automated copying  Super fast and precise copying  Support both Provider and Receiver  Support only  Local   Support both Trade and Signal mode  Multi Providers and Receivers allowed  Support unlimited local receivers  Allow set subscription expiry for...
 
Tyrell254:

Do not double post

It is selfish of you to waste other people's time

I have deleted your other posts and moved a reply to here.

 
Keith Watford:

Do not double post

It is selfish of you to waste other people's time

I have deleted your other posts and moved a reply to here.

i Am Sorry
Reason: