Estimating margin requirements in MQL5 - page 7

 
Vladimir:

You understand that it's not about the code, everyone who knows how to recalculate - that's it. But you have added volatility to the list of features, the impact of which you have actually identified. And if you go further into wood, you will gather more and more firewood. How to take it into account? The case seems quite hopeless...

I don't know what you mean at all.

It is all described in the trading conditions, in the actual trading rules.

The phenomenon is essentially commonplace.

The calculation is different accordingly.

But the issue is solvable

How to take into account - previous post.
 
Renat Akhtyamov:

I do not know what you mean.

It's all described in the trading conditions, in the actual trading rules.

The phenomenon is commonplace in essence.

Accordingly, the calculation is different

But the problem is solvable.

I will try to explain. The algorithm is as follows: we observe several tens of symbols in several tens of brokerage companies. Estimations are made in steps; I will call them for simplicity: the expected profitability of a deal on the margin taken by it. It is different for each pair (symbol, DC). Including not only at the moment of transaction opening. To select those symbols and brokerage companies, where we will open a deal, we need to compare this figure. For this choice we need to estimate the leverage, in what limits it will be in an expected period before closing the transaction. After all, we will have to reserve this amount.

This is the maximum programme. So far, I don't even know if I can take OrderCalcMargin() as a basis for estimating the required margin. Let it just be the margin for the current moment. You said that as the volatility changes, the leverage changes. So, we will have to collect statistics - in what ranges it changes in each of VC for each symbol. Or it will be possible to find acceptable ranges of these fluctuations. The worst thing would be if it turns out that leverage varies in unpredictable ways...

My question "does OrderCheck() or OrderCalcMargin() take into account the features of leverage specified in the specification" is a starting point in this approach.
 
Vladimir:

Let me try to explain. The algorithm is as follows: several dozens of symbols in several dozens of DCs are monitored. Estimations are made at a certain step, I will call them for simplicity the expected profitability of a deal on the margin taken by it. It is different for each pair (symbol, DC). Including not only at the moment of transaction opening. To select those symbols and brokerage companies, where we will open a deal, we need to compare this figure. For this choice we need to estimate the leverage, in what limits it will be in an expected period before closing the transaction. After all we will have to reserve this amount.

This is the maximum program. So far, I don't even know if I can take OrderCalcMargin() as a basis for estimating the required margin. Let it only be the margin for the current moment. You said that as the volatility changes, the leverage changes. So, we will have to collect statistics - in what ranges it changes in each of VC for each symbol. Or it will be possible to find acceptable ranges of these fluctuations. The worst thing would be if it turns out that leverage varies in unpredictable ways...

I am writing for the last time:

Read the trading conditions of a particular brokerage company and you won't need any statistics.

 
Renat Akhtyamov:

Last time I write:

You may change the leverage at your own discretion and you may get only 20 for a few hours.

//My question "does OrderCheck() or OrderCalcMargin() take into account the features of leverage specified in the specification" is a starting point in this approach.

Current

You never see when a leverage reduction email arrives, and there can be many factors, it's not just for elections in the countries. They may change the leverage on the "fly" at their discretion, you may set it from 100 to 20, and for just a few hours.

 
Vitaly Muzichenko:

Have you ever seen a letter in the mail informing you of a leverage reduction, and there can be many factors, it is not just for elections in countries. You may also not get a letter - they change leverage on the fly as they see fit, they may go from 100 to 20, and for just a few hours.

Vitaly, I have already written the tracking algorithm in the previous version, I used it myself, because the leverage was 1:2000

In trading conditions they specifically specify the limits of leverage change, the conditions, time, under what conditions they do not change it at all, etc.

You may change it on the fly too, that is why I was tracking it.

 
Vladimir:.
My question "does OrderCheck() or OrderCalcMargin() take into account the features of leverage specified in the specification" is a starting point in this approach.

Sorry, in your own words:

"it's not about the code, it's about everyone who can recalculate."

It is likely that you have assigned yourself to all as well.

Do the math and everything will be
 

Or maybe the terminal doesn't have the right information?
I checked if the terminal sends a request to the server each time, or it checks if I have enough funds. I've found only one brokerage company in MT5 that logs its requests in two lines with two points if there is insufficient amount of money. May be because out of MT5 this terminal is the only one connected to a real account, the other MT5 ones I have demo. Log for 6 manual trade opening attempts:

2018.07.03 04:59:35.231 Trades '3038119': market buy 1.26 EURUSD.m
2018.07.03 04:59:35.331 Trades '3038119': market buy 1.26 EURUSD.m [No money]
2018.07.03 05:00:51.667 Trades '3038119': market buy 1.26 EURUSD.m
2018.07.03 05:00:51.747 Trades '3038119': failed market buy 1.26 EURUSD.m [No money]
2018.07.03 05:00:55.001 Trades '3038119': market buy 1.26 EURUSD.m
2018.07.03 05:00:55.091 Trades '3038119': market buy 1.26 EURUSD.m [No money]
2018.07.03 05:01:00.008 Trades '3038119': market sell 1.26 EURUSD.m
2018.07.03 05:01:00.091 Trades '3038119': failed market sell 1.26 EURUSD.m [No money]
2018.07.03 05:01:02.911 Trades '3038119': market sell 1.26 EURUSD.m
2018.07.03 05:01:03.007 Trades '3038119': failed market sell 1.26 EURUSD.m [No money]
2018.07.03 05:01:05.952 Trades '3038119': market sell 1.26 EURUSD.m
2018.07.03 05:01:06.035 Trades '3038119': failed market sell 1.26 EURUSD.m [No money]

Time intervals between the request line and the No money answer (in milliseconds): 100 80 90 83 96 87.
The ping to server shown in terminal is 73.56 ms. Why terminal waits for 80 ms or more before deciding that it's not enough money? It looks like it sends all requests to server without checking for sufficiency. Why is that? I see one natural reason - the terminal doesn't have necessary information for such checking.
And I was always sure that "Not enough money..." message is given by the terminal itself, that it's not just sending server's decisions.

Dennis Kirichenko seems to be the most precise answer to my question https://www.mql5.com/ru/forum/261955/page4#comment_7949343

Renat Akhtyamov, what method did you suggest in https://www.mql5.com/ru/forum/261955/page2#comment_7945930"Request margin information from the server"? Even if it takes a second, okay, but what kind of request to the server were you referring to? Is it just an attempt to open an anticipated trade, for which a preliminary margin estimate is made?

 
Vladimir:

Or maybe you don't have the right information in your terminal?
I started to check if the terminal sends the request to the server every time, or if it is checking the sufficiency of the funds. I've found only one brokerage company in MT5 that logs requests in two lines showing two points in case of insufficient funds. May be because out of MT5 this terminal is the only one connected to a real account, the other MT5 ones I have demo. Log for 6 manual trade opening attempts:

2018.07.03 04:59:35.231 Trades '3038119': market buy 1.26 EURUSD.m
2018.07.03 04:59:35.331 Trades '3038119': market buy 1.26 EURUSD.m [No money]
2018.07.03 05:00:51.667 Trades '3038119': market buy 1.26 EURUSD.m
2018.07.03 05:00:51.747 Trades '3038119': failed market buy 1.26 EURUSD.m [No money]
2018.07.03 05:00:55.001 Trades '3038119': market buy 1.26 EURUSD.m
2018.07.03 05:00:55.091 Trades '3038119': market buy 1.26 EURUSD.m [No money]
2018.07.03 05:01:00.008 Trades '3038119': market sell 1.26 EURUSD.m
2018.07.03 05:01:00.091 Trades '3038119': failed market sell 1.26 EURUSD.m [No money]
2018.07.03 05:01:02.911 Trades '3038119': market sell 1.26 EURUSD.m
2018.07.03 05:01:03.007 Trades '3038119': failed market sell 1.26 EURUSD.m [No money]
2018.07.03 05:01:05.952 Trades '3038119': market sell 1.26 EURUSD.m
2018.07.03 05:01:06.035 Trades '3038119': failed market sell 1.26 EURUSD.m [No money]

Time intervals between the request line and the No money answer (in milliseconds): 100 80 90 83 96 87.
The ping to server shown in terminal is 73.56 ms. Why terminal waits for 80 ms or more before deciding that it's not enough money? It looks like it sends all requests to server without checking for sufficiency. Why is that? I see one natural reason - the terminal doesn't have necessary information for such checking.
And I was always sure that "Not enough money..." message is given by the terminal itself, that it's not just sending server's decisions.

Dennis Kirichenko seems to have answered my question most accurately https://www.mql5.com/ru/forum/261955/page4#comment_7949343

Renat Akhtyamov, what method did you suggest in https://www.mql5.com/ru/forum/261955/page2#comment_7945930"Request margin information from the server"? Even if it takes a second, okay, but what kind of request to the server were you referring to? Is it just an attempt to open an anticipated trade for which a preliminary margin estimate is made?

I do understand you, of course.

In the beginning I did not understand simple things right away

Once again, here's the margin for 1 lot to sell

OrderCalcMargin(ORDER_TYPE_SELL,_Symbol,1,BID,Mgn)

But for buying

OrderCalcMargin(ORDER_TYPE_BUY,_Symbol,1,ASK,Mgn)

The leverage is the ratio to it, not more than

k=100/leverage

like this

And your log tells you that you have no money and cannot open an order for free.

You can open an order with demo money. However, as far as I understand, you don't have any demo money either.

The balance is zero, isn't it?
 
Guys, give me the address of a brokerage house where the leverage for a symbol or the leverage of an account changes frequently. Or at least for some symbols separate leverage conditions.
 

ForexClub.

Checked their margin relative to this lot using ::OrderCalcMargin(). Real account, leverage 1:500.

EURUSDLotPriceVolume value, $Margin, $Theoretical leverage
100 0001.001.16716116 716233.43500

11.001.167161 283 8762 567.75500

51.001.167165 952 51611 905.03500

101.00
1.1671611 788 31623 576.63500


It turns out that the leverage does not change when the trading volume increases, which does not correspond to the Specification.

Reason: