MetaTrader 4 Build 574 with Updated MQL4 Language and Market of Applications Released - page 17

 
mikol:

Ok thanks.

The following is not fully tested, but does seem to work at first glance. Two different options for how ReadUrl() does the Ansi-to-Unicode conversion:

// If turned on, ReadUrl() works by writing the server response to a temporary file and then reading it back in.
// If turned off, ReadUrl() works by converting the Ansi response to Unicode in memory using MultiByteToWideChar()
#define READURL_USE_TEMPFILE   false

#import "wininet.dll"
   int InternetOpenW(string, int, string, string, int);
   int InternetOpenUrlW(int, string, string, int, int, int);
   int InternetCloseHandle(int);
   int InternetReadFile(int, int, int, int & arr[]);
#import

#import "kernel32.dll"
   int LocalAlloc(int, int);                   
   int LocalFree(int);                  
   // Can be removed if READURL_USE_TEMPFILE = true
      int MultiByteToWideChar(int, int, int, int, string &, int);
   // Can be removed if READURL_USE_TEMPFILE = false
      int CreateFileW(string, int, int, int, int, int, int);   
      int WriteFile(int, int, int, int & arr[], int);
      int CloseHandle(int);
#import
                
string ReadUrl(string Url, bool PrintDebuggingMessages = false)
{
   string strData = "";
   bool bSuccess = false;
   
   // Get an internet handle
   int hInternet = InternetOpenW("me!", 0 /* 0 = INTERNET_OPEN_TYPE_PRECONFIG */, NULL, NULL, 0);
   if (hInternet == 0) {
      if (PrintDebuggingMessages) Print("InternetOpenW() failed");
   } else {
      
      // Get a URL handle
      int hInternetUrl = InternetOpenUrlW(hInternet, Url, NULL, 0, 0, 0);
      if (hInternetUrl == 0) {
         if (PrintDebuggingMessages) Print("InternetOpenUrlW() failed");
      } else {
         if (PrintDebuggingMessages) Print("Okay: url handle: ", hInternetUrl);

         #ifdef READURL_USE_TEMPFILE
            string strTempFile = "url.txt";
            int hTempFile = CreateFileW(StringConcatenate(TerminalInfoString(TERMINAL_DATA_PATH), "\\MQL4\\Files\\", strTempFile), 1073741824, 0, 0, 2, 0, 0);
            if (hTempFile == -1 /* -1 = INVALID_HANDLE_VALUE */) {
         #endif 
                  
         } else {
            // Allocate a buffer to hold the web server's response.
            // We potentially get the response in multiple chunks
            int szBuffer = 50000;
            int ptrBuffer = LocalAlloc(0x40 /* LMEM_FIXED | LMEM_ZEROINIT*/, szBuffer);
            if (ptrBuffer == 0) {
               if (PrintDebuggingMessages) Print("Memory allocation failed");
            } else {
            
               // Keep calling InternetReadFile() until it fails, or until
               // it says that the read is complete
               bool bKeepReading = true;
               while (bKeepReading) {                    
                  int szRead[1];
                  int success = InternetReadFile(hInternetUrl, ptrBuffer, szBuffer - 1, szRead);
                  if (success == 0) {
                     if (PrintDebuggingMessages) Print("InternetReadFile failed");
                     bKeepReading = false;
                  } else {
                     
                     // InternetReadFile() has succeeded, but we may be at the end of the data 
                     if (szRead[0] == 0) {
                        if (PrintDebuggingMessages) Print("Reached end of data");
                        bKeepReading = false;
                        bSuccess = true;
                        
                     } else {
                        // We either write the data to a temporary file, or we convert
                        // it in memory using MultiByteToWideChar()
                        #ifdef READURL_USE_TEMPFILE
                           int szWritten[1];
                           WriteFile(hTempFile, ptrBuffer, szRead[0], szWritten, 0);
                        #else                          
                           // Get the number of Unicode characters which are equivalent to the bytes received
                           string strDummy = "";
                           int RequiredChars = MultiByteToWideChar(0, 0, ptrBuffer, szRead[0], strDummy, 0);
                           if (RequiredChars == 0) {
                              if (PrintDebuggingMessages) Print("Failed to get conversion size");
                              bKeepReading = false; // Exit
                           } else {
                              // Need a buffer which is RequiredChars chars long 
                              string strConvert = "";
                              for (int i = 0; i < RequiredChars; i++) strConvert = StringConcatenate(strConvert, " ");
                              
                              // Do the Ansi to Unicode conversion
                              int DoneChars = MultiByteToWideChar(0, 0, ptrBuffer, szRead[0], strConvert, RequiredChars);
                              if (DoneChars == 0) {
                                 if (PrintDebuggingMessages) Print("Failed to do string conversion");
                                 bKeepReading = false; // Exit
                              } else {
                                 
                                 // Add the converted text to the total response
                                 strData = StringConcatenate(strData, strConvert);
                              }
                           }
                        #endif                           
                     }
                  }
               }
                       
               LocalFree(ptrBuffer);
            }
         
            CloseHandle(hTempFile);

            if (bSuccess) {
               #ifdef READURL_USE_TEMPFILE
                  // If we are using a temporary file rather than in-memory conversion,
                  // then we now need to read that temp file back in from disk
                  int fRead = FileOpen(strTempFile, FILE_BIN | FILE_ANSI | FILE_READ);
                  if (fRead < 0) {
                     if (PrintDebuggingMessages) Print("Failed to open temp file for reading");
                  } else {
                     strData = FileReadString(fRead, FileSize(fRead));
                     FileClose(fRead);
                  }
                  FileDelete(strTempFile);
               #endif                   
            }
         }
         InternetCloseHandle(hInternetUrl);
      }
      InternetCloseHandle(hInternet);
   }

   return (strData);
}

// EXAMPLE:
void start()
{
   string strData = ReadUrl("http://www.google.com/");
   Print(strData);
}
 
Ovo:

I feel something smelly with the 577 update.

Custom indicators behave very strange, I did not find clue yet, but I feel big trouble in the air... Problems are both with the original 509 ex4 and those compiled in 574/577 running on the start() method.

You could be right, I had a custom indicator running on the beta since the first release it has worked correctly through every update since then except now build 577 it is not drawing its objects correctly I havent had time to track down the issue yet though.
 
gchrmt4:

The following is not fully tested, but does seem to work at first glance. Two different options for how ReadUrl() does the Ansi-to-Unicode conversion:



Lovely! thanks
 

hi all,

i've been testing the 574 build and i'm getting an error that i don't get in 509. I use an EA which uses thre DLL's (user32, shell32 and kernel32). I copied the exactly files from 509 to 574 and when i run the EA this is the error i get: "Cannot load 'C:\Users\xxxx\AppData\Roaming\MetaQuotes\Terminal\B0ECF8932F3651E4A257AF9885DA21B7\MQL4\Libraries\user32.dll'" and the same for the others dll

what am i doing wrong? i've copied the files in "C:\Users\xxxx\AppData\Roaming\MetaQuotes\Terminal\B0ECF8932F3651E4A257AF9885DA21B7\MQL4\Libraries" folder and in C:\Users\xxxx\Desktop\MetaTrader4\MQL4\Libraries

can anyone share those dll's please?

thanks.

 

The current help file seems to be rather inconsistent (if I neglect a few pages in Cyrillic)

______________________________________

iCustom

Calculates the specified custom indicator and returns its value.

double iCustom(
string symbol, // symbol
int timeframe, // timeframe
string name, // path/name of the custom indicator compiled program
... // custom indicator input parameters (if necessary)
int mode, // line index
int shift // shift
);

int handle_customMA=iCustom(Symbol(),PERIOD_CURRENT, "Custom Moving Average",13,0, MODE_EMA,PRICE_TYPICAL);


I need to get the latter, but the compiler seems to recognize only the former.

 

If any one is still interested with weird behaviour... this time it is about indicators.

  • It seems that "Array out of range" is fired regardless of setting the #property strict in 577. This might be the reason some "updated" indicators suddenly stopped working in 577.
  • Indicator variables at global scope do not clear after deinit(). That might confuse some recently "updated" indicators to initialize properly.
  • I am still having issues with the 509 ex4 indicators in compatibility mode. They start correctly when attached, but end up with expert stopped error after changing timeframe or input parameters. Then they cannot recover until detached. Edit: according to trace information in logs it looks like it crashes on a first ex4-library call.
 

double iCustom(
string symbol, // symbol
int timeframe, // timeframe
string name, // path/name of the custom indicator compiled program
... // custom indicator input parameters (if necessary)
int mode, // line index
int shift // shift

);

int handle_customMA=iCustom(Symbol(),PERIOD_CURRENT, "Custom Moving Average",13,0, MODE_EMA,PRICE_TYPICAL);
                                                                                          Mode and shift ???

 
WHRoeder:


Yes. I only copy/pasted two parts of the help, so I am afraid only MQs know what is what, but for me it is confusing.
 
I cannot select some fonts in MetaEditor, such as Inconsolata. Why?
 

Hi,

Has someone succeded in using the new "custom" optimisation criteria with OnTester() method ?

Seems to return always 0 for me.

Thanks.

Reason: