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

 
leonerd:

But you don't take into account differently directed orders and the Margin hedge factor here.

The "order direction" is accounted for byAccountFreeMarginCheck https://docs.mql4.com/ru/account/accountfreemargincheck

For your purpose, my function needs to pass the total lot and order type OP_BUY or OP_SELL as parameters
If it is a counter-close, the margin is released there,

For a lock there was something similar, but I don't think all brokers use the same way of calculating margin for a lock, I don't remember, the lock theme seems to have subsided in runet, it's not in demand

for the coefficient it seems to be about the leverage, there were discussion threads, search through the forum "margin calculation" should be able to find it, I have not dealt with this topic for a long time, it is not in high demand

here is an article on the subject, it seems to have a margin calculationhttps://www.mql5.com/ru/articles/2555

AccountFreeMarginCheck - Информация о счете - Справочник MQL4
AccountFreeMarginCheck - Информация о счете - Справочник MQL4
  • docs.mql4.com
Размер свободных средств, которые останутся после открытия указанного ордера по текущей цене на текущем счете. Если свободных средств не хватает, то будет сгенерирована ошибка 134 (ERR_NOT_ENOUGH_MONEY).
 
Igor Makanu:

The "direction of the order" is accounted for byAccountFreeMarginCheck https://docs.mql4.com/ru/account/accountfreemargincheck

For your purpose, my function needs to pass the total lot and order type OP_BUY or OP_SELL as parameters
If we are talking about a counter-close, the margin is released there,

I don't remember, the topic of locks seems to have subsided in runet, it is not in demand.

for the coefficient it seems to be about the leverage, there were discussion threads, search through the forum "margin calculation" should be able to find it, I have not dealt with this topic for a long time, it is not in high demand

here is an article on the subject, it seems there is a margin calculationhttps://www.mql5.com/ru/articles/2555

AccountFreeMarginCheck assumes this is the current price. My price is not the current price. It's different.

 
SYMBOL_MARGIN_HEDGED no analogue for MT4?
 
leonerd:
SYMBOL_MARGIN_HEDGED no analogue for MT4?
MarketInfo(_Symbol, MODE_MARGINHEDGED);
 
Alexey Viktorov:

Thank you. What about this? Is it possible to calculate what I need? Margin for the orders to be opened in advance, knowing their price and volume.

 

Please advise why the program does not show any changes and does not show oil and raw material stocks

 
leonerd:

Thank you. What about this? Is it possible to calculate what I need? The margin for the orders to be opened in advance, knowing their price and volume.

I think if you can predict the price of the assets involved in the value of margin, the orders that are to be opened, you will not be costly. You don't need to trade forex, you can just tell the whole society for money what the price will be in xx minutes.

Probably it is better to calculate how much money you will need to open an order in the current moment.

You said it... But I'm not going to change it on principle. I'm just drunk. I'm not going to change it.

Anyway, for the reason already said, I can't understand the sabb itself. Maybe I'll figure it out tomorrow. But at any rate, the margin for pending orders is IMPOSSIBLE.

One more thing: at the moment of opening an order, margin is fully calculated and only after it has been opened, will it be corrected according to MODE_MARGINHEDGED.

Accordingly, if you need to calculate a deal to lock up a losing position, you should count as an opening with a 100% margin and only after that open an additional order with the released funds.

If I got it wrong... sorry...

 
Alexey Viktorov:

The most important thing is the RIGHT one.

Yes thank you it's not convenient to put those zeros in the print.

 
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 with templates. 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 also 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 a universal solution with the least amount of checks, can I convert the type of variable, or declare a variable through a macro, what can I do?
 
Alexey Viktorov:


One more remark: At the moment of order opening, margin is calculated in full and only after opening margin is corrected in accordance with MODE_MARGINHEDGED.

Accordingly, if you need to calculate the trade size to lock up a losing position, you should consider it as an opening with a 100% margin and only after that open an additional order with the released funds.

If I got it wrong... sorry...

I do not really understand this comment. You can open a locking position (opposite to the one opened) if your margin is lower than the margin for the newly opened order (not in the position itself). So where is 100% there?

Reason: