Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1188

 
odyn:

Please explain.

TheOnTradeTransaction function.

Does it have to be in the Expert Advisor?

If not, in what cases must it be included in the code? And why?

Only OnInit() and OnTick() are mandatory, the rest of them are optional. The reason for that is clearly described in the documentation of the language.

The forum engine has put a link to the function name, click on it and read it.
 
Alexey Viktorov:

Only OnInit() and OnTick() are mandatory, the rest are at the discretion of the codewriter. Why is it clearly described in the documentation of the language.

The forum engine has put a link to the name of the function, so we can read it.

I only ask a question when I can't understand the explanation in documentation, articles and forum.

If it was "clearly described", I wouldn't ask.

The function is designed to handle the results of a trade request. This function does not return anything.

The function is not necessary to it.

So, the function is necessary when the Expert Advisor receives the results of processing requests from the server? But doesn't any Expert Advisor send them? So, the function must always be inserted into the Expert Advisor?

 

Hello! Question for experienced users!

MQL5 has OBJ_CHART.

Please advise how to use indicators, in particular MA, in OBJ_CHART, and whether it is possible?

 
odyn:

I only ask a question when I can't understand the explanation in the documentation, in the articles and in the forum.

If it was "clearly described", I wouldn't ask.

The function is designed to process the results of a trade request. This function does not return anything.

The function is not necessary to it.

So, the function is necessary when the Expert Advisor receives the results of processing requests from the server? But doesn't any Expert Advisor send them? So, the function must always be inserted into the Expert Advisor?

Some programmers are stuck with those examples that they mastered back in mql4 and cannot get away from them. The OnTradeTransaction() is like a dog's tail for such programmers. But if you want, for example, to easily detect an event when a pending order is activated, it cannot be done easier than in OnTradeTransaction(). If you need to take some decision and perform some actions at the moment of position closing, you will find it as easy as OnTradeTransaction(). And if it is necessary to perform some actions when closing by TP, and other actions when closing by SL, it cannot be done easier than in OnTradeTransaction().

But¡¡¡ now, those of whom I have mentioned will come and start speculating about how many milliseconds there is here and there... All in all, it's up to the amateur. If you are interested, run it and see what you can get in OnTradeTransaction() and think how you can use it for yourself.

 

Tell me, if I need to open two trades at the same time, but check if there is an error when opening one of them, how do I catch the error?

Is there a function that returns the ability to open a trade on an asset?

 
Alexey Viktorov:


Thanks for the reply!

 

I can't open the file in the tester. I get error 5004.

int               m_file_handle;
short             m_delimiter;

m_delimiter='\t';
m_file_handle=FileOpen(m_filename,FILE_READ|FILE_CSV,m_delimiter);
if(m_file_handle==INVALID_HANDLE)
  {
   Print(__FUNCTION__+": file open failed. Error: ",GetLastError());
   return false;
  }

It's a normal csv file with tabulation as separator. I put it in MQL5\Files folder of the agent. After trying to open it, the file disappears.

 
leonerd:

I can't open the file in the tester. I get error 5004.

It's a normal csv file with tabulation as separator. I put it in MQL5\Files folder of the agent. The file disappears after trying to open it.

ok, without #property tester_file apparently doesn't work.

 
Roman Sharanov:

Tell me, if I need to open two trades at the same time, but check if there is an error when opening one of them, how do I catch the error?

Is there a function that returns the possibility to open a trade on an asset?

Use OnTradeTransaction().

 

Please suggest an analog of MQL4 function MarketInfo(asymbol, MODE_MARGIN_REQUIRED) in MQL5.

I need to getthe amount of free funds needed to open 1 lot to buy.

I tried different variants of SymbolInfoDouble(symbol, ...) function in MQL5, I can't find the right variant, it returns 0 everywhere.

Документация по MQL5: Константы, перечисления и структуры / Состояние окружения / Информация о счете
Документация по MQL5: Константы, перечисления и структуры / Состояние окружения / Информация о счете
  • www.mql5.com
, то позиции по каждому символу разрешается закрывать только в том порядке, в котором они были открыты — сначала самую старую, затем более новую и т.д. При попытке закрыть позиции в ином порядке будет получена ошибка. Уровень залоговых средств, при достижении которого происходит принудительное закрытие самой убыточной позиции (Stop Out...