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

 
Seric29:
Guys who can help with this question. I want to declare a global variable of undefined type or arbitrary type. Then this variable will be used in functions where templates are applied. In other words, I call function and take array of any type, then calculations will be done and result will be returned by function and will be assigned to this variable. I want to store the result of calculation of these parameters in a variable, so I don't have to call the function for the second time. How can I find universal solution with fewest checks, can I convert variable type, or declare it as variable with macro, what can I do?

If I understand correctly, then

https://www.mql5.com/ru/docs/basis/oop/templates

Документация по MQL5: Основы языка / Объектно-ориентированное программирование / Шаблоны функций
Документация по MQL5: Основы языка / Объектно-ориентированное программирование / Шаблоны функций
  • www.mql5.com
Перегруженные функции обычно используются для выполнения похожих операций над различными типами данных. Простой пример такой функции в MQL5 - ArraySize(), которая возвращает размер массива любого типа. На самом деле эта системная функция является перегруженной, и вся реализация такой перегрузки спрятана от разработчика программ на MQL5: То есть...
 
leonerd:

I don't really understand this comment. You can open a locking position (opposite to the open position) with a free margin lower than the margin for the newly opened order (not in the lock). So where is 100% there?

Example:

USDJPY currency, leverage 1:100. Lot 0.1, the margin is 100

According to the specification the hedged margin is 50000, which means 50%

In order to open a locking position, 100 more funds must be available in the account. Otherwise, there will be an error ... do not remember the number, in general, not enough funds.

And only after opening a position the actual margin will be corrected according to the values given in the specification.

But, if there is only 50 available funds in the account, then you can open twice for 0.05

 
Alekseu Fedotov:

If I have understood correctly, then

https://www.mql5.com/ru/docs/basis/oop/templates

I already know about the use of template technology. This method allows you to return the type of a variable, but converting the type of one variable to another will not. It may not be possible.

 
Alexey Viktorov:

Example:

USDJPY currency, leverage 1:100. Lot 0.1, the margin is 100

According to the specification, the hedged margin is 50,000, which means 50%.

To open a locking position, 100 more funds must be available in the account. Otherwise, there will be an error ... do not remember the number, in general, not enough funds.

And only after opening a position, the actual margin will be corrected according to the values in the specification.

But, if there is only 50 free funds in the account, then you can open twice for 0.05

Ok, maybe that's the way it is. We should check it out.

We should check on the price of an order. Then what about the MQL5 functionhttps://www.mql5.com/ru/docs/trading/ordercalcmargin?

The order open price is in the parameter. How does it work for crosses? How does it work for cross rates? Does MT5 know how to predict prices?

Документация по MQL5: Торговые функции / OrderCalcMargin
Документация по MQL5: Торговые функции / OrderCalcMargin
  • www.mql5.com
Вычисляет размер маржи, необходимой для указанного типа ордера на текущем счете и при текущем рыночном окружении без учета текущих отложенных ордеров и открытых позиций. Позволяет оценить размер маржи для планируемой торговой операции. Значение возвращается в валюте счета. [out]  Переменная, в которую...
 
i downloaded freeNumFractals indicator for mt5, but fractals do not update on the chart.

FreeNumFractals

 
Pavel5554:
i have already reinstalled mt5 and this indicator,but it has no effect.

FreeNumFractals

What is that indicator? I have no effect. Where is the link to it?

 
leonerd:

All right, maybe that's it. We'll have to check it out.

On the price of the order. What about the MQL5 functionhttps://www.mql5.com/ru/docs/trading/ordercalcmargin?

The order open price is in the parameter. How does it work for crosses? How does it work for cross rates? Can MT5 predict prices?

Well, you have to read everything carefully. Quote from the documentation:

The calculation is performed as if there are no pending orders and open positions in the current account. The value of margin depends on many factors and may change when the market environment changes.

The calculation is performed... i.e. the obtained value will be without taking into account the open position, and only then it will be corrected according to the specification if the opposite position is opened. This is what I was talking about.

Margin value... for pending orders is calculated "from the background" and may not correspond to the real value.

 
Sergey Voytsekhovsky:

Great advice and a great science for the future!!! Went even a little further than that. Below is the result.

So it was:

So it became, the effectiveness of the approach is obvious!!! Thank you.

Thanks to Sergei and Alexey for the coloured stochastic indicator. You are very good. Respect!

 
How can I make my indicator appear in the main window instead of the main chart (my indicator is built in the form of bars).

So that my indicator data will replace the chart data.

And that all standard indicators of the client terminal can be thrown on this new chart. And for these indicators to work on my indicator's data, not on price bars.
 

There is a question like this. So, there is a loop

     for(...........)              
     {if(.........){ что-то делаем}else
      if(.........){ break}else{ break;}} 

The 1stbreak is located not in first parentheses of the loop but in parentheses nested inside them. The 2ndbreak is even deeper nested in inner parentheses. As I understood in this casebreak simply doesn't work, to tell the truth I didn't understand if it worked or not but the program hung up and made unnecessary iterations. In order to exit a loop with a lot of conditions I added an exit flag to the loop. Maybe it seemed to me that it does not work, who thinks on this issue?

Reason: