help writing a file

 

hello,

i"m learning the mql4 for a while. and i just cant understand what is wronge with my code. trying to write a file with this code :

 

extern string FileName = "testfile12.csv";
extern double candle_open_new,candle_open;
int init()
  {
//----
  candle_open   =  iOpen(NULL,0,1);  
//----
   return(0);
  }
int start()
  {
//----

   candle_open_new   =  iOpen(NULL,0,1);
   
   if ( candle_open_new != candle_open )
      {
         Alert(candle_open_new, candle_open);
         int handle;
         datetime timenow = TimeCurrent();
         handle = FileOpen(FileName, FILE_CSV | FILE_READ | FILE_WRITE, ';');
         Alert (handle);
         if (handle >0)
            {
            FileWrite( handle, Close[0], Open[0], High[0], Low[0], TimeToStr(timenow));
            FileClose( handle);
            }
      candle_open = candle_open_new;
      } 
      
//----
   return(0);
  }

the handle value is 1 when i"m testing it in the metatrder. but there is no file in the /tester/file

 thanks for the help.

idan 

Files:
array.mq4  2 kb
 
idanc15:

hello,

i"m learning the mql4 for a while. and i just cant understand what is wronge with my code. trying to write a file with this code :

 

the handle value is 1 when i"m testing it in the metatrder. but there is no file in the /tester/file

 thanks for the help.

idan 

Are you running this in the Strategy Tester or live/demo ?  is it an UAC issue ?

You should read this thread also:  Can price != price ?

 

hey

 

i"m running it in the strategy tester.

 i just run it as a expert and the result is the same-  handle = 1 but no file.

if in UAC you mean firewall- so i allowed the MT4 in the windows firewall  (i dont have other one)

 

is there some thing wronge with the code?

 

thanks 

 
idanc15:

hey

 

i"m running it in the strategy tester.

 i just run it as a expert and the result is the same-  handle = 1 but no file.

if in UAC you mean firewall- so i allowed the MT4 in the windows firewall  (i dont have other one) 

Nope,  search for UAC on this site,  search box is in the top right of this page . . .
 

hey

 

i disabled the UAC in my computer - still no file

 

thanks 

 
idanc15:

hey

i disabled the UAC in my computer - still no file

I ran your code . . .  note where I have MT4 installed = no UAC issues.

 

 
idanc15:

hey

 

i disabled the UAC in my computer - still no file

 

thanks 

If UAC was enabled when you install your platform that changes nothing, the files are created outside Program Files. In a subdirectory of your user account.

 

hey

i just tryed it on other computer with XP and it runing good

 

i wil try to find the problam in the windows 7 computer

 

thanks for the help 

 
idanc15:

hey

i just tryed it on other computer with XP and it runing good

i wil try to find the problam in the windows 7 computer

Re-install MT4 in a folder that is not Program Files.
 
  1. Don't install in \program files*. Avoid the problems
  2. candle_open_new   =  iOpen(NULL,0,1);
       if ( candle_open_new != candle_open )
    Unreliable, two candles can always have the same open price, just as a candle can have the same open and close price (Doji.) Volume is unreliable, you can miss ticks. Bars is unreliable - max bars in chart. Always use time
    if (candle_open != Time[0]){ candle_open = Time[0]; ...
  3. Why are you using the functions iOpen(NULL,0,x) instead of the simpler, faster, predefined variables Open[x]?
  4. i wil try to find the problam in the windows 7 computer
    We've told you the solution to your problam. #1.
 

thanks for the advise. i will try it and i will use it 

 just want to ask  one more thing about writing a file. 

is it possible to enter each value to a single column ( i mean in the exel)

now i get it all toghter in a single column

 

WHRoeder:

  1. We've told you the solution to your problam. #1.

  1. Don't install in \program files*. Avoid the problems
  2. Unreliable, two candles can always have the same open price, just as a candle can have the same open and close price (Doji.) Volume is unreliable, you can miss ticks. Bars is unreliable - max bars in chart. Always use time
  3. Why are you using the functions iOpen(NULL,0,x) instead of the simpler, faster, predefined variables Open[x]?
  4. i wil try to find the problam in the windows 7 computer