Script with loop infinitive, How Can I get out?

 

Hello Mrs...

I use the fallow code for create an loop. This loop save in .csv file any information.

But when I finish or remove this script, all information in my .csv file are erased...

I imagine that is happens because my loop is infinite. So, when I remove this script I generate an error...I dont know..

Is this can be my problem?

If yes, I imagine if is possible put un button or any option for when I click or execute, my loop are break and my script unlodad correctly.

If my code is generated withou this infinite loop, my file is save corretly and I dont have problem...

Thanks..

int start()
{
//----
int bars_count=100;
int j;
for (j=1; j>0; j++) //THIS LOOP IS INFINITIVE
{
Sleep(60000); //IN EACH 1 MINUTE, THE FALLOW CODE IS EXECUTED
int handle1=FileOpen("101.csv",FILE_CSV|FILE_WRITE, ",");
for(int i=0;i<bars_count;i++)
FileWrite(handle1, TimeToStr(Time[i], TIME_DATE),TimeToStr(Time[i], TIME_MINUTES),Open[i],Close[i],High[i], Low[i]);
FileClose(handle1);
}
//----
return(0);
}

 


in this video, the autor speak that the script are perfectly for run one time, no loops...

https://www.youtube.com/watch?v=fNrLT8Qhb_o


So, How I can make my function withou scripts?


Thanks
 

The infinite loop is not causing the file to be erased(well technically not). Everytime you open the file, it starts writing at the start unless you tell it otherwise. Try adding this line :-

FileSeek(handle1, 0, SEEK_END);
 

Your open command does not include FILE_READ

Each time you open it it is opened with zero length

Check the FileOpen() documentation

If you want to append the existing data after opening the file to read and write, then use FileSeek() as above.

 
phy:

Your open command does not include FILE_READ

Each time you open it it is opened with zero length

Check the FileOpen() documentation

If you want to append the existing data after opening the file to read and write, then use FileSeek() as above.


Hello phy.

But my problem isn't open file with zero length. I always write new bytes...The olds, is deleted...

The line code for Write in my file, is function ok. My problem is how I can exit my script without ths, erase all information in my .csv file.

If I make my code not infinitive, only write bytes and unload, the function is perfectly...

But if I make this infinitive loop, where I have problem...


EDIT:

Is possible in mql4 to create an button, an rigth menu, anything, for I interact my script? For exemple, I can to create an If in my loop. If the boolean Test is True, so exit the loop. If boolean Test igual as False, so the loop continue...But How Can I interact with my script for I can change this boolean?

 

Ok, thanks for your attention and help for me.


My solution is line:

if(IsStopped()==true) break;

Reason: