Errors, bugs, questions - page 2020

 
Kirill Belousov:

The OrderCalcMargin function does not take the opening price into account when calculating margin

Is this a Bug or should it be?

Of course it's a bug. Write to the SD.

Print("price_1= ",price_1," margin_1= ",NormalizeDouble(margin_1,8)," ",TOSTRING(OrderCalcMargin(ORDER_TYPE_BUY,_Symbol,0.1,price_1,margin_1)));

This line works as it should, but I had to check as I have to guess the order of execution. Discussion on this point here.

 
fxsaber:

A bug, of course. Write in the SD.

This line works as it should, but I had to check as I have to guess the order of execution. Discussion of this point here.

The order of calculating expressions in Print() is from right to left. Sort of... So far... Also checked it beforehand :)


It's hard to be sure when there is adirect contradiction in MQL4/5 reference:

MQL5 ReferenceLanguage FundamentalsFunctionsParameter Passing

Note

Remember that parameters are passed to the function backwards, i.e., the last parameter is calculated and passed first, then the penultimate one, and so on. The parameter that is the first after the opening bracket is calculated and passed to the function last.


MQL5 ReferenceLanguage FundamentalsOperations and ExpressionsOther Operations

Function call with arguments x1, x2,..., xn

Each argument can be a constant, a variable or an expression of a corresponding type. Passed arguments are separated by commas and must be enclosed in parentheses, the opening parenthesis must follow the function name.

The value of the expression is the value returned by the function. If the return value type of a function is void, the function call cannot be placed to the right of the assignment operation. Note that the order of expressions x1,..., xn is guaranteed.


So far I'm focusing on passing parameters in reverse order.

 
Kirill Belousov:

A question about OrderCalcMargin came up in a neighbouring threadhttps://www.mql5.com/ru/forum/216697/page3


Test: let's check 2 different ways of calculating the deposit by substituting different opening prices.

Here is the LOG

The OrderCalcMargin function doesn't consider the opening price when calculating the margin

This seems to be related to the exchange rate of the quoted currency, which has to be recalculated for the time and opening price.

If the quoted currency is USD (and the account currency is also USD), then the calculated margin will change according to the opening price.

Log for GBPUSD

Is it a Bug or should it be?

Probably it should be, because AUDUSD and USDJPY in particular are involved in the calculation, and their quotes are constant at the time of calculation.

Now, this thought makes me want to check... In the MetaQuotes-Demo account in the market overview GBPUSD is present, but not in the robo account...

 
Alexey Viktorov:

This must be the case because AUDUSD and USDJPY in particular are involved in the calculation and their quotes are unchanged at the time of calculation.

Now, this thought makes me want to check... GBPUSD is present in MetaQuotes-Demo account, but not in Robo-account...

Just wanted to tell you - that there is a bug.

I have already reproduced your situation with Margin=0 in OrderCalcMargin calculation.

Just haven't posted it yet.

 
Alexey Viktorov:

In MetaQuotes-Demo account GBPUSD is present in Market Watch, but not in Robo account...

Most likely present in Market Watch (not to be confused with the general list of symbols), but not shown.

 
Alexey Viktorov:

This must be the case because AUDUSD and USDJPY in particular are involved in the calculation and their quotes are unchanged at the time of calculation.

Now, this thought makes me want to check... In the MetaQuotes-Demo account in the market overview GBPUSD is present but not in the robo account...

Here is the test:

#define  TOSTRING(A) #A+" = "+(string)(A)
void OnStart()
  {
   double margin_1=999,price_1;

   Print(TOSTRING(price_1=SymbolInfoDouble(Symbol(),SYMBOL_ASK)));
   Print("price_1= ",price_1," margin_1= ",NormalizeDouble(margin_1,8)," ",TOSTRING(OrderCalcMargin(ORDER_TYPE_BUY,_Symbol,0.1,price_1,margin_1)));
   Print("price_1= ",price_1," margin_1= ",NormalizeDouble(margin_1,8)," ",TOSTRING(MyOrderCalcMargin(ORDER_TYPE_BUY,_Symbol,0.1,price_1,margin_1)));
   Print(TOSTRING(price_1=SymbolInfoDouble(Symbol(),SYMBOL_BID)));
   Print("price_1= ",price_1," margin_1= ",NormalizeDouble(margin_1,8)," ",TOSTRING(OrderCalcMargin(ORDER_TYPE_BUY,_Symbol,0.1,price_1,margin_1)));
   Print("price_1= ",price_1," margin_1= ",NormalizeDouble(margin_1,8)," ",TOSTRING(MyOrderCalcMargin(ORDER_TYPE_BUY,_Symbol,0.1,price_1,margin_1)));
   Print(TOSTRING(price_1=10.0));
   Print("price_1= ",price_1," margin_1= ",NormalizeDouble(margin_1,8)," ",TOSTRING(OrderCalcMargin(ORDER_TYPE_BUY,_Symbol,0.1,price_1,margin_1)));
   Print("price_1= ",price_1," margin_1= ",NormalizeDouble(margin_1,8)," ",TOSTRING(MyOrderCalcMargin(ORDER_TYPE_BUY,_Symbol,0.1,price_1,margin_1)));
   Print(TOSTRING(price_1=1.0));
   Print("price_1= ",price_1," margin_1= ",NormalizeDouble(margin_1,8)," ",TOSTRING(OrderCalcMargin(ORDER_TYPE_BUY,_Symbol,0.1,price_1,margin_1)));
   Print("price_1= ",price_1," margin_1= ",NormalizeDouble(margin_1,8)," ",TOSTRING(MyOrderCalcMargin(ORDER_TYPE_BUY,_Symbol,0.1,price_1,margin_1)));
//выведем признак выбранности мажоров
   Print(TOSTRING(SymbolInfoInteger("GBPUSD",SYMBOL_SELECT)));
   Print(TOSTRING(SymbolInfoInteger("USDJPY",SYMBOL_SELECT)));
   Print(TOSTRING(SymbolInfoInteger("USDCAD",SYMBOL_SELECT)));
   Print(TOSTRING(SymbolInfoInteger("AUDUSD",SYMBOL_SELECT)));
   Print(TOSTRING(SymbolInfoInteger("NZDUSD",SYMBOL_SELECT)));
   Print(TOSTRING(SymbolInfoInteger("USDCHF",SYMBOL_SELECT)));
   Print(TOSTRING(SymbolInfoInteger("EURUSD",SYMBOL_SELECT)));
   for(int i=SymbolsTotal(false)-1;i>=0;i--)
     {
       //проверим для каждого символа брокера ситуацию, когда OrderCalcMargin()==true, а маржа=0
       if(OrderCalcMargin(ORDER_TYPE_BUY,SymbolName(i,false),0.1,SymbolInfoDouble(SymbolName(i,false),SYMBOL_ASK),margin_1)==true && margin_1==0)
        {
         Print(TOSTRING(SymbolName(i,false))," ",TOSTRING(margin_1)," ");
        }
     }
  }

// Альтернатива OrderCalcMargin
bool MyOrderCalcMargin(const ENUM_ORDER_TYPE action,const string symbol,const double volume,const double price,double &margin)
  {
   double MarginInit,MarginMain;

   const bool Res=SymbolInfoMarginRate(symbol,action,MarginInit,MarginMain);

   margin=Res ? MarginInit*price*volume*SymbolInfoDouble(symbol,SYMBOL_TRADE_TICK_VALUE)/
          (SymbolInfoDouble(symbol,SYMBOL_TRADE_TICK_SIZE)*AccountInfoInteger(ACCOUNT_LEVERAGE)) : 0;

   return(Res);
  }

1. Select crosses in MarketWatch, hide everything with USD

2) Add DSHBTC symbol and open its chart.

3. Close terminal

4) Open the terminal

5. Let's start test for DSHBTC

Here is the LOG:

JM      0       09:26:05.485    test (DSHBTC,H1)        price_1=SymbolInfoDouble(Symbol(),SYMBOL_ASK) = 0.07183
QK      0       09:26:05.487    test (DSHBTC,H1)        price_1= 0.07183 margin_1= 0.0 OrderCalcMargin(ORDER_TYPE_BUY,_Symbol,0.1,price_1,margin_1) = true
KO      0       09:26:05.487    test (DSHBTC,H1)        price_1= 0.07183 margin_1= 0.0 MyOrderCalcMargin(ORDER_TYPE_BUY,_Symbol,0.1,price_1,margin_1) = true
QN      0       09:26:05.487    test (DSHBTC,H1)        price_1=SymbolInfoDouble(Symbol(),SYMBOL_BID) = 0.07079000000000001
NJ      0       09:26:05.487    test (DSHBTC,H1)        price_1= 0.07079000000000001 margin_1= 0.0 OrderCalcMargin(ORDER_TYPE_BUY,_Symbol,0.1,price_1,margin_1) = true
HO      0       09:26:05.487    test (DSHBTC,H1)        price_1= 0.07079000000000001 margin_1= 0.0 MyOrderCalcMargin(ORDER_TYPE_BUY,_Symbol,0.1,price_1,margin_1) = true
LL      0       09:26:05.487    test (DSHBTC,H1)        price_1=10.0 = 10.0
EE      0       09:26:05.487    test (DSHBTC,H1)        price_1= 10.0 margin_1= 0.0 OrderCalcMargin(ORDER_TYPE_BUY,_Symbol,0.1,price_1,margin_1) = true
QF      0       09:26:05.487    test (DSHBTC,H1)        price_1= 10.0 margin_1= 0.0 MyOrderCalcMargin(ORDER_TYPE_BUY,_Symbol,0.1,price_1,margin_1) = true
HD      0       09:26:05.487    test (DSHBTC,H1)        price_1=1.0 = 1.0
EN      0       09:26:05.487    test (DSHBTC,H1)        price_1= 1.0 margin_1= 0.0 OrderCalcMargin(ORDER_TYPE_BUY,_Symbol,0.1,price_1,margin_1) = true
OM      0       09:26:05.487    test (DSHBTC,H1)        price_1= 1.0 margin_1= 0.0 MyOrderCalcMargin(ORDER_TYPE_BUY,_Symbol,0.1,price_1,margin_1) = true
EN      0       09:26:05.487    test (DSHBTC,H1)        SymbolInfoInteger(GBPUSD,SYMBOL_SELECT) = 0
GI      0       09:26:05.487    test (DSHBTC,H1)        SymbolInfoInteger(USDJPY,SYMBOL_SELECT) = 0
DS      0       09:26:05.487    test (DSHBTC,H1)        SymbolInfoInteger(USDCAD,SYMBOL_SELECT) = 0
JL      0       09:26:05.487    test (DSHBTC,H1)        SymbolInfoInteger(AUDUSD,SYMBOL_SELECT) = 0
JF      0       09:26:05.487    test (DSHBTC,H1)        SymbolInfoInteger(NZDUSD,SYMBOL_SELECT) = 0
MQ      0       09:26:05.487    test (DSHBTC,H1)        SymbolInfoInteger(USDCHF,SYMBOL_SELECT) = 0
HK      0       09:26:05.487    test (DSHBTC,H1)        SymbolInfoInteger(EURUSD,SYMBOL_SELECT) = 0
LH      0       09:26:05.488    test (DSHBTC,H1)        SymbolName(i,false) = DSHBTC margin_1 = 0.0 
RS      0       09:26:05.489    test (DSHBTC,H1)        SymbolName(i,false) = NZDJPY margin_1 = 0.0 
FE      0       09:26:05.489    test (DSHBTC,H1)        SymbolName(i,false) = NZDCHF margin_1 = 0.0 
QO      0       09:26:05.489    test (DSHBTC,H1)        SymbolName(i,false) = NZDCAD margin_1 = 0.0 
RP      0       09:26:05.489    test (DSHBTC,H1)        SymbolName(i,false) = GBPNZD margin_1 = 0.0 
JD      0       09:26:05.489    test (DSHBTC,H1)        SymbolName(i,false) = GBPCAD margin_1 = 0.0 
CN      0       09:26:05.489    test (DSHBTC,H1)        SymbolName(i,false) = GBPJPY margin_1 = 0.0 
KP      0       09:26:05.489    test (DSHBTC,H1)        SymbolName(i,false) = GBPCHF margin_1 = 0.0 
JK      0       09:26:05.489    test (DSHBTC,H1)        SymbolName(i,false) = GBPAUD margin_1 = 0.0 
QL      0       09:26:05.489    test (DSHBTC,H1)        SymbolName(i,false) = EURNZD margin_1 = 0.0 
RG      0       09:26:05.489    test (DSHBTC,H1)        SymbolName(i,false) = EURJPY margin_1 = 0.0 
RH      0       09:26:05.489    test (DSHBTC,H1)        SymbolName(i,false) = EURGBP margin_1 = 0.0 
HS      0       09:26:05.489    test (DSHBTC,H1)        SymbolName(i,false) = EURCHF margin_1 = 0.0 
CD      0       09:26:05.489    test (DSHBTC,H1)        SymbolName(i,false) = EURCAD margin_1 = 0.0 
GO      0       09:26:05.489    test (DSHBTC,H1)        SymbolName(i,false) = EURAUD margin_1 = 0.0 
QP      0       09:26:05.489    test (DSHBTC,H1)        SymbolName(i,false) = CHFJPY margin_1 = 0.0 
JJ      0       09:26:05.489    test (DSHBTC,H1)        SymbolName(i,false) = CADJPY margin_1 = 0.0 
JL      0       09:26:05.489    test (DSHBTC,H1)        SymbolName(i,false) = CADCHF margin_1 = 0.0 
QF      0       09:26:05.489    test (DSHBTC,H1)        SymbolName(i,false) = AUDNZD margin_1 = 0.0 
NI      0       09:26:05.489    test (DSHBTC,H1)        SymbolName(i,false) = AUDJPY margin_1 = 0.0 
JS      0       09:26:05.489    test (DSHBTC,H1)        SymbolName(i,false) = AUDCHF margin_1 = 0.0 
EF      0       09:26:05.489    test (DSHBTC,H1)        SymbolName(i,false) = AUDCAD margin_1 = 0.0 

All crosses show margin=0 and NO CROSS MAJORS have been selected.

Once again, run the script on DSHBTC

LOG

HF      0       09:29:07.268    test (DSHBTC,H1)        price_1=SymbolInfoDouble(Symbol(),SYMBOL_ASK) = 0.07185999999999999
IQ      0       09:29:07.268    test (DSHBTC,H1)        price_1= 0.07185999999999999 margin_1= 0.0 OrderCalcMargin(ORDER_TYPE_BUY,_Symbol,0.1,price_1,margin_1) = true
KP      0       09:29:07.268    test (DSHBTC,H1)        price_1= 0.07185999999999999 margin_1= 0.0 MyOrderCalcMargin(ORDER_TYPE_BUY,_Symbol,0.1,price_1,margin_1) = true
DE      0       09:29:07.269    test (DSHBTC,H1)        price_1=SymbolInfoDouble(Symbol(),SYMBOL_BID) = 0.07087
OQ      0       09:29:07.269    test (DSHBTC,H1)        price_1= 0.07087 margin_1= 0.0 OrderCalcMargin(ORDER_TYPE_BUY,_Symbol,0.1,price_1,margin_1) = true
MQ      0       09:29:07.269    test (DSHBTC,H1)        price_1= 0.07087 margin_1= 0.0 MyOrderCalcMargin(ORDER_TYPE_BUY,_Symbol,0.1,price_1,margin_1) = true
QP      0       09:29:07.269    test (DSHBTC,H1)        price_1=10.0 = 10.0
HI      0       09:29:07.269    test (DSHBTC,H1)        price_1= 10.0 margin_1= 0.0 OrderCalcMargin(ORDER_TYPE_BUY,_Symbol,0.1,price_1,margin_1) = true
LK      0       09:29:07.269    test (DSHBTC,H1)        price_1= 10.0 margin_1= 0.0 MyOrderCalcMargin(ORDER_TYPE_BUY,_Symbol,0.1,price_1,margin_1) = true
MH      0       09:29:07.269    test (DSHBTC,H1)        price_1=1.0 = 1.0
HR      0       09:29:07.269    test (DSHBTC,H1)        price_1= 1.0 margin_1= 0.0 OrderCalcMargin(ORDER_TYPE_BUY,_Symbol,0.1,price_1,margin_1) = true
NP      0       09:29:07.269    test (DSHBTC,H1)        price_1= 1.0 margin_1= 0.0 MyOrderCalcMargin(ORDER_TYPE_BUY,_Symbol,0.1,price_1,margin_1) = true
GR      0       09:29:07.269    test (DSHBTC,H1)        SymbolInfoInteger(GBPUSD,SYMBOL_SELECT) = 1
FM      0       09:29:07.269    test (DSHBTC,H1)        SymbolInfoInteger(USDJPY,SYMBOL_SELECT) = 0
JG      0       09:29:07.269    test (DSHBTC,H1)        SymbolInfoInteger(USDCAD,SYMBOL_SELECT) = 1
DP      0       09:29:07.269    test (DSHBTC,H1)        SymbolInfoInteger(AUDUSD,SYMBOL_SELECT) = 1
DJ      0       09:29:07.269    test (DSHBTC,H1)        SymbolInfoInteger(NZDUSD,SYMBOL_SELECT) = 1
OE      0       09:29:07.269    test (DSHBTC,H1)        SymbolInfoInteger(USDCHF,SYMBOL_SELECT) = 1
FO      0       09:29:07.269    test (DSHBTC,H1)        SymbolInfoInteger(EURUSD,SYMBOL_SELECT) = 1
DD      0       09:29:07.269    test (DSHBTC,H1)        SymbolName(i,false) = DSHBTC margin_1 = 0.0 

There are no major components, but USDJPY is the only one.

All tests were done on MetaQuotes


 
fxsaber:

Most likely present in the Market Watch (not to be confused with the general symbol list), but not shown.

We are somehow talking about the same thing in different ways


 
Alexey Viktorov:

We are somehow talking about the same thing in different ways

Exactly. The Market Watch doesn't show it, but it is there.

 
Kirill Belousov:
for(int i=SymbolsTotal(false)-1;i>=0;i--)
Adjust it.
 
fxsaber:
Fix it.

Done!

P.S. Forgot to remove the reserve :)