Download MetaTrader 5
To add comments, please log in or register
Deposit to your account via Visa QIWI Wallet
Tsz Yau Lo
234
Tsz Yau Lo 2016.03.02 22:57 
// Opening Orders
   while(true){                                                                               // Orders opening Loop
   
   if(TotalOrder==0 && Opn_B==true){                                                          // No opened orders and pending orders + criterion for opening Buy
   RefreshRates();                                                                            // Refresh Rates
   SL=Bid - New_Stop(StopLoss)*Point;                                                         // Calculating SL of opened
   TP=Bid + New_Stop(TakeProfit)*Point;                                                       // Calculating TP of opened
   Alert("Attempt to open Buy. Waiting for response..");
   Ticket=OrderSend(Symb,OP_BUY,LotOpened,Ask,Slippage,SL,TP,NameEA,MagicNumber,0,clrGreen);  // Opening Buy
   if(Ticket>0){                                                                              // Success
   
   Alert("Opened order Buy ",Ticket);
   return;                                                                                    // Exit OnTick()
   
   }
   
   if(Fun_Error(GetLastError())==1)                                                           // Processing errors
   continue;                                                                                  // Retrying
   return;                                                                                    // Exit OnTick()
   
   }
   
   if(TotalOrder==0 && Opn_S==true){                                                               // No opened orders and pending orders + criterion for opening Sell
   RefreshRates();                                                                            // Refresh Rates
   SL=Ask + New_Stop(StopLoss)*Point;                                                         // Calculating SL of opened
   TP=Ask - New_Stop(TakeProfit)*Point;                                                       // Calculating TP of opened
   Alert("Attempt to open Sell. Waiting for response..");
   Ticket=OrderSend(Symb,OP_SELL,LotOpened,Bid,Slippage,SL,TP,NameEA,MagicNumber,0,clrRed);   // Opening Sell
   if(Ticket>0){                                                                              // Success
   
   Alert("Opened order Sell ",Ticket);
   return;                                                                                    // Exit OnTick()
   
   }


   // Checking stop levels

double New_Stop(double Parametr)                      // Checking stop levels
  {
   
   double Min_Dist=MarketInfo(Symb,MODE_STOPLEVEL);   // Minimal distance
  
   if (Parametr < Min_Dist)                           // If less than allowed
     {
  
      Parametr=Min_Dist;                              // Resetting the value to the minimum value allowed
      Alert("Increased distance of stop level.");
  
     }
  
   return(Parametr);                                  // Returning value
  
  }
Hello guys. I have created an EA recently, but the stoploss and takeprofit is not working properly. If I turned off the stoploss and takeprofit (putting 0 in the ordersend() function), the EA works absolutely fine. But if not, the stoploss will keep on happening right after the trade. Can someone plz plz plz help?
/
To add comments, please log in or register