Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1227

 

Hi all, just a quick refresher on the thread: There's a question in the code:

int stoplevel;
int  MinimumUseStopLevel;

// Calculate stoplevel as max of either STOPLEVEL or FREEZELEVEL
   stoplevel = fmax(SymbolInfoInteger(_Symbol,MODE_FREEZELEVEL), SymbolInfoInteger(_Symbol,SYMBOL_TRADE_STOPS_LEVEL));
// Then calculate the stoplevel as max of either this stoplevel or MinimumUseStopLevel
   stoplevel = fmax(MinimumUseStopLevel, stoplevel);

When compiling, it generates a warning:"possible loss of data due to type conversion ...". What does he need? It's not so critical, but I'd like to know.


Документация по MQL5: Основы языка / Типы данных / Приведение типов
Документация по MQL5: Основы языка / Типы данных / Приведение типов
  • www.mql5.com
Часто возникает необходимость преобразовать один числовой тип в другой. Не каждый числовой тип допустимо преобразовать в другой, допустимые преобразования в MQL5 показаны на схеме: Сплошные линии со стрелками обозначают преобразования, которые выполняются без потери информации. Вместо типа char может выступать тип bool (оба занимают в памяти 1...
 
Sayberix:

Hi all, just a quick refresher on the thread: There's a question in the code:

When compiling, it generates a warning:"possible loss of data due to type conversion ...". What does he need? Not so critical, but would like to know.


The site engine itself inserted a link to the answer, and there is an example of explicit type conversion .........

//--- ускорение свободного падения
   double g=9.8;
   double round_g=(int)g;
   double math_round_g=MathRound(g);
   Print("round_g = ",round_g);
   Print("math_round_g =",math_round_g);
/*
   Результат:
   round_g = 9
   math_round_g = 10
*/
 
Sayberix:

Hi all, just a quick refresher on the thread: There's a question in the code:

When compiling, it generates a warning:"possible loss of data due to type conversion ...". What does he need? It's not that crucial, but I'd like to know.


You have not only a warning but an error as well. Are you sure it's this particular code you're compiling?

That's how it should be:

   int stoplevel=0;
   int MinimumUseStopLevel=0;

// Calculate stoplevel as max of either STOPLEVEL or FREEZELEVEL
   stoplevel = int(fmax(SymbolInfoInteger(_Symbol,SYMBOL_TRADE_FREEZE_LEVEL), SymbolInfoInteger(_Symbol,SYMBOL_TRADE_STOPS_LEVEL)));
// Then calculate the stoplevel as max of either this stoplevel or MinimumUseStopLevel
   stoplevel = int(fmax((int)MinimumUseStopLevel,(int)stoplevel));

It's just without digging into the code - so you don't get errors and warnings.

And if you think about it, you're mixing the warm and the wet

 
Artyom Trishkin:

Not only do you have a warning, you also have an error. Are you sure this is the code you are compiling?

That's the way it should be:

It's just without digging into the code - so you don't get errors and warnings.

And if you think about it, you're mixing things up.

Thank you.

Don't scold me, I'm just learning - trying to understand other people's code. Seems to me it's the quickest way to learn.

I don't understand why he needs type conversion, if all variables are int and return values via symbolinfointeger ?

 
Sayberix:

Thank you.

Don't scold me too much, I'm just learning - trying to make sense of other people's code. Seems to me this is the fastest way to learn.

I don't understand why it needs type conversion, if all variables are int and return values via symbolinfointeger ?

SymbolInfoInteger() returns long
Документация по MQL5: Получение рыночной информации / SymbolInfoInteger
Документация по MQL5: Получение рыночной информации / SymbolInfoInteger
  • www.mql5.com
2. Возвращает true или false в зависимости от успешности выполнения функции.  В случае успеха значение свойства помещается в приемную переменную, передаваемую по ссылке последним параметром. Если функция используется для получения информации о последнем тике, то лучше использовать SymbolInfoTick(). Вполне возможно, что по данному символу с...
 

Good day dear programmers!

How can I make my EA open positions irrespective of positions opened manually or other positions opened by another EA? I tried to do it with magic, but it did not work. I tried to do it with magic, but it did not work:

datetime some_time=TimeCurrent();
extern string Symbol3 = ""; //Инструмент (""текущий по умолчанию)
extern int P=1;          //Таймфрейм
extern int MagicNumber = 100500;


int start()
{

int send;
                                      
double SL=50;                                   
double TP=50;                       
double Lots=3;       

      
//&&(OrderMagicNumber() == MagicNumber)
//&&(OrdersTotal() ==0)&&    
 
              
if ((Close[0]>High[1])&&(OrderMagicNumber() != MagicNumber)) 
{
send=OrderSend(Symbol3,OP_BUY,Lots,Ask,3,Bid-SL*Point,Bid+TP*Point,MagicNumber);
}

if ((Close[0]<Low[1])&&(OrderMagicNumber() != MagicNumber))
{
send=OrderSend(Symbol3,OP_SELL,Lots,Bid,3,Ask+SL*Point,Ask-TP*Point,MagicNumber);
}

return(0);
}
 
Alexey Belyakov:

Good day dear programmers!

How can I make my EA open positions irrespective of positions opened manually or other positions opened by another EA? I tried to do it with magic, but it did not work. Here is the code:


You are missing fields and no order is selected to check number

int n = 0;
for(int i = OrdersTotal(); i >= 0; i--) {
      if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES))continue;
      if(OrderSymbol() != _Symbol)continue;
      if(OrderMagicNumber() != magic)continue;     
n++;
}

if(n == 0){
OrderSend(_Symbol, _type, lot, price, 0, sl, tp, comment, magic, 0, clrNONE);
}
 
How to withdraw money from an account

 
Help... Put it in and can't get it out
 
Georgiy Liashchenko:


You have missing fields and the order to check the number is not being highlighted

I did. I didn't. It opens in packs. Magic's ignoring it.


datetime some_time=TimeCurrent();
//extern string Symbol3 = ""; //Инструмент (""текущий по умолчанию)
extern int P=1;          //Таймфрейм
extern int MagicNumber = 100500;


int start()
{

int send;
                                     
double SL=200;                                   
double TP=200;                       
double Lots=1;       

int n = 0;
for(int i = OrdersTotal(); i >= 0; i--) 
{
      if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES))continue;
      if(OrderSymbol() != "EURUSD")continue;
      if(OrderMagicNumber() != MagicNumber)continue;     
n++;
}
          
//&&(OrderMagicNumber() == MagicNumber)
//&&(OrdersTotal() ==0)&&    
             
if ((Close[0]>High[1])&&(n==0))
{
send=OrderSend("EURUSD",OP_BUY,Lots,Ask,3,Bid-SL*Point,Bid+TP*Point,MagicNumber);
}

if ((Close[0]<Low[1])&&(n==0))  
{
send=OrderSend("EURUSD",OP_SELL,Lots,Bid,3,Ask+SL*Point,Ask-TP*Point,MagicNumber);
}

return(0);
}

Reason: