void OnStart()
Here is a simple script.
{
double calc_margin; // Cost of 1 lot BUY
double ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
OrderCalcMargin(ORDER_TYPE_BUY, _Symbol, 1.0, ask, calc_margin);
Print("Order value of 1 lot=", calc_margin);
}
On currencies calculates correctly. For example, by Eurodoll = 1171.02.
And on indexes-wrong. In particular, on CAC40 (Alpari) issues 640.73. But if you open an order, the margin is 1941.97.
Please tell me: what am I doing wrong?
user_mt5
I need to think about all this, experiment.
In General, it is difficult to perceive. For example, ” SYMBOL_TRADE_LIQUIDITY_RATE”
Liquidity ratio – the share of the value of an asset that can be used as collateral.
There are a lot of questions: what is this coefficient, why, for what and how it is necessary to use it, where does this share come from, and why in principle it is different. Etc.
I experimented with the shoulder in a well-known firm A. the value of the lot on currencies changes in proportion to the shoulder (well, at least this). And on the indices, it grows proportionally to 1: 50, with a further increase in the leverage, it does not change. And at the same time, the broker can arbitrarily change the leverage. Well. And where to subtract these exotic formulas? What kind of rackets are there?.
Your train of thought is clear to me. But I don’t quite agree. I still think that there are no obstacles to making a few simple functions: the cost of an order of 1 lot (so that the programmer does not calculate it based on his, of course, erroneous ideas, and the platform responds to the function request), the cost of 1 point, the maximum allowable leverage for the symbol, etc.With this approach, the customer’s opinion is not required, this should be the basic norm of the platform. If a particular customer uses exotic methods of calculation, then the developer should release an application specifically for this customer to its server part (!) of the platform, in which the customer will be able to change their coefficients (3.03 and other nonsense) as he pleases. But for the trader, the user-programmer, the contact data set should be uniform, simple and understandable for all brokers for all symbols.
It should have been..
At least they would already give contextual links to examples. But no, I have to guess. A very mysterious language, this MQL..
marketeer
What do the SymbolInfoInteger(_Symbol, SYMBOL_TRADE_CALC_MODE) and SymbolInfoMarginRate functions return for your case? And SymbolInfoDouble(_Symbol, SYMBOL_TRADE_LIQUIDITY_RATE)?
vlad143
In the process of trading, most DCS change their leverage, at least for the weekend,or even for the time of news. Also, the leverage may be different for cases when the client is Polish or non-Polish Manually, unfortunately, in Your case, you will need to organize the calculation in the terminal according to the rules of Your DC, and not just take into account the coefficients. I do not know how to “make a simple normal set of functions for a programmer that characterize the broker’s trading conditions” in MQL languages. This will be an analogue of trigger procedures in the DBMS, involving such funds in the turnover, edit (lead) which should DC, the task is not easy and at the technological level, and what will happen at the organizational level? DC, unlike traders, pay for the platform, that is, ultimately, they are the customer of the work performed by MQ. There are very few customers in the world who will readily take on a new amount of work to support margin calculation procedures in the terminal. Yes, and responsible support… Perhaps this is the reason for the lack of adequate margin assessment tools in the platform.
user_mt5
Vladimir, thank you very much.
Turns out it’s even worse than I thought.
Now it is clear that there is some stupid coef = 3.03.Multiply 640 by 3.03 my brain is enough.
But tell me, please, is it possible to get this 3.03 programmatically? Or do these coefficients for all similar symbols need to be entered into the program manually?
vlad143
1941.97/640.73 = 3.03087. We look at the specification of contracts for CAC40 there: “Collateral, % 3.03”. Matched if you have a nominal leverage of 1: 100.
It’s not about indices/currencies, in this DC in General, the calculation of collateral is very complicated, see “How to calculate collateral with floating leverage depending on the nominal value of positions?” and “Margin requirements for ASX 200, CAC 40, HSI 50, NQ 100, STOXX 50, NG”.