While Loop In Strategy Tester, Timer

 
Hello. Because the default timer is not available in mql4 so I decided to write my own timer. To do so I made one second while cycle. Code Shown below
void countUp()
{
int CurrentSecond;
if(TimeSeconds(TimeLocal()) == 59)
CurrentSecond = -1;
else
CurrentSecond = TimeSeconds(TimeLocal());
while(true)
{
int localSeconds = TimeSeconds(TimeLocal());
if(localSeconds == (CurrentSecond + 1))
{
Alert("Passed loop After 1" + " " + count);
countUp();
}
}
}


My problem is that In While Loop Tester stacks. I can't get in if statement.

Can anyone help me?

I am writing this to make my Sleep() function because sleep() doesn't work in strategy tester. Can someone give me advice what to do?
 
sandrika_ :
Hello. Because the default timer is not available in mql4 so I decided to write my own timer. To do so I made one second while cycle. Code Shown below
<CODE REMOVED>

My problem is that In While Loop Tester stacks. I can't get in if statement.

Can anyone help me?

I am writing this to make my Sleep() function because sleep() doesn't work in strategy tester. Can someone give me advice what to do?

Firstly . . .

Please read some other posts before posting . . .

Please edit your post . . . please use the SRC button to post code: How to use the SRC button.

 

Secondly . . .

There is no point trying to do what you are doing. If you wait the time in the Strategy Tester will not pass, all you will end up doing is making your CPU warm for no good reason.

Why do you need to Sleep in the Strategy Tester ?

 
Thank you for your reply. You can't see the point, I didn't asked that. I didn't provided whole code. In a live mode This code works good. with no CPU warm. I just want to know why it doesn't work in Strategy tester.

Why do you need to Sleep in the Strategy Tester ?

Because I need timer, After some time to do some code, I can use sleep() in live mode but what to do in Strategy Tester
 
sandrika_ :
Thank you for your reply. You can't see the point, I didn't asked that. I didn't provided whole code. In a live mode This code works good. with no CPU warm. I just want to know why it doesn't work in Strategy tester.Because I need timer, After some time to do some code, I can use sleep() in live mode but what to do in Strategy Tester
It's not a good idea to use Sleep() as a timer, use it to pause and then retry but don't use it as a timer . . . instead use time, so if you want to pause for at least 20 seconds use a datetime variable to record the current time ( TimeCurrent() ) and then for each tick check to see if TimeCurrent() is equal or greater than the saved time + 20
 
sandrika_ :
Thank you for your reply. You can't see the point, I didn't asked that. I didn't provided whole code. In a live mode This code works good. with no CPU warm. I just want to know why it doesn't work in Strategy tester.

In the Strategy Tester TimeLocal() == TimeCurrent() and if you constantly loop there are no ticks so time does not change . . .

TimeLocal() "Note: At the testing, local time is modelled and is the same as the modelled last known server time."

 

Until you return from start(), nothing is changing. Return from start, on the next call, reevaluate your conditions.

TimeLocal is irrelevant in the tester. You should need to use it at all. TimeCurrent() is the broker's (tester's) time.

 
WHRoeder :

Until you return from start(), nothing is changing. Return from start, on the next call, reevaluate your conditions.

TimeLocal is irrelevant in the tester. You should need to use it at all. TimeCurrent() is the broker's (tester's) time.


I don't use start. I use Init. So problem is that stack is full in loop. So now I have no idea How to simulate sleep() function in strategy tester. But loop was in cycle only 1 second and it is enought to full up stack. Need advice, I don't want to use start(), I want to do some code in every some time
 
Can I Empty Stack ? Set null or something?
 
sandrika_ :
Can I Empty Stack ? Set null or something?
It won't help . . . to make time pass in the Strategy Tester you MUST use start() . . . the next tick is not used until start() returns, if start is never called it never returns so the next tick is never used . . . time does not advance.
 
RaptorUK :
It won't help . . . to make time pass in the Strategy Tester you MUST use start() . . . the next tick is not used until start() returns, if start is never called it never returns so the next tick is never used . . . time does not advance.


Ok I understand that in strategy tester the next tick is not used until start() returns. But I just can't get why it works in Live mode and not in tester. OK i will use start, I didn't want to use start() because I can't control its call back. But in tester Ok I will use start()
Reason: