question: why do my EA not send buy stop order successfully?

 

why do my EA not send buy stop order successfully?

Can anyone help me please. 


here's my code:

 

extern double Lots=0.01;
extern double CloseProfit=10;
double pips;
double InitialAsk;
double InitialBid;

///////////////////////////////////////// in pips

extern string UpperBuyStop;            // 
   extern double UBSdistance=1;
   extern int UBSUnits=1;              // 
   extern double UBSTakeProfit=1;
////////////////////////////////////////////////////////////////
double UBS1price=InitialAsk+UBSdistance*pips;
double UBS2price=InitialAsk+UBSdistance*pips*2;
double UBS3price=InitialAsk+UBSdistance*pips*3;
double UBS4price=InitialAsk+UBSdistance*pips*4;
double UBS5price=InitialAsk+UBSdistance*pips*5;
double UBS6price=InitialAsk+UBSdistance*pips*6;
double UBS7price=InitialAsk+UBSdistance*pips*7;
double UBS8price=InitialAsk+UBSdistance*pips*8;
double UBS9price=InitialAsk+UBSdistance*pips*9;
double UBS10price=InitialAsk+UBSdistance*pips*10;
double UBS11price=InitialAsk+UBSdistance*pips*11;
double UBS12price=InitialAsk+UBSdistance*pips*12;
double UBS13price=InitialAsk+UBSdistance*pips*13;
double UBS14price=InitialAsk+UBSdistance*pips*14;
double UBS15price=InitialAsk+UBSdistance*pips*15;
double UBS16price=InitialAsk+UBSdistance*pips*16;
double UBS17price=InitialAsk+UBSdistance*pips*17;
double UBS18price=InitialAsk+UBSdistance*pips*18;
double UBS19price=InitialAsk+UBSdistance*pips*19;
double UBS20price=InitialAsk+UBSdistance*pips*20;


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   double ticksize = MarketInfo(Symbol(),MODE_TICKSIZE);
   if(ticksize == 0.00001 || ticksize == 0.001)
   pips = ticksize*10;
   else pips = ticksize;
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
int start()
  {
//---
   if(OrdersTotal()==0)
      {
      InitialAsk= MarketInfo(Symbol(),MODE_ASK);
      InitialBid= MarketInfo(Symbol(),MODE_BID);
      }   
   UBSmodule();
//---
   return(0);     
  }
//+------------------------------------------------------------------+
void UBSmodule()
   {
      if(UBSUnits==1)
         {
            checkUBS1();
         }
      if(UBSUnits==2)
         {
            checkUBS1();
            checkUBS2();
         }
      if(UBSUnits==3)
         {
            checkUBS1();
            checkUBS2();
            checkUBS3();
         }
      if(UBSUnits==4)
         {
            checkUBS1();
            checkUBS2();
            checkUBS3();
            checkUBS4();
         }
      if(UBSUnits==5)
         {
            checkUBS1();
            checkUBS2();
            checkUBS3();
            checkUBS4();
            checkUBS5();
         }
      if(UBSUnits==6)
         {
            checkUBS1();
            checkUBS2();
            checkUBS3();
            checkUBS4();
            checkUBS5();
            checkUBS6();
         }
      if(UBSUnits==7)
         {
            checkUBS1();
            checkUBS2();
            checkUBS3();
            checkUBS4();
            checkUBS5();
            checkUBS6();
            checkUBS7();
         }
      if(UBSUnits==8)
         {
            checkUBS1();
            checkUBS2();
            checkUBS3();
            checkUBS4();
            checkUBS5();
            checkUBS6();
            checkUBS7();
            checkUBS8();
         }
      if(UBSUnits==9)
         {
            checkUBS1();
            checkUBS2();
            checkUBS3();
            checkUBS4();
            checkUBS5();
            checkUBS6();
            checkUBS7();
            checkUBS8();
            checkUBS9();
         }
      if(UBSUnits==10)
         {
            checkUBS1();
            checkUBS2();
            checkUBS3();
            checkUBS4();
            checkUBS5();
            checkUBS6();
            checkUBS7();
            checkUBS8();
            checkUBS9();
            checkUBS10();
         }
      if(UBSUnits==11)
         {
            checkUBS1();
            checkUBS2();
            checkUBS3();
            checkUBS4();
            checkUBS5();
            checkUBS6();
            checkUBS7();
            checkUBS8();
            checkUBS9();
            checkUBS10();
            checkUBS11();
         }
      if(UBSUnits==12)
         {
            checkUBS1();
            checkUBS2();
            checkUBS3();
            checkUBS4();
            checkUBS5();
            checkUBS6();
            checkUBS7();
            checkUBS8();
            checkUBS9();
            checkUBS10();
            checkUBS11();
            checkUBS12();
         }
      if(UBSUnits==13)
         {
            checkUBS1();
            checkUBS2();
            checkUBS3();
            checkUBS4();
            checkUBS5();
            checkUBS6();
            checkUBS7();
            checkUBS8();
            checkUBS9();
            checkUBS10();
            checkUBS11();
            checkUBS12();
            checkUBS13();
         }
      if(UBSUnits==14)
         {
            checkUBS1();
            checkUBS2();
            checkUBS3();
            checkUBS4();
            checkUBS5();
            checkUBS6();
            checkUBS7();
            checkUBS8();
            checkUBS9();
            checkUBS10();
            checkUBS11();
            checkUBS12();
            checkUBS13();
            checkUBS14();
         }
      if(UBSUnits==15)
         {
            checkUBS1();
            checkUBS2();
            checkUBS3();
            checkUBS4();
            checkUBS5();
            checkUBS6();
            checkUBS7();
            checkUBS8();
            checkUBS9();
            checkUBS10();
            checkUBS11();
            checkUBS12();
            checkUBS13();
            checkUBS14();
            checkUBS15();
         }
      if(UBSUnits==16)
         {
            checkUBS1();
            checkUBS2();
            checkUBS3();
            checkUBS4();
            checkUBS5();
            checkUBS6();
            checkUBS7();
            checkUBS8();
            checkUBS9();
            checkUBS10();
            checkUBS11();
            checkUBS12();
            checkUBS13();
            checkUBS14();
            checkUBS15();
            checkUBS16();
         }
      if(UBSUnits==17)
         {
            checkUBS1();
            checkUBS2();
            checkUBS3();
            checkUBS4();
            checkUBS5();
            checkUBS6();
            checkUBS7();
            checkUBS8();
            checkUBS9();
            checkUBS10();
            checkUBS11();
            checkUBS12();
            checkUBS13();
            checkUBS14();
            checkUBS15();
            checkUBS16();
            checkUBS17();
         }
      if(UBSUnits==18)
         {
            checkUBS1();
            checkUBS2();
            checkUBS3();
            checkUBS4();
            checkUBS5();
            checkUBS6();
            checkUBS7();
            checkUBS8();
            checkUBS9();
            checkUBS10();
            checkUBS11();
            checkUBS12();
            checkUBS13();
            checkUBS14();
            checkUBS15();
            checkUBS16();
            checkUBS17();
            checkUBS18();
         }
      if(UBSUnits==19)
         {
            checkUBS1();
            checkUBS2();
            checkUBS3();
            checkUBS4();
            checkUBS5();
            checkUBS6();
            checkUBS7();
            checkUBS8();
            checkUBS9();
            checkUBS10();
            checkUBS11();
            checkUBS12();
            checkUBS13();
            checkUBS14();
            checkUBS15();
            checkUBS16();
            checkUBS17();
            checkUBS18();
            checkUBS19();
         }
      if(UBSUnits==20)
         {
            checkUBS1();
            checkUBS2();
            checkUBS3();
            checkUBS4();
            checkUBS5();
            checkUBS6();
            checkUBS7();
            checkUBS8();
            checkUBS9();
            checkUBS10();
            checkUBS11();
            checkUBS12();
            checkUBS13();
            checkUBS14();
            checkUBS15();
            checkUBS16();
            checkUBS17();
            checkUBS18();
            checkUBS19();
            checkUBS20();
         }

   }
void checkUBS1()
   {
   int total=0;
   for(int o=OrdersTotal()-1; o>=0; o--)
      {
         OrderSelect(o,SELECT_BY_POS,MODE_TRADES);
         if(UBS1price == OrderOpenPrice()) total++;
      }
   if(total==0) 
      {
         double UBS1tp;
         if(UBSTakeProfit==0) UBS1tp=0;
         else UBS1tp = UBS1price+(UBSTakeProfit*pips);
         if(Ask<UBS1price) OrderSend(Symbol(),OP_BUYSTOP,Lots,UBS1price,3,0,UBS1tp,NULL,0,0,clrRed);
      }
   }
void checkUBS2()
   {
   int total=0;
   for(int o=OrdersTotal()-1; o>=0; o--)
      {
         OrderSelect(o,SELECT_BY_POS,MODE_TRADES);
         if(UBS2price == OrderOpenPrice()) total++;
      }
   if(total==0) 
      {
         double UBS2tp;
         if(UBSTakeProfit==0) UBS2tp=0;
         else UBS2tp = UBS2price+(UBSTakeProfit*pips);
         if(Ask<UBS2price) OrderSend(Symbol(),OP_BUYSTOP,Lots,UBS2price,3,0,UBS2tp,NULL,0,0,clrRed);
      }
   }
void checkUBS3()
   {
   int total=0;
   for(int o=OrdersTotal()-1; o>=0; o--)
      {
         OrderSelect(o,SELECT_BY_POS,MODE_TRADES);
         if(UBS3price == OrderOpenPrice()) total++;
      }
   if(total==0) 
      {
         double UBS3tp;
         if(UBSTakeProfit==0) UBS3tp=0;
         else UBS3tp = UBS3price+(UBSTakeProfit*pips);
         if(Ask<UBS3price) OrderSend(Symbol(),OP_BUYSTOP,Lots,UBS3price,3,0,UBS3tp,NULL,0,0,clrRed);
      }
   }
void checkUBS4()
   {
   int total=0;
   for(int o=OrdersTotal()-1; o>=0; o--)
      {
         OrderSelect(o,SELECT_BY_POS,MODE_TRADES);
         if(UBS4price == OrderOpenPrice()) total++;
      }
   if(total==0) 
      {
         double UBS4tp;
         if(UBSTakeProfit==0) UBS4tp=0;
         else UBS4tp = UBS4price+(UBSTakeProfit*pips);
         if(Ask<UBS4price) OrderSend(Symbol(),OP_BUYSTOP,Lots,UBS4price,3,0,UBS4tp,NULL,0,0,clrRed);
      }
   }
void checkUBS5()
   {
   int total=0;
   for(int o=OrdersTotal()-1; o>=0; o--)
      {
         OrderSelect(o,SELECT_BY_POS,MODE_TRADES);
         if(UBS5price == OrderOpenPrice()) total++;
      }
   if(total==0) 
      {
         double UBS5tp;
         if(UBSTakeProfit==0) UBS5tp=0;
         else UBS5tp = UBS5price+(UBSTakeProfit*pips);
         if(Ask<UBS5price) OrderSend(Symbol(),OP_BUYSTOP,Lots,UBS5price,3,0,UBS5tp,NULL,0,0,clrRed);
      }
   }
void checkUBS6()
   {
   int total=0;
   for(int o=OrdersTotal()-1; o>=0; o--)
      {
         OrderSelect(o,SELECT_BY_POS,MODE_TRADES);
         if(UBS6price == OrderOpenPrice()) total++;
      }
   if(total==0) 
      {
         double UBS6tp;
         if(UBSTakeProfit==0) UBS6tp=0;
         else UBS6tp = UBS6price+(UBSTakeProfit*pips);
         if(Ask<UBS6price) OrderSend(Symbol(),OP_BUYSTOP,Lots,UBS6price,3,0,UBS6tp,NULL,0,0,clrRed);
      }
   }
void checkUBS7()
   {
   int total=0;
   for(int o=OrdersTotal()-1; o>=0; o--)
      {
         OrderSelect(o,SELECT_BY_POS,MODE_TRADES);
         if(UBS7price == OrderOpenPrice()) total++;
      }
   if(total==0) 
      {
         double UBS7tp;
         if(UBSTakeProfit==0) UBS7tp=0;
         else UBS7tp = UBS7price+(UBSTakeProfit*pips);
         if(Ask<UBS7price) OrderSend(Symbol(),OP_BUYSTOP,Lots,UBS7price,3,0,UBS7tp,NULL,0,0,clrRed);
      }
   }
void checkUBS8()
   {
   int total=0;
   for(int o=OrdersTotal()-1; o>=0; o--)
      {
         OrderSelect(o,SELECT_BY_POS,MODE_TRADES);
         if(UBS8price == OrderOpenPrice()) total++;
      }
   if(total==0) 
      {
         double UBS8tp;
         if(UBSTakeProfit==0) UBS8tp=0;
         else UBS8tp = UBS8price+(UBSTakeProfit*pips);
         if(Ask<UBS8price) OrderSend(Symbol(),OP_BUYSTOP,Lots,UBS8price,3,0,UBS8tp,NULL,0,0,clrRed);
      }
   }
void checkUBS9()
   {
   int total=0;
   for(int o=OrdersTotal()-1; o>=0; o--)
      {
         OrderSelect(o,SELECT_BY_POS,MODE_TRADES);
         if(UBS9price == OrderOpenPrice()) total++;
      }
   if(total==0) 
      {
         double UBS9tp;
         if(UBSTakeProfit==0) UBS9tp=0;
         else UBS9tp = UBS9price+(UBSTakeProfit*pips);
         if(Ask<UBS9price) OrderSend(Symbol(),OP_BUYSTOP,Lots,UBS9price,3,0,UBS9tp,NULL,0,0,clrRed);
      }
   }
void checkUBS10()
   {
   int total=0;
   for(int o=OrdersTotal()-1; o>=0; o--)
      {
         OrderSelect(o,SELECT_BY_POS,MODE_TRADES);
         if(UBS10price == OrderOpenPrice()) total++;
      }
   if(total==0) 
      {
         double UBS10tp;
         if(UBSTakeProfit==0) UBS10tp=0;
         else UBS10tp = UBS10price+(UBSTakeProfit*pips);
         if(Ask<UBS10price) OrderSend(Symbol(),OP_BUYSTOP,Lots,UBS10price,3,0,UBS10tp,NULL,0,0,clrRed);
      }
   }
void checkUBS11()
   {
   int total=0;
   for(int o=OrdersTotal()-1; o>=0; o--)
      {
         OrderSelect(o,SELECT_BY_POS,MODE_TRADES);
         if(UBS11price == OrderOpenPrice()) total++;
      }
   if(total==0) 
      {
         double UBS11tp;
         if(UBSTakeProfit==0) UBS11tp=0;
         else UBS11tp = UBS11price+(UBSTakeProfit*pips);
         if(Ask<UBS11price) OrderSend(Symbol(),OP_BUYSTOP,Lots,UBS11price,3,0,UBS11tp,NULL,0,0,clrRed);
      }
   }
void checkUBS12()
   {
   int total=0;
   for(int o=OrdersTotal()-1; o>=0; o--)
      {
         OrderSelect(o,SELECT_BY_POS,MODE_TRADES);
         if(UBS12price == OrderOpenPrice()) total++;
      }
   if(total==0) 
      {
         double UBS12tp;
         if(UBSTakeProfit==0) UBS12tp=0;
         else UBS12tp = UBS12price+(UBSTakeProfit*pips);
         if(Ask<UBS12price) OrderSend(Symbol(),OP_BUYSTOP,Lots,UBS12price,3,0,UBS12tp,NULL,0,0,clrRed);
      }
   }
void checkUBS13()
   {
   int total=0;
   for(int o=OrdersTotal()-1; o>=0; o--)
      {
         OrderSelect(o,SELECT_BY_POS,MODE_TRADES);
         if(UBS13price == OrderOpenPrice()) total++;
      }
   if(total==0) 
      {
         double UBS13tp;
         if(UBSTakeProfit==0) UBS13tp=0;
         else UBS13tp = UBS13price+(UBSTakeProfit*pips);
         if(Ask<UBS13price) OrderSend(Symbol(),OP_BUYSTOP,Lots,UBS13price,3,0,UBS13tp,NULL,0,0,clrRed);
      }
   }
void checkUBS14()
   {
   int total=0;
   for(int o=OrdersTotal()-1; o>=0; o--)
      {
         OrderSelect(o,SELECT_BY_POS,MODE_TRADES);
         if(UBS14price == OrderOpenPrice()) total++;
      }
   if(total==0) 
      {
         double UBS14tp;
         if(UBSTakeProfit==0) UBS14tp=0;
         else UBS14tp = UBS14price+(UBSTakeProfit*pips);
         if(Ask<UBS14price) OrderSend(Symbol(),OP_BUYSTOP,Lots,UBS14price,3,0,UBS14tp,NULL,0,0,clrRed);
      }
   }
void checkUBS15()
   {
   int total=0;
   for(int o=OrdersTotal()-1; o>=0; o--)
      {
         OrderSelect(o,SELECT_BY_POS,MODE_TRADES);
         if(UBS15price == OrderOpenPrice()) total++;
      }
   if(total==0) 
      {
         double UBS15tp;
         if(UBSTakeProfit==0) UBS15tp=0;
         else UBS15tp = UBS15price+(UBSTakeProfit*pips);
         if(Ask<UBS15price) OrderSend(Symbol(),OP_BUYSTOP,Lots,UBS15price,3,0,UBS15tp,NULL,0,0,clrRed);
      }
   }
void checkUBS16()
   {
   int total=0;
   for(int o=OrdersTotal()-1; o>=0; o--)
      {
         OrderSelect(o,SELECT_BY_POS,MODE_TRADES);
         if(UBS16price == OrderOpenPrice()) total++;
      }
   if(total==0) 
      {
         double UBS16tp;
         if(UBSTakeProfit==0) UBS16tp=0;
         else UBS16tp = UBS16price+(UBSTakeProfit*pips);
         if(Ask<UBS16price) OrderSend(Symbol(),OP_BUYSTOP,Lots,UBS16price,3,0,UBS16tp,NULL,0,0,clrRed);
      }
   }
void checkUBS17()
   {
   int total=0;
   for(int o=OrdersTotal()-1; o>=0; o--)
      {
         OrderSelect(o,SELECT_BY_POS,MODE_TRADES);
         if(UBS17price == OrderOpenPrice()) total++;
      }
   if(total==0) 
      {
         double UBS17tp;
         if(UBSTakeProfit==0) UBS17tp=0;
         else UBS17tp = UBS17price+(UBSTakeProfit*pips);
         if(Ask<UBS17price) OrderSend(Symbol(),OP_BUYSTOP,Lots,UBS17price,3,0,UBS17tp,NULL,0,0,clrRed);
      }
   }
void checkUBS18()
   {
   int total=0;
   for(int o=OrdersTotal()-1; o>=0; o--)
      {
         OrderSelect(o,SELECT_BY_POS,MODE_TRADES);
         if(UBS18price == OrderOpenPrice()) total++;
      }
   if(total==0) 
      {
         double UBS18tp;
         if(UBSTakeProfit==0) UBS18tp=0;
         else UBS18tp = UBS18price+(UBSTakeProfit*pips);
         if(Ask<UBS18price) OrderSend(Symbol(),OP_BUYSTOP,Lots,UBS18price,3,0,UBS18tp,NULL,0,0,clrRed);
      }
   }
void checkUBS19()
   {
   int total=0;
   for(int o=OrdersTotal()-1; o>=0; o--)
      {
         OrderSelect(o,SELECT_BY_POS,MODE_TRADES);
         if(UBS19price == OrderOpenPrice()) total++;
      }
   if(total==0) 
      {
         double UBS19tp;
         if(UBSTakeProfit==0) UBS19tp=0;
         else UBS19tp = UBS19price+(UBSTakeProfit*pips);
         if(Ask<UBS19price) OrderSend(Symbol(),OP_BUYSTOP,Lots,UBS19price,3,0,UBS19tp,NULL,0,0,clrRed);
      }
   }
void checkUBS20()
   {
   int total=0;
   for(int o=OrdersTotal()-1; o>=0; o--)
      {
         OrderSelect(o,SELECT_BY_POS,MODE_TRADES);
         if(UBS20price == OrderOpenPrice()) total++;
      }
   if(total==0) 
      {
         double UBS20tp;
         if(UBSTakeProfit==0) UBS20tp=0;
         else UBS20tp = UBS20price+(UBSTakeProfit*pips);
         if(Ask<UBS20price) OrderSend(Symbol(),OP_BUYSTOP,Lots,UBS20price,3,0,UBS20tp,NULL,0,0,clrRed);
      }
   }
Files:
abc.mq4  38 kb
 
ok626569: why do my EA not send buy stop order successfully?
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Check your return codes and find out why. What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles