Questions from Beginners MQL5 MT5 MetaTrader 5 - page 42

 

Good afternoon! I can't figure out how to do one simple thing in MQL5. I need to declare a class level variable (type three-dimensional array double) and then make its late initialization in constructor. In C# it would look like this:

public class MyClass
{
   
  private double[,,] myArray;
   
  public MyClass(int dimension1, int dimension2, int dimension3)

{
   myArray = new double[dimension1, dimension2, dimension3];

}

How to achieve the same result in MQL5? I can declare a three-dimensional dynamic array. But with ArrayResize function I can allocate memory only for the first dimension, what about the other two?

Документация по MQL5: Основы языка / Типы данных / Объект динамического массива
Документация по MQL5: Основы языка / Типы данных / Объект динамического массива
  • www.mql5.com
Основы языка / Типы данных / Объект динамического массива - Документация по MQL5
 
Good day! Dear forum users, Can someone please advise here
int OnInit()
  {
//---
  Print ( ACCOUNT_BALANCE );
   Print (SYMBOL_MARGIN_INITIAL);//Начальная (инициирующая) маржа обозначает размер необходимых залоговых средств в маржинальной валюте для открытия позиции объемом в один лот. Используется при проверке средств клиента при входе в рынок.
  
   printf("ACCOUNT_BALANCE =  %G",AccountInfoDouble(ACCOUNT_BALANCE));
   printf("ACCOUNT_CREDIT =  %G",AccountInfoDouble(ACCOUNT_CREDIT));
   printf("ACCOUNT_PROFIT =  %G",AccountInfoDouble(ACCOUNT_PROFIT));
   printf("ACCOUNT_EQUITY =  %G",AccountInfoDouble(ACCOUNT_EQUITY));
   printf("ACCOUNT_MARGIN =  %G",AccountInfoDouble(ACCOUNT_MARGIN));
   printf("ACCOUNT_FREEMARGIN =  %G",AccountInfoDouble(ACCOUNT_FREEMARGIN));
   printf("ACCOUNT_MARGIN_LEVEL =  %G",AccountInfoDouble(ACCOUNT_MARGIN_LEVEL));
   printf("ACCOUNT_MARGIN_SO_CALL = %G",AccountInfoDouble(ACCOUNT_MARGIN_SO_CALL));
   printf("ACCOUNT_MARGIN_SO_SO = %G",AccountInfoDouble(ACCOUNT_MARGIN_SO_SO));
  
   MqlTradeRequest request={0};
      MqlTradeResult result={0};
      
 
  {
    request.    action=TRADE_ACTION_DEAL;           // Тип выполняемого действия
  
    request.                        volume=1;           // Запрашиваемый объем сделки в лотах     
    request.               type=ORDER_TYPE_SELL;             // Тип ордера
    
   }
   
  OrderSend(request,result); 
  
  
  int Error=GetLastError(); ResetLastError();
        printf("Error %i ",Error);
      
        
        
       
  
  
  
  
  
  
  
  
//---
   return(0);
  }
//+------------------------------------------------------------------+

ERR_TRADE_SEND_FAILED
4756
Failed to send trade request

Why didn't it work? Maybe the professionals can tell me quickly where to look, otherwise I'll be guessing till tonight...

Документация по MQL5: Торговые функции / OrderSend
Документация по MQL5: Торговые функции / OrderSend
  • www.mql5.com
Торговые функции / OrderSend - Документация по MQL5
 
Dimka-novitsek:
Good day! Dear forum users, can someone give you some tips here?

ERR_TRADE_SEND_FAILED
4756
Failed to send a trade request

Why didn't it work? Maybe professionals will quickly tell you where to look, otherwise I'll be guessing till evening...

You do not need to guess, you need to look at information in MqlTradeRequest request, you created it for a reason.

Well, for starters you have not specified the price at which you plan to sell

 
Dimka-novitsek: I'd like to know where to look quickly, otherwise I'll be guessing until tonight...
First, you need to see how many mandatory fields must be filled in for the request variable for this type of action.
 
Thank you!!! I somehow thought that with instant execution the price was understandable....
 
Good day! I do not quite understand how to use the function
 for (int i=0;i<10;i=i+0.1){ Print( "i ",i);  
 bool  OrderCalcMargin(
         action=ORDER_TYPE_SELL,           // тип ордера
                  symbol=_Symbol,           // имя символа
                  volume=i,           // объем
                  price=last_tick.bid,            // цена открытия
   double&               margin            // переменная для получения значения маржи
   ); 
   Print( " margin  ", margin );  }
  

OrderCalcMargin' - function can be declared only in the global scope deposit.mq5 86 Something is wrong, in short.

In general, I want to create a function that uses a percentage of the deposit. For example, 50% is a deal on half of my deposit. I want to understand how much 1 lot is? Can it be calculated programmatically? I have been thinking and reading for the third day now. And lots may be different everywhere - it depends on the type of transaction and on the account!

Документация по MQL5: Стандартные константы, перечисления и структуры / Торговые константы / Свойства сделок
Документация по MQL5: Стандартные константы, перечисления и структуры / Торговые константы / Свойства сделок
  • www.mql5.com
Стандартные константы, перечисления и структуры / Торговые константы / Свойства сделок - Документация по MQL5
 
Dimka-novitsek:
Good day! I do not quite understand how to use the function

OrderCalcMargin' - the function can be declared only in the global scope of deposit.mq5 86 Something is wrong.

Dmitry!

Read carefully what a function is and what a function call is

You've got a complete mess of declarations and uses

 
Dimka-novitsek: I want to understand, how much is 1 lot? Is it possible to calculate it programmatically? I have been thinking and reading for three days now. And lots may be different everywhere - it depends on the type of transaction and on the account!
If your answer to the second question, try to find the article"The ABCs of Currency Trading" by its title. It seems to be written for MT4, but it's not too special.
 

Thank you!

Yes, the double-pred function is my fault...

 

It still frowns... Let's say action=ORDER_TYPE_SELL, it says 'action' - undeclared identifier. OrENUM_ORDER_TYPE action=ORDER_TYPE_SELL, it says 'action' - unexpected token.

It's everywhere... And in English...

 for (int i=0;i<10;i=i+0.1){ Print( "i ",i);  
  OrderCalcMargin(
       ENUM_ORDER_TYPE  action=ORDER_TYPE_SELL,           // тип ордера
                  symbol=_Symbol,           // имя символа
                  volume=i,           // объем
                  price=last_tick.bid,            // цена открытия
                 margin            // переменная для получения значения маржи
   ); 
   Print( " margin  ", margin );  }
Reason: