Questions from Beginners MQL5 MT5 MetaTrader 5 - page 662
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Unfortunately, there is no analog of theMarketInfo(symbf,MODE_MARGINREQUIRED) property in MQL5, but it was already discussed somewhere on the forum
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.
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);
Thank you! Figured it out.
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);
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);
}
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);
}
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.
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:
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"));
}
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 :)
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...