Download MetaTrader 5
To add comments, please log in or register
Having questions? Ask them on the Forum - traders will help you!
FightWithMarket
120
FightWithMarket 2015.10.26 11:50 

I am not good in programming. I know that start() is work on every new incoming tick, I would like to have Task A work every new tick, Task B work every 1 second, both task run in parallel. How should I code?

 

Below my code structure, Task A also work every second which is not what I want. I want to make Task B an independent loop. Thanks 

 

int start()

 Task A;

 while(1==1)

       {   Task B;

 Sleep (1000);

         }

Keith Watford
Moderator
7887
Keith Watford 2015.10.26 11:53  
Read the documentation for OnTimer, that should give you some clues
FightWithMarket
120
FightWithMarket 2015.10.26 11:53  
GumRai:
Read the documentation for OnTimer, that should give you some clues
OK. will try~ Thanks GumRai!
FightWithMarket
120
FightWithMarket 2015.10.26 12:12  
GumRai:
Read the documentation for OnTimer, that should give you some clues

Hi GumRai,

 

OK. I get it.

 

1 EA only can set 1 timer? Possible to set multiple timer in 1 EA?

Thanks 

Keith Watford
Moderator
7887
Keith Watford 2015.10.26 12:30  

There can only be 1 timer set at a time.

It does not have to be set in init.

For less than 1 second, EventSetMillisecondTimer.

You say that you are not good in programming, I would suggest that you stick to a single Timer event in your EA until you are more confident. 

FightWithMarket
120
FightWithMarket 2015.10.27 02:35  
GumRai:

There can only be 1 timer set at a time.

It does not have to be set in init.

For less than 1 second, EventSetMillisecondTimer.

You say that you are not good in programming, I would suggest that you stick to a single Timer event in your EA until you are more confident. 

 Thanks GumRai. I've 1 last question.

 

I've read FileReadString doc, but I scratch my head  to display text using comment or print.


https://docs.mql4.com/files/filereadstring


 My code:

 

 file_handle=FileOpen( "myfile.txt",FILE_READ);
 string mytext;
 mytext= FileReadString(file_handle);
 Comment(" My text is " +mytext);   //This is where I stuck....

 

PrintFormat(mytext) can work, but I not able to put this in comment.


I try Stringformat as well but return (NULL), means keep print (NULL). 

Kindly advice. Thanks 

Keith Watford
Moderator
7887
Keith Watford 2015.10.27 11:43  

Please try to avoid the large gaps between lines and in your code. It doesn't make it nice to read.

Please use the SRC button when posting code

 

Your code should work as far as I can see.

Do you get " My text is " printed in your comment? 

If so, then the first line in the file is probably blank

If the comment is different, maybe you over-write the Comment elsewhere in the code, or another indicator or EA is over-writing it. 

FightWithMarket
120
FightWithMarket 2015.10.27 12:26  

Yes, I able to get "My text is" but after that the mytext string read from text file is not showing.

 I just wrote OK in the first line of the text file. 

If I use Stringformat("My text is %s",mytext), it will show My text is (NULL).

Keith Watford
Moderator
7887
Keith Watford 2015.10.27 12:59  

Possibly your file is not in the correct folder

   ResetLastError();
   int file_handle=FileOpen("myfile.txt",FILE_READ);
   if(file_handle==INVALID_HANDLE)
      Print("Error opening file, Error- ",GetLastError());
   string mytext;
   mytext=FileReadString(file_handle);
   Comment(" My text is "+mytext);   //This is where I stuck....

 

 Check for errors

FightWithMarket
120
FightWithMarket 2015.10.27 13:22  
GumRai:

Possibly your file is not in the correct folder

 

 Check for errors

I get error 5004.

5004

ERR_FILE_CANNOT_OPEN

Cannot open file

 

Solved now by adding    FileClose(file_handle);

 Thanks GumRai so much! 

/
To add comments, please log in or register