Questions from Beginners MQL5 MT5 MetaTrader 5 - page 24

 
Please tell me, I am using one function inside another. In outer I declare a variable. In the internal one, I use it. Here is about
  string PositionSymboll = "";
   if  (PositionSymboll=PositionGetSymbol(i)){//Возвращает символ соответствующей открытой позиции и автоматически выбирает позицию для дальнейшей работы с ней
    if (PositionGetInteger(POSITION_MAGIC)== MAGIC)//Функция возвращает запрошенное свойство открытой позиции, предварительно выбранной
              { BU_();}}

Etc. It swears like this. 'PositionSymboll' - undeclared identifier Redo.mq5 2472 5

I honestly didn't expect any catch here. If I encapsulate it inside the BU_() function I'm using, the pyrimen will "null". What should I do better?

It would be very good for me to declare it inside the first function, inside the if loop.

 
Oh, you! And even by declaring it inside void OnTick() function, the compiler also swears the same, already on the first function! I'm out, I'm out...
 
Dimka-novitsek:
Oh, you! And even declaring it inside the void OnTick() function, the compiler also blows up, already on the first function! I'll pass, just fell out...
void OnStart()
  {
   int i=0; long MAGIC=1234;
   
   string PositionSymboll="";
   if(PositionSymboll=PositionGetSymbol(i))
     {//Возвращает символ соответствующей открытой позиции и автоматически выбирает позицию для дальнейшей работы с ней
      if(PositionGetInteger(POSITION_MAGIC)==MAGIC)//Функция возвращает запрошенное свойство открытой позиции, предварительно выбранной
        { BU_();}
     }
  }
void  BU_(){} 

compiles normally, but the construct

string PositionSymboll="";
   if(PositionSymboll)

questionable, are you checking for true/false string variable ????????? i'm puzzled

the question is rhetorical.

 
Thank you!!! I'm still just learning, this is my first EA in MQL5. What do you mean by rhetorical?
 
Dimka-novitsek:
Thanks!!! I'm still just learning, this is my first EA in MQL5. What do you mean by rhetorical?

This means not requiring a response.

Just a string type variable passed as an expression in an if statement, will only give false in one case, if the variable has not been initialised.

In all other cases the variable content will be given out true.

 
Thank you!!!
 

Could you please tell me if there is a function that should return true if there is a pending order at the price sent to the function. But it returns "bald" (alternately true/false). Please advise where I'm missing the logic of working with orders in mql5? (just learning).


bool OrderExist(double price)                                                                      // функция возвращает наличие ордера на передаваемой цене
{
         
uint total=OrdersTotal();
ulong    ticket;

for(uint i=0;i<total;i++)
   {
   if((ticket=OrderGetTicket(i))>0)      
      {
      if(NormalizeDouble(OrderGetDouble(ORDER_PRICE_OPEN),4)== price)
         {
         return(true);
         }
      }
   }
return(false);
}
Документация по MQL5: Стандартные константы, перечисления и структуры / Торговые константы / Свойства ордеров
Документация по MQL5: Стандартные константы, перечисления и структуры / Торговые константы / Свойства ордеров
  • www.mql5.com
Стандартные константы, перечисления и структуры / Торговые константы / Свойства ордеров - Документация по MQL5
 
DMXX:

Please advise, there is a function that should return true if there is a pending order at the price I have sent to the function. But it returns bald one (alternately true/false). Please advise where I'm missing the logic of working with orders in mql5? (just learning).

But it is not certain that the order opened at the given price, there might have been slippage, so I get the following: if the order opened on time - true, if it didn't (the price has shifted) - false.

 
fyords:
But it's not the fact that the order was opened at the set price, slippage could have occurred and that's why we have the following result: if the order was opened in time - true, if it was not opened in time (the price moved) - false.
Yes, it is displayed in the terminal at this price. If it is in operations, it means that it has been placed successfully, right?
 
DMXX:
Yes, it is hanging in the terminal at this price. If it is in operations, it means that it is placed successfully, right?

Yes, it is set, but when it is triggered...

Or another example: we have a pending order, its price differs from the current one by 1 point, at the next tick the price jumps not by 1 point, but, let us say, by 3-5 points, which results in opening at a wrong price. An obvious example is a gap.

Or maybe I do not understand the question and am dumb.

Reason: