Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1388

 
OK, thank you.
 
Vladimir Karputov #:

How to get code from WinAPI function 'GetLastError'? I want to delete a non-existing file with the WinAPI function DeleteFileW.

According toDeleteFileW' s help, if

Code description 'ERROR_FILE_NOT_FOUND

ERROR_FILE_NOT_FOUND

2 (0x2)

The system cannot find the file specified.


That is, I should get a '2' when trying to delete a file that doesn't exist - but I get a '0'.


My script code:

Execution result:

uint res = kernel32::GetLastError();
 

Koldun Zloy #:

uint res = kernel32::GetLastError();


! Thank you!

 

How can I make this check work?

double arrHTF[];
double arrETF[];

bool printArr(double& arr[])
   {
   bool isequal=arr==arrETF;
   Print("equals ETF"+isequal);
   return true;
   }
 
Max B #:

How can we make this check work?

If not ArrayCompare, then in a loop by element-by-element comparison.

 
JRandomTrader #:

If not ArrayCompare, then in loop by element-by-element comparison.

I just want to compare pointers, not contents (which array does arr point to?)

 

Good afternoon! Please help me with getting the required margin value.

#include <Trade\SymbolInfo.mqh>  
#include <Trade\AccountInfo.mqh>

CSymbolInfo    m_symbol;                     // symbol info object
CAccountInfo   m_account;                    // account info object
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   m_symbol.Name(Symbol());
   
   const string this_symbol = m_symbol.Name();
   //ENUM_ORDER_TYPE order_type = ORDER_TYPE_BUY;
   double order_volume =  0;
   double order_price = 0;
   double Price_Min_Lot = 0;
   
   
   order_volume = 1;
   order_price = m_symbol.Ask();
   Price_Min_Lot = m_account.MarginCheck(this_symbol, ORDER_TYPE_BUY, order_volume, order_price);
   Print("Требуемая маржа =", Price_Min_Lot);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {

   
  }
//+---------------------------------------------------------------

Outputs: "Required margin =1.797693134862316e+308", i.e. maximum value of double. Can you please tell me where the error is, or how to make to get the right value, thank you in advance.



 
-IMXO- #:

Good afternoon! Please help me with getting the required margin value.

Outputs: "Required margin =1.797693134862316e+308", i.e. maximum value of double. Please advise me where the error is or how to get the right value, thank you in advance.

In general, when you print a double value, use:

Print( DoubleToString(Price_Min_Lot,2) );
 
Vitaly Muzichenko #:

In general, when you print double values, use:

It won't help. The function itself is crippled. And using SB is doubly awkward.

And it's also executed in OnInit(), when nothing has been loaded yet.
 
-IMXO- #:

Good afternoon! Please help me with getting the required margin value.

Outputs: "Required margin =1.797693134862316e+308", i.e. maximum value of double. Please tell me where the error is or how to get the right value, thank you in advance.



When you check something after hours, check in script.

Reason: