Questions from Beginners MQL5 MT5 MetaTrader 5 - page 662

 
Sergey Gritsay:
Unfortunately, there is no analog of theMarketInfo(symbf,MODE_MARGINREQUIRED) property in MQL5, but it was already discussed somewhere on the forum
OrderCalcMargin
OrderCalcMargin Calculates the amount of margin required for the specified order type in the current account and in the current market environment, excluding current pending orders and open positions. Allows you to estimate the amount of margin for the planned trade. The value is returned in the account currency. bool OrderCalcMargin ( ENUM_ORDER_TYPE action, // order type string symbol, // symbol name double volume, // volume double price, // open price double& margin // variable for margin value); Parameters action [in] Order type, can accept values from ENUM_ORDER_TYPE. symbol [in] Name of the financial instrument. volume [in] Trade operation volume. price [in] Opening price. margin [out] Variable, where the necessary amount of margin will be written in case of successful execution of this function. The calculation is done as if there were no pending orders or open positions in the current account. The margin value depends on many factors and may change during...
Documentation | 2015.12.03 14:00
 
forexman77:

You need to get programmatically,the size of free funds needed to open 1 lot to buy in MQL5, analog of MQL4 "MarketInfo(symbf,MODE_MARGINREQUIRED);"

Try the OrderCheck() function.
 
Alexey Kozitsyn:
Try the OrderCheck() function.
Thank you! Figured it out.
double lot=1.0;
double margin_buy,margin_sell;
OrderCalcMargin(ORDER_TYPE_BUY,_Symbol,lot,SymbolInfoDouble(_Symbol,SYMBOL_ASK),margin_buy);
OrderCalcMargin(ORDER_TYPE_SELL,_Symbol,lot,SymbolInfoDouble(_Symbol,SYMBOL_BID),margin_sell);
Print("margin_buy=",margin_buy);
Print("margin_sell=",margin_sell);
 
forexman77:
Thank you! Figured it out.
double lot=1.0;
double margin_buy,margin_sell;
OrderCalcMargin(ORDER_TYPE_BUY,_Symbol,lot,SymbolInfoDouble(_Symbol,SYMBOL_ASK),margin_buy);
OrderCalcMargin(ORDER_TYPE_SELL,_Symbol,lot,SymbolInfoDouble(_Symbol,SYMBOL_BID),margin_sell);
Print("margin_buy=",margin_buy);
Print("margin_sell=",margin_sell);
Yes, you can, but in the case of OrderCheck() it is fed with the trade request structure already ready to be sent just before the request itself.
 

I want to transfer part of the code into a function, but the result of the function is not to return a value, but to actually change the values of the variables, how do I do that?

 int CountExpOrder_OS=0;

 int CountExpOrder_OB=0;

 int CountMarketOrder_OS=0;

 int CountMarketOrder_OB=0;

 

OpenOrdersInfo();

void OpenOrdersInfo()

  {

   CountExpOrder_OS=StrToInteger(Order.Exp_Order_Info(Symbol(),Magic,SELL,ALL,"Number"));

   CountExpOrder_OB=StrToInteger(Order.Exp_Order_Info(Symbol(),Magic,BUY,ALL,"Number"));

   CountMarketOrder_OS=StrToInteger(Order.Market_Order_Info(Symbol(), Magic, OP_SELL, ALL, "Number"));

   CountMarketOrder_OB=StrToInteger(Order.Market_Order_Info(Symbol(), Magic, OP_BUY, ALL, "Number"));


   Print("Отложенных ордеров на покупку открыто(Magic: ",Magic,")=",CountExpOrder_OB);

   Print("Отложенных ордеров на продажу открыто(Magic: ",Magic,")=",CountExpOrder_OS);

   Print("Рыночных ордеров на покупку открыто(Magic: ",Magic,")=",CountMarketOrder_OB);

   Print("Рыночных ордеров на продажу открыто(Magic: ",Magic,")=",CountMarketOrder_OS);

  } 

 
-Aleks-:

I want to transfer a part of the code to a function, but the result of the function would not be to return a value, but to actually change the values of the variables, how do I do that?

it won't help?

int OpenOrdersInfo()

{

...

return(0);

}

 
-Aleks-:

This question, I want to transfer part of the code into a function, but the result of the function is not the return of a value, but actually change the values of variables, how do I do it?

 int CountExpOrder_OS=0;

 int CountExpOrder_OB=0;

 int CountMarketOrder_OS=0;

 int CountMarketOrder_OB=0;

 

OpenOrdersInfo();

void OpenOrdersInfo()

  {

   CountExpOrder_OS=StrToInteger(Order.Exp_Order_Info(Symbol(),Magic,SELL,ALL,"Number"));

   CountExpOrder_OB=StrToInteger(Order.Exp_Order_Info(Symbol(),Magic,BUY,ALL,"Number"));

   CountMarketOrder_OS=StrToInteger(Order.Market_Order_Info(Symbol(), Magic, OP_SELL, ALL, "Number"));

   CountMarketOrder_OB=StrToInteger(Order.Market_Order_Info(Symbol(), Magic, OP_BUY, ALL, "Number"));


   Print("Отложенных ордеров на покупку открыто(Magic: ",Magic,")=",CountExpOrder_OB);

   Print("Отложенных ордеров на продажу открыто(Magic: ",Magic,")=",CountExpOrder_OS);

   Print("Рыночных ордеров на покупку открыто(Magic: ",Magic,")=",CountMarketOrder_OB);

   Print("Рыночных ордеров на продажу открыто(Magic: ",Magic,")=",CountMarketOrder_OS);

  } 

It's OK here, VOID doesn't return the result.

 
-Aleks-:

I want to transfer part of the code into a function, but the result of the function would not be to return a value, but to actually change the values of the variables, how do I do that?

I could try that, but it's not a good solution:

int CountExpOrder_OS=0,CountExpOrder_OB=0,CountMarketOrder_OS=0,CountMarketOrder_OB=0;

OpenOrdersInfo(CountExpOrder_OS,CountExpOrder_OB,CountMarketOrder_OS,CountMarketOrder_OB);
  Print("Ордеров на покупку(Magic: ",Magic,")=",CountExpOrder_OB);
  Print("Ордеров на продажу(Magic: ",Magic,")=",CountExpOrder_OS);
  Print("Позиций на покупку(Magic: ",Magic,")=",CountMarketOrder_OB);
  Print("Позиций на продажу(Magic: ",Magic,")=",CountMarketOrder_OS);


void OpenOrdersInfo(int &CountExpOrder_OS,int &CountExpOrder_OB,int &CountMarketOrder_OS,int &CountMarketOrder_OB)
 {
  CountExpOrder_OS=StrToInteger(Order.Exp_Order_Info(Symbol(),Magic,SELL,ALL,"Number"));
  CountExpOrder_OB=StrToInteger(Order.Exp_Order_Info(Symbol(),Magic,BUY,ALL,"Number"));
  CountMarketOrder_OS=StrToInteger(Order.Market_Order_Info(Symbol(), Magic, OP_SELL, ALL, "Number"));
  CountMarketOrder_OB=StrToInteger(Order.Market_Order_Info(Symbol(), Magic, OP_BUY, ALL, "Number"));
 }
 
Vladislav Andruschenko:

It's OK, the VOID doesn't return a result.

Yes, it's working correctly - it's just that there was a bug on my part and I fell into a stupor.

Thank you all for your help.

Now I will ask questions on five :)

 
-Aleks-:

Yes, that's right - it was just a slip-up on my part and I fell into a stupor.

Thank you all for your help.

I'll be asking questions for a fiver now :)

5 quid for an answer?

)

Waiting...