Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1051

 
secret:

Thanks for the reply, I've looked at both the documentation and your example, but still haven't found how to get a parameter similar to OrderClosePrice() in MT4.

If ENUM_DEAL_ENTRY ==DEAL_ENTRY_OUT && ENUM_DEAL_TYPE == DEAL_TYPE_SELL --- it means that BUY position was closed and therefore DEAL_PRICE is the closing price.

 
secret:

Thanks for the reply, I've looked at both the documentation and your example, but still haven't found how to get a parameter similar to OrderClosePrice() in MT4.

There is no direct analogy. The position consists of trades. If you want accurate data exactly for a position - you must first assemble the position back from the trading history.

Therefore, it is better to work with the concept of "deal".


Generally, the implementation depends very much on the answer to the question: "Why?". That is, first describe exactly what you want and why.

 
secret:

How do I get the closing price of an order (trade, position - anything at all)?

Googled the forum, couldn't find it.

https://www.mql5.com/ru/forum/162461

Как определить последнюю цену закрытия ордера (MQL5)?
Как определить последнюю цену закрытия ордера (MQL5)?
  • 2016.12.05
  • www.mql5.com
Подскажите как определить последнюю цену закрытия ордера (MQL5)? В MQL4 было просто OrderClosePrice...
 
Igor Makanu:

alternatively openhttps://www.mql5.com/ru/code/16006

and look at@fxsaber' s implementation

It's unrealistic to rip out the implementation from there, as it has a strong dependency on all other parts of the library.

 

Friends, please advise how to solve a seemingly simple problem. A piece of code:

double stavkariska;

//ставка риска по инструментам

if(StringCompare(_Symbol,"VTBR")==0||StringCompare(_Symbol,"LKOH")==0)

   {double stavkariska=0.3;}

else double stavkariska=1;

  int lot=int (depozit/(d*stoimkontr)*stavkariska); 

Compiler warning:

declaration of 'stavkariska' hides local declaration at line 25 script.mq5 32 12

possible use of uninitialized variable 'stavkariska' script.mq5 33 39

What is the right way to solve this problem, so that it compiles without any warnings?


Компиляция - Разработка программ - MetaTrader 5
Компиляция - Разработка программ - MetaTrader 5
  • www.metatrader5.com
Компиляция — это процесс перевода исходного кода MQL4/MQL5-программы на машинный язык. Ее результатом является создание исполняемого файла программы (*EX4 или *.EX5), который может быть запущен в торговой платформе. Скомпилировать можно любой файл (*.MQ4, *.MQ5 или *.MQH), однако исполняемый файл (*.EX4 или *.EX5) может быть получен только в...
 
TrueSam:

Friends, please advise on how to solve a seemingly simple problem. A piece of code:

Compiler warning:

declaration of 'stavkariska' hides local declaration at line 25 script.mq5 32 12

possible use of uninitialized variable 'stavkariska' script.mq5 33 39

How to solve the problem correctly, so that it compiles without any warnings?


Use a translator:

декларация 'stavkariska' скрывает локальную декларацию в строке 25 скрипт.mq5 32 12

возможно использование неинициализированной переменной 'stavkariska' скрипт.mq5 33 39


That is, declare variables more carefully - avoid declaring the same variables in the same scope.

When declaring a variable , make a habit of initializing it immediately.

   double StavkaRiska=0.0;// ставка риска по инструментам

   if(StringCompare(_Symbol,"VTBR")==0 || StringCompare(_Symbol,"LKOH")==0)
     double StavkaRiska=0.3;
   else StavkaRiska=1;

   int lot=int(depozit/(d*stoimkontr)*StavkaRiska);
 
Vladimir Karputov:

Make use of the translator:


That is, declare variables more carefully - avoid declaring the same variables in the same scope.

When declaring a variable , make a habit of initialising it immediately.

The thing is, if I declare another variable in the If else statement, I get the need to declare it again, otherwise the error "'stavkariska1' - undeclared identifier. A vicious circle for a newbie. Perhaps there are other ways to implement selection?
 
TrueSam:
The thing is that declaring another variable in the If else operator, I get the need to declare it again, otherwise the error "'stavkariska1' - undeclared identifier. A vicious circle for a beginner. Perhaps there are other ways to implement the selection?

The little robot made a mistake in a hurry, too.

   double StavkaRiska=0.0;// ставка риска по инструментам

   if(StringCompare(_Symbol,"VTBR")==0 || StringCompare(_Symbol,"LKOH")==0)
     double  StavkaRiska=0.3;
   else StavkaRiska=1;

   int lot=int(depozit/(d*stoimkontr)*StavkaRiska);

The highlighted one is unnecessary. Without re-declaration it should work as it should.

 
Alexey Viktorov:

The little robot made a mistake in his haste too.

The highlighted one is redundant. Without the re-announcement, it should work as it should.

Thank you for your attention. I'm sorry, I typed directly into my browser using copypaste.

 
Alexey Viktorov:

The little crabber also made a mistake in his haste.

The highlighted one is redundant. Without a re-announcement it should work as it should.

Thank you very much! The grail is working :)