Errors, bugs, questions - page 4

 
Interesting:

MarketInfo(Symbol(),MODE_MARGININIT) = SymbolInfoDouble(_Symbol,SYMBOL_MARGIN_INITIAL)

What then corresponds to MODE_MARGINREQUIRED? Or otherwise, how do I know how much free money I need to open 1 lot to buy?

In Moving Average.mq5 Expert Advisor from mql5 creators, lots are calculated like this

input double MaximumRisk        = 0.02;    // Maximum Risk in percentage
input double DecreaseFactor     = 3;       // Descrease factor
input int    MovingPeriod       = 12;      // Moving Average period
input int    MovingShift        = 6;       // Moving Average shift
//---
int   ExtHandle=0;
//+------------------------------------------------------------------+
//| Calculate optimal lot size                                       |
//+------------------------------------------------------------------+
double TradeSizeOptimized(void)
  {
//--- select lot size
   double lot=NormalizeDouble(AccountInfoDouble(ACCOUNT_FREEMARGIN)*MaximumRisk/1000.0,2);

Why is MaximumRisk so small (0.02%) and divided by 1000 when calculating lots? What does this 1000 represent? Maybe 1000 = available funds needed to buy 1 lot multiplied by 100% (to convert 0.02% into 0.0002 fraction)? That is, the available funds for the purchase of 1 lot is $10 ($10x100%=1000). Is it in the right direction I think?

And one more question. Is there a limit on the maximum number of open orders?

 
gpwr:

What then corresponds to MODE_MARGINREQUIRED? Or otherwise how do I know the amount of available funds needed to open 1 lot to buy?

And one more question. Is there a limit on the maximum number of open orders?


I asked myself this question.


Here is the developers' answer:

Rashid Umarov:

See

SYMBOL_TRADE_CONTRACT_SIZE

Trade contract size

double

и

SYMBOL_CURRENCY_MARGIN

Currency in which the margin is calculated

string


As I understand it, you will have to calculate it yourself

 

gpwr:

In Moving Average.mq5 Expert Advisor from mql5 creators, lots are calculated like this

Why is MaximumRisk so small (0.02%) and divided by 1000 when calculating lots? What does this 1000 represent? Maybe 1000 = available funds needed to buy 1 lot multiplied by 100% (to convert 0.02% into 0.0002 fraction)? That is, the available funds for the purchase of 1 lot is $10 ($10x100%=1000). Is it in the right direction I think?

And one more question. Is there a limit on the maximum number of open orders?


AccountInfoDouble(ACCOUNT_FREEMARGIN)*MaximumRisk

This line calculates the risk as 2% of available funds, if I understood correctly. Why do they divide this amount by 1000?


But if I understand correctly, then with a deposit (free funds) of $20,000, the Expert Advisor recommends to open no more than 2% of this amount ($400).

Dividing this amount by 1,000 we will logically get 0.4 lot...

 

gpwr:

Is there a limit to the maximum number of open orders?

I was wondering the same thing. There is a suggestion that the developers are still thinking about (for them, by the way - application 15802).
 
Interesting:

This line calculates the risk as 2% of the amount of available funds, if I understand correctly. Why this amount is divided by 1,000 is up to the developers.

But if I understand correctly, then with a deposit (free funds) of $ 20,000, the Expert Advisor recommends to open no more than 2% of this amount ($ 400).

Dividing this amount by 1,000 we will logically get 0.4 lot...

Now I got it. There is a mistake in Moving Average.mq5. Instead of

input double MaximumRisk        = 0.02;    // Maximum Risk in percentage

It should be

input double MaximumRisk        = 0.02;    // Maximum Risk as a fraction  of a free margin

Then division by 1000 in calculation of lots is clear: $100,000(lot size)/100(leverage) = 1000. However, the mql5 developers must not show such an example of an Expert Advisor. It should be changed

double lot=NormalizeDouble(AccountInfoDouble(ACCOUNT_FREEMARGIN)*MaximumRisk/1000.0,2);

To

double LotSize    =SymbolInfoDouble(_Symbol,SYMBOL_TRADE_CONTRACT_SIZE);
int    Leverage   =AccountInfoInteger(ACCOUNT_LEVERAGE);
double FreeMargin =AccountInfoDouble(ACCOUNT_FREEMARGIN);  
double LotRqdMgn  =LotSize/Leverage;
double lot        =NormalizeDouble(FreeMargin*MaximumRisk/LotRqdMgn,2);

Or better yet

double Step       =SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_STEP);
double LotSize    =SymbolInfoDouble(_Symbol,SYMBOL_TRADE_CONTRACT_SIZE);
int    Leverage   =AccountInfoInteger(ACCOUNT_LEVERAGE);
double FreeMargin =AccountInfoDouble(ACCOUNT_FREEMARGIN);  
double LotRqdMgn  =LotSize/Leverage;
double lot        =NormalizeDouble(MathFloor(FreeMargin*MaximumRisk/LotRqdMgn/Step)*Step,2);

It's a pity that MODE_MARGINREQUIRED has been lost, though. Maybe the developers will restore this parameter to reduce the number of calculations.

 
Interesting:
stringo:
Short names have always only ever been used for display in the indicator subwindow
So it's not displayed there, either it's an error or I don't understand something...
Found the error and fixed it, 16051 can be closed.
 

I don't know if I'm putting my bug reports in the right place. If not, please correct me.

When testing my EA, I purposely created such a situation to see if the tester determines the margin correctly. So, the deposit of $100. We trade EURUSD. Minimum lot size is 0.1. The following code for calculation of lots is in the Expert Advisor

double volMin     =SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN);
double LotSize    =SymbolInfoDouble(_Symbol,SYMBOL_TRADE_CONTRACT_SIZE);
long   Leverage   =AccountInfoInteger(ACCOUNT_LEVERAGE);
double FreeMargin =AccountInfoDouble(ACCOUNT_FREEMARGIN);  
double LotRqdMgn  =LotSize/Leverage;
double vol=NormalizeDouble(MathFloor(FreeMargin*MaxRisk/LotRqdMgn/Step)*Step,2);
if(vol<volMin) vol=volMin;
if(vol*LotRqdMgn>FreeMargin) vol=0.0;
Print(LotRqdMgn," ",FreeMargin);
return(vol);

The tester generates these errors

2010.06.08 22:28:57 Core 1 no enough money [instant buy 0.10 EURUSD at 1.19242]
2010.06.08 22:28:57 Core 1 PrevBalance: 100.00, PrevEquity 100.00, PrevMargin: 0.00, NewMargin: 119.24, NewFreeMargin: -19.24
2010.06.08 22:28:57 Core 1 1000 100
2010.06.08 22:28:57 Core 1 no enough money [instant buy 0.10 EURUSD at 1.19180]
2010.06.08 22:28:57 Core 1 PrevBalance: 100.00, PrevEquity 100.00, PrevMargin: 0.00, NewMargin: 119.18, NewFreeMargin: -19.18
2010.06.08 22:28:57 Core 1 1000 100
2010.06.08 22:28:57 Core 1 no enough money [instant buy 0.10 EURUSD at 1.19362]
2010.06.08 22:28:57 Core 1 PrevBalance: 100.00, PrevEquity 100.00, PrevMargin: 0.00, NewMargin: 119.36, NewFreeMargin: -19.36
2010.06.08 22:28:57 Core 1 1000 100

Judging by these messages, free margin needed to buy 1 lot, LotRqdMgn, is equal to 1000, which seems to be correct. FreeMargin=100. Multiply 0.1 lot by 1000 and you get 100. It means we have enough funds to open the 1st lot. But the tester reports that we do not have enough funds. Where is error?

 
gpwr:

Based on these messages, the free margin required to buy 1 lot, LotRqdMgn, is 1000, which seems correct. FreeMargin=100. Multiply 0.1 lot by 1000 and you get 100. It means we have enough funds to open the 1st lot. But the tester reports that we do not have enough funds. Where is the error?

The error is that you forgot about the margin currency in your calculations. Balance = 100 USD and margin requirement = 100 EUR (119 USD).

That's why you can't make a transaction - everything is correct.

 
Renat:

The mistake is that you forgot about the margin currency in your calculations. Balance = 100 USD and margin requirement = 100 EUR (119 USD).

That's why it's not possible to make a transaction - everything is correct.

Thank you Renat. I have understood my mistake. Changed the formula for LotRqdMgn calculation and everything works correctly now.

 

A new word in librarianship, or the amazing next to it...


So, I created an Expert Advisor that uses the library, checked it and everything works. I have made an archive with the Expert Advisor, this library and some MQL5 and MQH files. I gave the archive to the Appliciant/Developer for testing.


That would be OK, but I have decided to run the tests on another terminal. So I unpacked the archive and decided to attach the Expert Advisor to the chart.


And in terminal journal these two lines are written:

2010.06.10 09:54:51 PM Experts MechanicalTrading-Infinity-2010 (EURUSD,Daily)
2010.06.10 09:54:51 Experts Loading of MechanicalTrading-Infinity-2010 (EURUSD,Daily) failed


I started to search what and how it works (or rather, doesn't work) and found an astonishing fact - terminal sees compiled library in directory (as *.ex5), but persistently "sinks" it, which is not very good, as you understand...

After trying many possible reasons for such behaviour, I decided to place the original file (as *.mq5) in the folder with the library. I tried to add an EA to the chart - oh my god, everything works.


In the process of the game, a number of questions came up:

1. Why doesn't the Expert Advisor work, if the library is represented only as .ex5?

2. Why does the terminal stubbornly delete this file from the directory?

3. Why doesn't the terminal log have a clear comment about all of the above?

4. Why doesn't the documentation say this behavior is possible?


And finally the fifth and final question - how do I cope with all this and what am I doing wrong (may be the terminal is missing one EX5 file and searching for something, for example a header file or the library itself)?


PS

By the way, I got the same bug with Expert Advisors, stubborn deletion of *.ex5 file... :(

Reason: