After MetaEditor Update my script have erros

 

Hi Everybody.

I dont understandin why my script that ran perfectly now have erros.

My metaeditor was updated to 5 but not to mql5, continue being mql4.

But now I have an error here:

 string PipeName = "\\\\.\\pipe\\Perpendicular_as_Client";
        int PipeMode = PIPE_TYPE_MESSAGE|PIPE_READMODE_MESSAGE|PIPE_WAIT;
        hPipe = CreateNamedPipeA(PipeName,PIPE_ACCESS_DUPLEX,PipeMode,1,1024,1024,NMPWAIT_USE_DEFAULT_WAIT,NULL);
        if (hPipe == INVALID_HANDLE_VALUE) {
                Print("CreateNamedPipe failed");
      return (-1);
        }

This code always run perfectly and now, after this update, get error.

Any change happens in new version? The exactly version is 5.00 Build 883.

Thanks

 
bisewski:

Hi Everybody.

I dont understandin why my script that ran perfectly now have erros.

My metaeditor was updated to 5 but not to mql5, continue being mql4.

But now I have an error here:

This code always run perfectly and now, after this update, get error.

Any change happens in new version? The exactly version is 5.00 Build 883.

Thanks

Please read a little MetaTrader 4 Build 600 with Updated MQL4 Language and Market of Applications Released

You have to replace CreateNamedPipeA (ansi version) with unicode version.

 
angevoyageur:

Please read a little MetaTrader 4 Build 600 with Updated MQL4 Language and Market of Applications Released

You have to replace CreateNamedPipeA (ansi version) with unicode version.


opa, thanks, I change to CreateNamedPipeW and work ok.

This function was changed too?

if(FileWriteString(ExtPipe,Quotes_From_APP,size_str)<size_str)

Before, this save in a .csv file numbers like this: 2014.02.06,12:35,1.36047,1.36051,1.36052,1.36041

Now, the numbers are being saving like this: 2 0 1 4 . 0 2 . 0 6, 1 2 : 3 5, 1 . 3 6 0 4 7, 1 . 3 6 0 5 1, 1 . 3 6 0 5 2, 1 . 3 6 0 4 1

Maybe, not necessary is an space in the numbers, maybe other because in the csv file the sequence continue correct, without spaces, but when I read this value with my vb.net applicative, this spaces are read.

Sorry my english, I am with difficult to explain my problem.

sds

 
That's not a space, that's a null (ASCII zero), strings are now Unicode.
 
WHRoeder:
That's not a space, that's a null (ASCII zero), strings are now Unicode.

ok, solved, thanks all.
 

sorry but I continue having problems.

 int ShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
                int fWrite= CreateFileW(FullName, GENERIC_WRITE, ShareMode, 0, CREATE_ALWAYS, 0, 0);
                if (fWrite == INVALID_HANDLE_VALUE)
                   {                      
                      int BytesWritten[1] = {0};
                      
                      //Buffer_Old = "2014.02.06,12:35,1.36047,1.36051,1.36052,1.36041";
                      int szData = StringLen(Buffer_Old);
                      //WriteFile(fWrite, MulDiv(Buffer_Old, 1, 1), szData, BytesWritten, NULL);
                      WriteFile(fWrite, Buffer_Old, szData, BytesWritten, NULL);
                      CloseHandle(fWrite);

Buffer_Old have 200 lines like 2014.02.06,12:35,1.36047,1.36051,1.36052,1.36041 that I save in my .csv file.

The problem now is that only the middle, 100 lines are saved. If I put 500 lines, only 250 are saved. With this change ansii to unicode, I dont understanding where is the problem...

thanks

 

So if I understand good, if you are not coder specialist you will not can trade with old stratégy runing's years a go

Thanks MQ4

 
eliot:

So if I understand good, if you are not coder specialist you will not can trade with old stratégy runing's years a go

Thanks MQ4


Thanks Eliot, your help did total difference.
 
bisewski:

sorry but I continue having problems.

Buffer_Old have 200 lines like 2014.02.06,12:35,1.36047,1.36051,1.36052,1.36041 that I save in my .csv file.

The problem now is that only the middle, 100 lines are saved. If I put 500 lines, only 250 are saved. With this change ansii to unicode, I dont understanding where is the problem...

thanks

Is this function use ANSI or UNICODE string ?

                      WriteFile(fWrite, Buffer_Old, szData, BytesWritten, NULL);
How are you checking the number of lines of your CSV files ?
 
angevoyageur:

Is this function use ANSI or UNICODE string ?

How are you checking the number of lines of your CSV files ?
This is my entire code.
#import "kernel32.dll"
   int CreateNamedPipeW(string pipeName,int openMode,int pipeMode,int maxInstances,int outBufferSize,int inBufferSize,int defaultTimeOut,int security);
	//int CreateNamedPipeA(string PipeName,int dwOpenMode,int dwPipeMode,int nMaxInstances,int nOutBufferSize,int nInBufferSize,int nDefaultTimeOut,int lpSecurityAttributes);
	int ConnectNamedPipe(int hPipe,int lpOverlapped);
	int ReadFile(int hPipe, int& inBuffer[],int NumberOfBytesToRead, int& bytesRead[], int lpOverlapped);
	int WriteFile(int hPipe, string sBuffer, int NumberOfBytesToWrite, int& bytesWritten[], int lpOverlapped);
	int FlushFileBuffers(int hPipe);
	int DisconnectNamedPipe(int hPipe);
	int CloseHandle(int hPipe);
	int MulDiv(string X, int N1, int N2);
	//int CreateFileA(string Filename, int AccessMode, int ShareMode, int PassAsZero, int CreationMode, int FlagsAndAttributes, int AlsoPassAsZero);
   int CreateFileW(string name,int desiredAccess,int SharedMode,int security,int creation,int flags,int templateFile);
#import
string pathName="D:\\Forex\\Dados\\"+paridade;
                           string FullName;
                           string Buffer_Old = "vazio";
                           string Buffer_New = NULL;
                           for(int in=0; in<6; in++){ //o in aqui vai me dar uma nova posição no array que contém os dados para guardar e pegar os dados no csv
                               periodo = StrToInteger(StringSpliter(Pairs_Time_Infos[in],"@",0)); //pode ser 1,5,15,60,1440,10080.
                               bars_count = StrToInteger(StringSpliter(Pairs_Time_Infos[in],"@",2)); //200,200,3461,3461,1000,587.
                               FullName=pathName+StringSpliter(Pairs_Time_Infos[in],"@",1); //Um.csv,Cinco.csv,Quinze.csv...
                               RefreshRates();
                               Print(bars_count);
                               //MessageBox(TimeToStr(iTime(paridade,periodo,bars_count), TIME_DATE));
                               
                               if (TimeToStr(iTime(paridade,periodo,bars_count), TIME_DATE) != "1970.01.01"){
                                  //Data;Hora;Open;Close;High;Low
                                  Buffer_Old = TimeToStr(iTime(paridade,periodo,bars_count), TIME_DATE) + "," + TimeToStr(iTime(paridade,periodo,bars_count), TIME_MINUTES)+ "," + DoubleToStr(iOpen(paridade,periodo,bars_count),5) + "," + DoubleToStr(iClose(paridade,periodo,bars_count),5) + "," + DoubleToStr(iHigh(paridade,periodo,bars_count),5) +  "," + DoubleToStr(iLow(paridade,periodo,bars_count),5);
                               }else{
                                  Buffer_Old = "vazio";
                               }
                               
                for(int k=(bars_count-1);k >=0;k--) //vai dar um loop nos candle e ir somando os valores no Buffer_old.
                   {
                      if (TimeToStr(iTime(paridade,periodo,k), TIME_DATE) != "1970.01.01"){
                         if (Buffer_Old == "vazio"){
                            Buffer_Old = TimeToStr(iTime(paridade,periodo,k), TIME_DATE) + "," + TimeToStr(iTime(paridade,periodo,k), TIME_MINUTES)+ "," + DoubleToStr(iOpen(paridade,periodo,k),5) + "," + DoubleToStr(iClose(paridade,periodo,k),5) + "," + DoubleToStr(iHigh(paridade,periodo,k),5) +  "," + DoubleToStr(iLow(paridade,periodo,k),5);
                         }else{
                            Buffer_New =TimeToStr(iTime(paridade,periodo,k), TIME_DATE) + "," + TimeToStr(iTime(paridade,periodo,k), TIME_MINUTES)+ "," + DoubleToStr(iOpen(paridade,periodo,k),5) + "," + DoubleToStr(iClose(paridade,periodo,k),5) + "," + DoubleToStr(iHigh(paridade,periodo,k),5) +  "," + DoubleToStr(iLow(paridade,periodo,k),5);
                            Buffer_Old = Buffer_Old + "\r\n" + Buffer_New;
                            RefreshRates();
                         }
                      }
                   }//Fecha for(int k=0;k<=bars_count;k++)
                
                int ShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
                int fWrite= CreateFileW(FullName, GENERIC_WRITE, ShareMode, 0, CREATE_ALWAYS, 0, 0);
                if (fWrite == INVALID_HANDLE_VALUE)
                   {
                      Print("Unable to open " + FullName + " for writing");
                   }else{
                      int BytesWritten[1] = {0};
                      
                      //Buffer_Old = "Teste de texto";
                      int szData = StringLen(Buffer_Old);
                      //WriteFile(fWrite, MulDiv(Buffer_Old, 1, 1), szData, BytesWritten, NULL);
                      WriteFile(fWrite, Buffer_Old, szData, BytesWritten, NULL);
                      CloseHandle(fWrite);
                      Print(StringSpliter(Pairs_Time_Infos[in],"@",1) + " was saved.");
                   }//Fecha o Else do if (!IsValidFileHandle(fWrite))
                           }//for(int in=0; in<6; in++){
 
Good luck
Reason: