Questions from Beginners MQL5 MT5 MetaTrader 5 - page 414

 
Leanid Aladzyeu:

spits

possible loss of data due to type conversion .mq4 1697 29

type Doble at SL.

The compiler is strict nowadays, it should be like this, MarketInfo returns type double

sl = NormalizeDouble(sl,(int)MarketInfo(Symbol(),MODE_DIGITS));
 
Alexey Volchanskiy:

The compiler is strict nowadays, it should be like this, MarketInfo returns type double

The "sumbol" variable is correct, I have it as a variable in the modifier wrapper.

Thanks I put(int) and all is good.

I don't know how I did it before; my experience in writing EAs is 21 days))

I do not know how long I've been writing my EAs and I do not know how to do it properly.)

 

Leanid Aladzyeu:

I don't know how I used to write EAs (I've been writing them for 21 days)). And my EA is persistently making its way to the top of free EAs))

Well, then you are very lucky, until version 600 the old MQL4 was horrible )) Please send me the link to my EA, may be in your mailbox
 
Alexey Volchanskiy:
Well, then you are very lucky, until the 600 version the old MQL4 was horrible )) Please send me the link to the MQL4 Expert Advisor.
To my nickname and product.
 

For some reason it gives an error on the last line.

'}' - not all control paths return a value Expert4.mq4

Every non-void function should end with the return operator.

I'm just looking at this code from the video tutorial, but it may be for an old build.



#include#include <stderror.mqh>

//+------------------------------------------------------------------+
//|Expert4.mq4 |
//|Mikhail |
//||
//+------------------------------------------------------------------+
#property copyright "Mikhail"
#property link ""
#property version "1.00"
#property strict

int signal = 1;

int start()
{
if (signal == 1)
{
OrderSendX (Symbol(), OP_BUY, 0.2, Ask, 30, 0, 0, "Test", 123, 0, Blue);
}
return(0);
}
//+------------------------------------------------------------------+
int OrderSendX (string symbol, int cmd, double volume, double price, int slippage,double stoploss,
double takeprofit,string comment=NULL,int magic=0,datetime expiration=0,color arrow_color=CLR_NONE)
{
int err = GetLastError();
err = 0;
bool exit_loop = false;
int ticket = -1;

int Retry = 10;
int cnt = 0;
if (cmd == OP_BUY || cmd == OP_SELL)
{
while(!exit_loop)
{
ticket = OrderSend(symbol, cmd, volume, price, slippage, stoploss, takeprofit, comment,magic, expiration, arrow_color);
err = GetLastError();

switch(err)
{
case ERR_NO_ERROR:
exit_loop = true;
break;

{ case ERR_SERVER_BUSY:
case ERR_NO_CONNECTION:
case ERR_INVALID_PRICE:
case ERR_OFF_QUOTES:
case ERR_BROKER_BUSY:
case ERR_TRADE_CONTEXT_BUSY:
cnt++;
break;

case ERR_PRICE_CHANGED:


RefreshRates();
continue;

default:
exit_loop +true;
break;

}
if (cnt> Retry)
exit_loop = true;


if (!exit_loop)
{
Sleep(1000);
RefreshRates();

}
else
{
if(err != ERR_NO_ERROR)
{
Print ("ERROR: " + err);

}

}

if(err == ERR_NO_ERROR)
{
OrderSelect(ticket, SELECT_BY_TICKET,MODE_TRADES);
return(ticket);
}

Print("Error: order open failed after" + cnt + "atempts");
return(-1);


}//while
}//if
}//exit
 
Mikhail Nikolaev:

Here....

}


}


return(ticket);

}

 
Mikhail Nikolaev:

Leanid Aladzyeu:

Insert code correctly in the forum

 
Mikhail Nikolaev:

For some reason it gives an error on the last line.

'}' - not all control paths return a value Expert4.mq4

Every non-void function should end with the return operator.

I just watched this code in the video tutorial but it may be for old builds.



#include#include <stderror.mqh>

//+------------------------------------------------------------------+
//|Expert4.mq4 |
//|Mikhail |
//||
//+------------------------------------------------------------------+
#property copyright "Mikhail"
#property link ""
#property version "1.00"
#property strict

int signal = 1;

int start()
{
if (signal == 1)
{
OrderSendX (Symbol(), OP_BUY, 0.2, Ask, 30, 0, 0, "Test", 123, 0, Blue);
}
return(0);
}
//+------------------------------------------------------------------+
int OrderSendX (string symbol, int cmd, double volume, double price, int slippage,double stoploss,
double takeprofit,string comment=NULL,int magic=0,datetime expiration=0,color arrow_color=CLR_NONE)
{
int err = GetLastError();
err = 0;
bool exit_loop = false;
int ticket = -1;

int Retry = 10;
int cnt = 0;
if (cmd == OP_BUY || cmd == OP_SELL)
{
while(!exit_loop)
{
ticket = OrderSend(symbol, cmd, volume, price, slippage, stoploss, takeprofit, comment,magic, expiration, arrow_color);
err = GetLastError();

switch(err)
{
case ERR_NO_ERROR:
exit_loop = true;
break;

{ case ERR_SERVER_BUSY:
case ERR_NO_CONNECTION:
case ERR_INVALID_PRICE:
case ERR_OFF_QUOTES:
case ERR_BROKER_BUSY:
case ERR_TRADE_CONTEXT_BUSY:
cnt++;
break;

case ERR_PRICE_CHANGED:


RefreshRates();
continue;

default:
exit_loop +true;
break;

}
if (cnt> Retry)
exit_loop = true;


if (!exit_loop)
{
Sleep(1000);
RefreshRates();

}
else
{
if(err != ERR_NO_ERROR)
{
Print ("ERROR: " + err);

}

}

if(err == ERR_NO_ERROR)
{
OrderSelect(ticket, SELECT_BY_TICKET,MODE_TRADES);
return(ticket);
}

Print("Error: order open failed after" + cnt + "atempts");
return(-1);


}//while
}//if
}//exit

Man, is it really so hard to format the code? I won't even look at it on principle - it's a pain in the eye.
 
I'm lagging again, it won't fit
 
Leanid Aladzyeu:
I'm lagging again, I can't get it to fit.

It's fine, what browser are you using? Try changing to another one. I have FFox. I gave the answer in the comments in the code at the very end.

#include <stderror.mqh>
//+------------------------------------------------------------------+
//|                                                      Expert4.mq4 |
//|                                                          Mikhail |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Mikhail"
#property link      ""
#property version   "1.00"
#property strict

int signal = 1;

int start()
{
   if (signal == 1)
   {
      OrderSendX (Symbol(), OP_BUY, 0.2, Ask, 30, 0, 0, "Test", 123, 0, Blue);
   }
   return(0);
}
//+------------------------------------------------------------------+
int OrderSendX (string symbol, int cmd, double volume, double price, int slippage,double stoploss,
               double takeprofit, string comment=NULL, int magic=0, datetime expiration=0,color arrow_color=CLR_NONE)
{
   int err = GetLastError();
   err = 0;
   bool exit_loop = false;
   int ticket = -1;
  
   int Retry = 10;
   int cnt = 0;
   if (cmd == OP_BUY || cmd == OP_SELL)
   {
      while(!exit_loop)
      {
         ticket = OrderSend(symbol, cmd, volume, price, slippage, stoploss, takeprofit, comment,magic, expiration, arrow_color);
         err = GetLastError();
        
         switch(err)
         {
            case ERR_NO_ERROR:
            exit_loop = true;
            break;
           
            case ERR_SERVER_BUSY:
            case ERR_NO_CONNECTION:
            case ERR_INVALID_PRICE:
            case ERR_OFF_QUOTES:
            case ERR_BROKER_BUSY:
            case ERR_TRADE_CONTEXT_BUSY:
            cnt++;
            break;
           
            case ERR_PRICE_CHANGED:
           
          
            RefreshRates();
            continue;
           
            default:
               exit_loop +true;
               break;
         
         }
         if (cnt> Retry)
            exit_loop = true;
          
           
         if (!exit_loop)
            {
               Sleep(1000);
               RefreshRates();
              
            }
            else
               {
                  if(err != ERR_NO_ERROR)
                  {
                  Print ("ERROR: " + err);
                 
                  }
            
               }
              
               if(err == ERR_NO_ERROR)
               {
                  OrderSelect(ticket, SELECT_BY_TICKET,MODE_TRADES);
                  return(ticket);
               }
              
               Print("Error: order open failed after" + cnt + "atempts");
               return(-1);
           
           
}//while
}//if
// тут надо вернуть какое-то значение, компилятор не понимает, что у вас есть return-ы внутри while, он не умеет анализировать код. Он ожидает, что при выходе из функции будет возвращаться значение
}//exit
Reason: