Updated MQL4 and old code (sharing problem-solving experiences)

 

I think this topic may be useful in the light of the update.

The other day I foolishly decided to update the terminal and tested my Expert Advisors on it, but I did not update them on the real account.

I got errors. I do not want to say the developers are to blame, it is my fault too. However, I would like to specify a couple of details where I have encountered troubles:

1. Illegible characters in variable names: It's simple because the compiler showed the $ symbol as invalid. Fixed it quickly and easily. There were no more errors at the compilation stage.

After that, I had to find the faults in the Expert Advisor, to which the compiler did not complain.

2. When launching the test, I got swear words that the library stdlib.ex4 was not found. The solution was found stdlib source code in the specified folder and recompiled it.

3. Then I eliminated bugs associated with the fact that now as I understood NULL and 0 (zero) are different things. Earlier functions like iOpen(NULL,PERIOD_W1,1) worked correctly as iOpen(0,PERIOD_W1,1) i.e. both 0 and NULL could be specified. It doesn't work now, but the compiler doesn't swear at it, you just get an error during Expert Advisor's operation.

4. I do not know why I used NormalizeDouble(pr1,Digits) when setting an open price, stop level or profit. Now I have noticed that this function always returns a value with 4 decimal places when testing USDJPY with 3 decimal places and therefore I get errors when opening an order. I have replaced Digits with Digits() and everything is working.

That is all I faced at the moment. Now I am checking my EA for possible other problems.

By the way, if not recompiling the old code, ex4 will work without errors.

My build is currently 579, I still have 509 running on the real, flight is ok, but I am scared to upgrade.

If anyone has encountered problems with the transition - post here, it will be useful to others.

 
Check for 583, please.
 

Similar problem with the Point variable. Changing to Point()

Haven't got around to 583 build yet. And my broker doesn't have it yet.

 

Once again about Digits and Point.

I found out that the problem with them occurs when testing the same Expert Advisor on symbols of different digit capacity. The tester does not seem to change these variables. For instance, I first test it on Yerovdollar and then change the symbol for Dollar in the tester and the problem occurs. Or vice versa.

So maybe this is just a problem with the tester and this will not happen in real life. But I am just in case I always change Digits on Digits () and Point on Point ()

UPDATE change still does not help. Only restarting the terminal helps.

 
Thank you, we will check and fix it on Monday.
 

Oh, and I thought my code was all messed up...

Also in the tester the EA doesn't work, if the first test was on 4 digits, then the yen pairs are no longer tested, no positions open. For the test to pass on them too, I have to restart the terminal or recompile the EA.

Build 584.

No, I do not claim that my code is perfect, but the same code in build 509 worked in the tester during a change of the tested symbol without restarting the terminal, and without recompilation.


P.S.: The problem has been solved by calling type constructs so far:

   digits = MarketInfo( Symbol(), MODE_DIGITS);
   point = MarketInfo( Symbol(), MODE_POINT);

instead of simply assigning values to these variables, which seem to mean the same thing:

digits = Digits;
point = Point;
 

When translating to string for Comment on the graph, I replace Digits (gives 4) by the number 5. If I switch on "debugging", edit something, then on "pause" the chart disappears, and on completion of debugging a new chart appears (all green) with Expert Advisor, but without indicators! Is it going to be like that or is it temporary?

Good thing that only the one on the Demo has been updated. The one on Real has not updated yet. I don't know what to do, there are positions open in a small minus!

 

The green arrow points to the first line in the start:

int digits = MarketInfo( Symbol(), MODE_DIGITS); And at the bottom: MQL4\Experts\"EA name" start and line number No errors, but it doesn't compile What does it mean? I was told that nothing would happen! Could you please explain!

 

InternetOpenUrlA() from wininet.dll stopped working

Outputs 0 (zero) instead of internet page text.

Here's the full code.

#import "wininet.dll"

int InternetOpenA( string sAgent, int lAccessType, string sProxyName, string sProxyBypass, int lFlags );

int InternetOpenUrlA( int hInternetSession, string sUrl, string sHeaders, int lHeadersLength, int lFlags, int lContext );

int InternetReadFile( int hFile, int& lpvBuffer[], int lNumBytesToRead, int& lNumberOfBytesRead[] );

int InternetCloseHandle( int hInet );

int InternetQueryDataAvailable( int hFile, int& lpdwNumberOfBytesAvailable[], int dwFlags, int dwContext );

int HttpQueryInfoA(int hRequest, int dwInfoLevel, int& lpvBuffer[], int& lpdwBufferLength[], int& lpdwReserved[] );

#import


#define INTERNET_OPEN_TYPE_PRECONFIG 0x00000000 // use registry configuration

#define INTERNET_FLAG_RELOAD 0x80000000

#define INTERNET_FLAG_NO_CACHE_WRITE 0x04000000

#define INTERNET_FLAG_PRAGMA_NOCACHE 0x00000100



//+------------------------------------------------------------------+

//| script program start function |

//+------------------------------------------------------------------+

int start()

{

if(!IsDllsAllowed())

{

Alert("Необходимо в настройках разрешить использование DLL");

return(0);

}

int hInternetSession = InternetOpenA("Microsoft Internet Explorer",

0, "", "", 0);

if(hInternetSession <= 0)

{

Alert("Ошибка при вызове InternetOpenA()");

return(0);

}

int hURL = InternetOpenUrlA(hInternetSession,"https://www.mql4.com", "", 0, INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_RELOAD, 0);

if(hURL <= 0)

{

Alert("Ошибка при вызове InternetOpenUrlA()");

InternetCloseHandle(hInternetSession);

return(0);

}

int cBuffer[256];

int dwBytesRead[1];

string TXT = "";

while(!IsStopped())

{

bool bResult = InternetReadFile(hURL, cBuffer, 1024, dwBytesRead);

if(dwBytesRead[0] == 0)

break;

string text = "";

for(int i = 0; i < 256; i++)

{

text = text + CharToStr(cBuffer[i] & 0x000000FF);

if(StringLen(text) == dwBytesRead[0])

break;

text = text + CharToStr(cBuffer[i] >> 8 & 0x000000FF);

if(StringLen(text) == dwBytesRead[0])

break;

text = text + CharToStr(cBuffer[i] >> 16 & 0x000000FF);

if(StringLen(text) == dwBytesRead[0])

break;

text = text + CharToStr(cBuffer[i] >> 24 & 0x000000FF);

}

TXT = TXT + text;

Sleep(1);

}

if(TXT != "")

{

int h = FileOpen("SavedFromInternet.htm", FILE_CSV|FILE_WRITE);

if(h > 0)

{

FileWrite(h,TXT);

FileClose(h);

Alert("Готово! См. файл .../experts/files/SavedFromInternet.htm");

}

else

{

Alert("Ошибка при вызове FileOpen()");

}

}

else

{

Alert("Нет считанных данных");

}

InternetCloseHandle(hInternetSession);

return(0);

}

 
Due to the switch to unicdoe strings, you must now use InternetOpenUrlW
 
Renat:
Because of the switch to unicdoe strings, it is now necessary to use InternetOpenUrlW

It worked indeed! Thank you!