warnings buy and sell function

To add comments, please log in or register
texoro
160
texoro  
Hi guys,

I made these 2 small methods:

int OpenSell()
   {
      double SL=Ask - (StopLoss*Point);     // Calculating SL of opened
      double TP=Ask + (TakeProfit*Point);   // Calculating TP of opened
      OrderSend(Symbol(),OP_SELL,lotti,Bid,2,SL,TP,0,0,0,clrGreen);
      return(0);
   }

void OpenBuy()
   {
      SL=Bid - (StopLoss*Point);     // Calculating SL of opened
      TP=Bid + (TakeProfit*Point);   // Calculating TP of opened
      OrderSend(Symbol(), OP_BUY,lotti,Ask,2,SL,TP,0,0,0,clrGreen);
   }

I've these problems:

1) Return error message : "return value of 'OrderSend' should be checked"

2) When I open an order, I can not set "Stop" and "TakeProfit"

whroeder1
17949
whroeder1  

Check your return codes and you would know why.

Check your return codes for errors and report them.
          What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
          Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
Only those functions that return a value (e.g. iClose, MarketInfo, etc.) must you call ResetLastError before in order to check after.

texoro
160
texoro  
whroeder1:

Check your return codes and you would know why.

Check your return codes for errors and report them.
          What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
          Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
Only those functions that return a value (e.g. iClose, MarketInfo, etc.) must you call ResetLastError before in order to check after.


I solved the first point by Handling the error, but when it opens a position does not set TP and STOP.

texoro
160
texoro  
whroeder1:

Check your return codes and you would know why.

Check your return codes for errors and report them.
          What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
          Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
Only those functions that return a value (e.g. iClose, MarketInfo, etc.) must you call ResetLastError before in order to check after.

Hi Guys, I've arranged the functions in the following way:

int OpenSell()
{
   
   double SL, TP; int Ticket;   
   SL=Ask + (StopLoss*Point);     // Calculating SL of opened
   TP=Ask - (TakeProfit*Point);   // Calculating TP of opened
   Ticket = OrderSend(Symbol(),OP_SELL,lotti,Bid,2,SL,TP,0,0,0,clrGreen);
   if (Ticket > 0)                        // Success :)
   {
      Print("Opened order sell ",Ticket);                                                                                                                 
      return(0);                             // Exit start()
   }
   if (Fun_Error(GetLastError())==1)      // Processing errors
   return(-1);                                // Exit start()
}

int OpenBuy()
{

   double SL, TP; int Ticket;   
   SL=Bid - (StopLoss*Point);     // Calculating SL of opened
   TP=Bid + (TakeProfit*Point);   // Calculating TP of opened
   Ticket = OrderSend(Symbol(), OP_BUY,lotti,Ask,2,SL,TP,0,0,0,clrGreen);
   if (Ticket > 0)                        // Success :)
   {
      Print("Opened order Buy ",Ticket);                                                                                                                 
      return(0);                             // Exit start()
   }
   if (Fun_Error(GetLastError())==1)      // Processing errors
   return(-1);                                // Exit start()

and just for proof I created this "start":.......................................

   double ImaVeloceSignalOld=iMA(NULL,timeframe,mediaVelocePeriod,0,TipoMediaVeloce,PRICE_CLOSE,1); 
   double ImaLentaSignalOld=iMA(NULL,timeframe,mediaLentaPeriod,0,TipoMediaLenta,PRICE_CLOSE,1);
   double ImaVeloceSignalCurr=iMA(NULL,timeframe,mediaVelocePeriod,0,TipoMediaVeloce,PRICE_CLOSE,0); 
   double ImaLentaSignalCurr=iMA(NULL,timeframe,mediaLentaPeriod,0,TipoMediaLenta,PRICE_CLOSE,0);
  
   if (ImaLentaSignalOld<ImaVeloceSignalOld)
   {                       
      if (ImaLentaSignalCurr>ImaVeloceSignalCurr)
      {
        OpenBuy();
      } 
   }         
   if (ImaVeloceSignalOld<ImaLentaSignalOld)
   {           
      if (ImaVeloceSignalCurr>ImaLentaSignalCurr)
         {
            OpenSell();
         }
   }


I no longer have the problem "return error message:" Return value of ' OrderSend ' should be checked "Int OpenSell ()";

When I try to do a "back test" I can't open any position and if I try to execute in the diary I've this message "Expert crossing medium 1 ′ is not expert and cannot be executed";

When I run the backtest in the diary it gives me the following error:

2018.01.24 15:16:09.389 TestGenerator: unmatched data error (volume limit 162 at 2018.01.24 14:15 exceeded)




To add comments, please log in or register