Questions from Beginners MQL5 MT5 MetaTrader 5 - page 916

 
Zorian43:
Good evening everyone! I don't know if I'm writing in the right topic, sorry if I'm in the wrong one. When I installed Metatrader 5 on my Android, a demo account was created automatically and I was connected to it every time I started the app. When I wanted to connect another account, this time from my broker, I couldn't find the password to the demo account. I pressed "reset password" and I can´t connect to the demo account after that. Is there any way to restore access to the demo account?
No. Open a new demo account.
 

Hello!

Can you please tell me for what reason the CAccountInfo::MarginCheck() method can return the required margin of zero in the tester? It only returns zero when called for an ORDER_TYPE_BUY_LIMIT limit buy order.

Instrument Si-9.18 - dollar futures from MICEX.

In the test project, the next call in the tester gives not zero, but 90 - a small value, which looks quite implausible:

ENUM_ORDER_TYPE     orderType   = NULL;
uint                orderVolume = 1;
double              orderPrice  = gvTick.last;
double marginRequired = 0;

orderType       = ORDER_TYPE_BUY_LIMIT;
marginRequired  = gnCAccountInfo.MarginCheck( gsIns, orderType, orderVolume, orderPrice);
Print("  Требуемая маржа ", marginRequired);
Log output: 2018.09.01 13:38:56.040 2018.06.13 12:10:00 Margin required 90.0
 
rel18:

Hello!

Can you please tell me why the CAccountInfo::MarginCheck() method can return the required margin of zero in the tester? It only returns zero when called for a limit buy order ORDER_TYPE_BUY_LIMIT.

Instrument Si-9.18 - dollar futures from MICEX.

In the test project, the next call in the tester gives not zero, but 90 - a small value, which looks quite implausible:

I suspect because only

ORDER_TYPE_BUY

Market Buy order

ORDER_TYPE_SELL

Market Sell order

 
Vladimir Karputov:

I suspect this is because only

ORDER_TYPE_BUY

Market Buy order

ORDER_TYPE_SELL

Market Sell order

Here is the result of the Buy Limit Order in the tester for the same example. A margin of 90 is very small. Is it really so?


And here we have a margin of zero in the tester:



All history tests are conducted with a real account.
 

Indicator stopped working, help to compile
Thank you.

Files:
VP-Range-v6.mq5  44 kb
VP-v6.mq5  42 kb
 
rel18:

Here is the result of a limit buy order in the tester for the same example. A margin of 90 is very small, is that how it works?


Maybe it's the demo account? Try it on a real account with the same broker.

 
Aliaksei Karalkou:

Indicator stopped working, help to compile
Thank you.

Since the 1861 build there is a built-in iBarShift function, it cannot be used as a custom function. Please rename the function.

 

Hello! Please help me with this task. There is a value of String type in the format"PERIOD_M1""PERIOD_M2""PERIOD_M3", etc.. We need to replace these values with values of type ENUM_TIMEFRAMES - PERIOD_M1, PERIOD_M2, PERIOD_M3 respectively, etc..

In the EXAMPLE below everything would be fine, but we cannot use a string variable in the switch statement, what should we do? You could just use an if....else construct, but I think there are more elegant ways. Any suggestions? Thanks!

//+------------------------------------------------------------------+
//| Преобразует строку в таймфрейм                                   |
//+------------------------------------------------------------------+
ENUM_TIMEFRAMES StringToTimeframe(string timeframe)
  {
   ENUM_TIMEFRAMES tfr=Period();
   switch(timeframe) 
     {
      case "M1"  : tfr=PERIOD_M5;  break;
      case "M2"  : tfr=PERIOD_M6;  break;
      case "M3"  : tfr=PERIOD_M5;  break;
      }
//---
   return(tfr);
  }
 
Tango_X:

Hello! Please help me with this task. There is a value of String type in the format"PERIOD_M1""PERIOD_M2""PERIOD_M3", etc.. We need to replace these values with values of type ENUM_TIMEFRAMES - PERIOD_M1, PERIOD_M2, PERIOD_M3 respectively, etc..

In the EXAMPLE below everything would be fine, but we cannot use a string variable in the switch statement, what should we do? You could just use an if....else construct, but I think there are more elegant ways. Any suggestions? Thanks!

Use the if() construct

 
Tango_X:

Hello! Please help me with this task. There is a value of String type in the format"PERIOD_M1""PERIOD_M2""PERIOD_M3", etc.. We need to replace these values with values of type ENUM_TIMEFRAMES - PERIOD_M1, PERIOD_M2, PERIOD_M3 respectively, etc..

In the EXAMPLE below everything would be fine, but we cannot use a string variable in the switch statement, what should we do? You could just use an if....else construct, but I think there are more elegant ways. Any suggestions? Thanks!

//+------------------------------------------------------------------+
//| Преобразует строку в таймфрейм                                   |
//+------------------------------------------------------------------+
ENUM_TIMEFRAMES StringToTimeframe(string timeframe)
  {
   return
     (
      timeframe == "M1"   ?  PERIOD_M1  :
      timeframe == "M2"   ?  PERIOD_M2  :
      timeframe == "M3"   ?  PERIOD_M3  :
      timeframe == "M4"   ?  PERIOD_M4  :
      timeframe == "M5"   ?  PERIOD_M5  :
      timeframe == "M6"   ?  PERIOD_M6  :
      timeframe == "M10"  ?  PERIOD_M10 :
      timeframe == "M12"  ?  PERIOD_M12 :
      timeframe == "M15"  ?  PERIOD_M15 :
      timeframe == "M20"  ?  PERIOD_M20 :
      timeframe == "M30"  ?  PERIOD_M30 :
      timeframe == "H1"   ?  PERIOD_H1  :
      timeframe == "H2"   ?  PERIOD_H2  :
      timeframe == "H3"   ?  PERIOD_H3  :
      timeframe == "H4"   ?  PERIOD_H4  :
      timeframe == "H6"   ?  PERIOD_H6  :
      timeframe == "H8"   ?  PERIOD_H8  :
      timeframe == "H12"  ?  PERIOD_H12 :
      timeframe == "D1"   ?  PERIOD_D1  :
      timeframe == "W1"   ?  PERIOD_W1  :
      timeframe == "MN1"  ?  PERIOD_MN1 : 
      PERIOD_CURRENT
     );
  }
//+------------------------------------------------------------------+
Reason: