Oh, here is the MOST delicious in the "Reading Room" appeared, let's read what and how ...
Especially from such an author. :)
I would also like to see the swap calculation function. There are 5 kinds of swaps, and each has its own nuances.
Sometimes you don't get to the right place by the scientific method.
I found three variants by selection, but there is still SYMBOL_SWAP_MODE_BY_INTEREST. I can't check it because I can't find a broker with this calculation method.
Please - if there is a possibility to post in CodeBase the function of swap calculation for the specified currency and lot - we will be grateful.
I would also like to see the swap calculation function. There are 5 kinds of swaps, and each has its own nuances.
Sometimes you don't get to the right place by the scientific method.
I found three variants by selection, but there is still SYMBOL_SWAP_MODE_BY_INTEREST. I can't check it because I can't find a broker with this calculation method.
Please - if there is a possibility to post in CodeBase the function of swap calculation for the specified currency and lot - we will be grateful.
Если даже торговля на данном счете разрешена, то это еще не означает, что эксперт имеет право торговать. Чтобы проверить, разрешено ли торговать эксперту, пишем:
What are these cases, trading is allowed, but the Expert Advisor is not allowed to trade?
Does it mean the broker's prohibition or terminal settings?
By analogy with 4 : - " ...if the expert is allowed to trade and the flow for trade operations is free..."
i.e. IsTradeAllowed = IsExpertEnabled + IsTradeContextBusy ??? ?
Interesting and necessary article! I tried to check the formulas in this article and this is what I got. Let's take EURGBP as an example. The account currency is in dollars. The nearest currency pair is EURUSD, i.e. mode=true. So far so good? We use the formulas from the article to determine the required margin:
if(direction==POSITION_TYPE_BUY)
{
//--- reverse quote
if(mode)
{
//--- count at the purchase price for the reverse quote
calc_price=tick.ask;
answer=lot*lot_size*calc_price;
}
...
if(direction==POSITION_TYPE_SELL)
{
//--- reverse quote
if(mode)
{
//--- count by selling price for the reverse quote
calc_price=tick.bid;
answer=lot*lot_size*calc_price;
}
That is, when buying, according to the article, the required margin should be:
BUY: margin = lot*lot_size*tick_ask/leverage
and when selling:
SELL: margin = lot*lot_size*tick_bid/leverage
We code these formulas in a simple EA and try to sell and buy EURUSD with low funds in advance so that the metatrader will tell us what margin is needed. At the same time we output our calculated margin. We get these messages from the tester:
2010.07.06 16:34:01 Core 1 no enough money [instant sell 0.10 EURGBP at 0.82227 sl: 0.83296 tp: 0.79796]
2010.07.06 16:34:01 Core 1 PrevBalance: 10.00, PrevEquity 10.00, PrevMargin: 0.00, NewMargin: 122.91, NewFreeMargin: -112.91 - margin calculated by the tester
2010.07.06 16:34:01 Core 1 Error: not enough money. Free margin = 10, required margin = 122.899 - margin calculated by us.
2010.07.06 16:34:01 Core 1 no enough money [instant buy 0.10 EURGBP at 0.81247 sl: 0.80191 tp: 0.82988]
2010.07.06 16:34:01 Core 1 PrevBalance: 10.00, PrevEquity 10.00, PrevMargin: 0.00, NewMargin: 122.72, NewFreeMargin: -112.72 - margin calculated by the tester
2010.07.06 16:34:01 Core 1 Error: not enough money. Free margin = 10, required margin = 122.737 - margin calculated by us.
There's a difference. Now we change the formulae for calculating the required margin to
BUY: margin = lot*lot_size*tick_bid/leverage
SELL: margin = lot*lot_size*tick_ask/leverage
which contradicts the article. We get such messages from the tester:
2010.07.06 16:39:49 Core 1 no enough money [instant sell 0.10 EURGBP at 0.82227 sl: 0.83296 tp: 0.79796]
2010.07.06 16:39:49 Core 1 PrevBalance: 10.00, PrevEquity 10.00, PrevMargin: 0.00, NewMargin: 122.91, NewFreeMargin: -112.91 - margin calculated by the tester
2010.07.06 16:39:49 Core 1 Error: not enough money. Free margin = 10, required margin = 122.911 - margin calculated by us
2010.07.06 16:39:49 Core 1 no enough money [instant buy 0.10 EURGBP at 0.81247 sl: 0.80191 tp: 0.82988]
2010.07.06 16:39:49 Core 1 PrevBalance: 10.00, PrevEquity 10.00, PrevMargin: 0.00, NewMargin: 122.72, NewFreeMargin: -112.72 - margin calculated by the tester
2010.07.06 16:39:49 Core 1 Error: not enough money. Free margin = 10, required margin = 122.722 - margin calculated by us
.
Here the margin calculated by the Expert Advisor using the "wrong" method is exactly the same as the margin calculated by the tester. It turns out that either in the tester or in the article bid and ask are rearranged when calculating crosses like EURGBP. Who is right: the article or the tester?
The article is good and useful for me.
Both for understanding and time saving. Thank you
I just don't understand what we get with this function.
If the amount of collateral required, shouldn't the contract value be divided by the leverage?

- www.mql5.com
The article is good and useful for me.
Both for understanding and time saving. Thank you
I just don't understand what we get with this function.
If the size of the required collateral, then shouldn't the contract value be divided by the leverage?
If the amount of margin required, shouldn't the contract value be divided by the leverage?

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
New article Functions for Money Management in an Expert Advisor is published:
The development of trading strategies primarily focuses on searching for patterns for entering and exiting the market, as well as maintaining positions. If we are able to formalize some patterns into rules for automated trading, then the trader faces the question of calculating the volume of positions, the size of the margins, as well as maintaining a safe level of mortgage funds for assuring open positions in an automated mode. In this article we will use the MQL5 language to construct simple examples of conducting these calculations.
Author: MetaQuotes