function sleep alternative - page 2

 
paulepanke:

be careful with such a statement. there's always a logical reason to run sleep(). in Tester and even in indicators. 

I didn't say there was no logical reason to use sleep(),  there are many,  I said there was no reason to expect sleep() to work in the Strategy Tester.  Does it work in an Indicator running on a Strategy Tester chart,  I don't know,  maybe it does . . .  does it work in an EA running in the Strategy Tester,  as far as I know, no it doesn't.  Can an EA running in the Strategy Tester be made to pause ?  yes it can.
 
RaptorUK:
Take a look at what TimeSeconds() gives you,  then think about what TimeCurrent() gives you . . .  which one do you need and why ?


Simon,

int TimeSeconds( datetime time)

Returns the amount of seconds elapsed from the beginning of the minute for the specified time.

datetime TimeCurrent( )
Returns the last known server time (time of incoming of the latest quote) as number of seconds elapsed from 00:00 January 1, 1970.


"which one do you need and why ?" - Simon

I'd use both of e'm in concert, cause they go hand-in-hand. - Nathan

TimeSeconds(datetime time) requires a variable placed inside its braces. TimeCurrent() is then placed within these braces, which presents me viable solution. I've done this b4 but didn't understand why returned time values appeared to skip and pause (due to lack of an active tick/ticks).

What say you to this?


Thank you.

 
WHRoeder:

  1. No ticks of any kind are created until you return and it creates the next one and calls your start(). If you compute for 5 minutes and return the volume (tick count) on the next call will be +1. In a live chart, if you compute for 5 minutes, then you will miss 5 minutes of ticks and on the M1 several new bars will have formed.

William,

Thank you for expounding on this subject.

My interpretation of "2." is, when a tick is created, the return function is called. Next the Start() function is called directly after calling the return(0) function which triggers execution of the program once more. Is this interpretation of this portion of 2. correct?


"If you compute for 5 minutes", how can I be sure the EA will compute for five minutes (even if the EA computes for five minutes, I don't believe this will guarantees a tick will be created. Probability of a tick creation is increased)?


Apologies, I am having difficulty reading this:

"If you compute for 5 minutes and return the volume (tick count) on the next call will be +1. In a live chart, if you compute for 5 minutes, then you will miss 5 minutes of ticks and on the M1 several new bars will have formed."


Many thanks for your response.

 
RaptorUK:
I didn't say there was no logical reason to use sleep(),  there are many,  I said there was no reason to expect sleep() to work in the Strategy Tester.  Does it work in an Indicator running on a Strategy Tester chart,  I don't know,  maybe it does . . .  does it work in an EA running in the Strategy Tester,  as far as I know, no it doesn't.  Can an EA running in the Strategy Tester be made to pause ?  yes it can.

Simon,

"Can an EA running in the Strategy Tester be made to pause ?  yes it can."

Could you please express your thoughts regarding this method you'd use to "pause" an EA in the tester?


Thank you

 
  1. The EA returns from start() back to the tester. The tester creates the next tick and calls start(). If the EA does not return there is no next tick. It does not matter how long start() takes to return. The next tick is created when it does.
  2. You can not pause or sleep in the EA in the tester. You can programmatically press the pause button to pause the tester after the EA returns from start.
 

William,

So, a new tick calls the start() function in an EA, yes?

My question to you is this, "Do you know of any other way to call the start() function besides that of a new tick? Possibly a consistent repetitive action to substitute a calling for Start()?"

(I'm thinkin', is there a way to consistently track seconds that don't depend on ticks)


"...The next tick is created when it does."

I believe what you meant to write was, "At the creation of a new tick, Start() is then executed." ;)


So, you say an EA can't be paused or sleep in the tester, yes?


I'll review the link you provided but in the mean-time, can you please expound on this method of "pressing a pause button to pause the tester" after an EA being tested returns from start?

When run in the tester, would this method simulate the performance of the EA being paused for a decided segment of time in "real time" on a live account?


I understand tester has limitations and "work-arounds" must be used for simulation of "real time" performance.


Much gratitude William.


Also, do you mind if I just call you Will? It'd save me a sec. of time every message. Your call.

I like a feature your EA possesses and this is, "I wanted to close all orders before end of the week (market close Friday,) to prevent loss should the market gap over the week end, by passing the SL."

(Clapping hands with joy.) Hahaha! ;) By adding this feature to your EA, you cut unnecessary losses but this is different than what I attempt to do presently. Presently I am trying to track seconds of time consistently without the need of ticks to update the seconds. I wish for a different means to update the Start() function, Understood?


Thank you

 
WhooDoo22:

Presently I am trying to track seconds of time consistently without the need of ticks to update the seconds. I wish for a different means to update the Start() function, Understood?

I suspect that what you are trying to do is a flawed solution to your problem due to lack of understanding.  Why do you need to know the second from one second to the next if price hasn't changed for 30 seconds ? when price changes you get a tick.

 

A point of clarification of what WHRoeder said,  all the ticks are created before the Strategy Tester starts calling/executing them,  they are saved to a .fxt file in tester/history,  the ST calls a first tick and this in turn causes start() to be executed,  the next tick isn't called/used until start() has finished executing,  it's very important to understand this.  Only when start() has finished will the next tick be used so the EA can call start() again.  When the ST is run on full speed it is the speed at which start() runs that governs the speed of the ST,  so a very simple start() function will allow the ST to run very quickly,  a complex start() function will cause the ST to run slower.

 

In a Live/Demo situation if the start() function is very complex and takes a long time to run,  perhaps a few tenths of a second,  it is possible that the next tick can arrive before start() has completed,  in this situation the tick will be missed and will not cause start() to be called . . . . this CANNOT happen with the ST. 

 
WhooDoo22:

Simon,

"Can an EA running in the Strategy Tester be made to pause ?  yes it can."

Could you please express your thoughts regarding this method you'd use to "pause" an EA in the tester?

Sure,  it's not very elegant so I wouldn't suggest anyone use it.  I used a GlobalVariable set and unset by a script,  when the EA in the ST saw the GlobalVariable was set it would sit in a loop continually checking for the GlobalVariable to be unset,  when the script had unset the GlobalVariable the EA exited the loop and it's start() function could terminate.
 
WhooDoo22:

"which one do you need and why ?" - Simon

I'd use both of e'm in concert, cause they go hand-in-hand. - Nathan

TimeSeconds(datetime time) requires a variable placed inside its braces. TimeCurrent() is then placed within these braces, which presents me viable solution. I've done this b4 but didn't understand why returned time values appeared to skip and pause (due to lack of an active tick/ticks).

Lets assume you have 2 events and these events are 10 seconds apart,  what will be the difference between the values returned by  TimeSeconds(datetime time)  for these 2 events ?
 
RaptorUK:

I suspect that what you are trying to do is a flawed solution to your problem due to lack of understanding.  Why do you need to know the second from one second to the next if price hasn't changed for 30 seconds ? when price changes you get a tick.

 

A point of clarification of what WHRoeder said,  all the ticks are created before the Strategy Tester starts calling/executing them,  they are saved to a .fxt file in tester/history,  the ST calls a first tick and this in turn causes start() to be executed,  the next tick isn't called/used until start() has finished executing,  it's very important to understand this.  Only when start() has finished will the next tick be used so the EA can call start() again.  When the ST is run on full speed it is the speed at which start() runs that governs the speed of the ST,  so a very simple start() function will allow the ST to run very quickly,  a complex start() function will cause the ST to run slower.

 

In a Live/Demo situation if the start() function is very complex and takes a long time to run,  perhaps a few tenths of a second,  it is possible that the next tick can arrive before start() has completed,  in this situation the tick will be missed and will not cause start() to be called . . . . this CANNOT happen with the ST. 

Simon,

I suspect that what you are trying to do is a flawed solution to your problem due to lack of understanding.  Why do you need to know the second from one second to the next if price hasn't changed for 30 seconds ? when price changes you get a tick.

I'll admit I do have a lack of understanding, that is why I'm discussing the topic in the MQL4 forum. I wish to save price whenever it changes (i understand how to do this). Also, I understand how to save prices every second consistently on a LIVE/DEMO chart using Sleep(). Objective: I wish to consistently track seconds (without tracking seconds based on creation of ticks) up to max of a minute or less, then reset tracked seconds to zero. I understand why I wish to accomplish this objective. The reason being, I need to test an EA in the tester and can't use Sleep() while testing. What to do right? Gathering options.

Details then hm? ;)

Code a timer (usable in tester) to an EA. This timer counts up from 0-30 or down from or 30-0. While this time is counting up/down, I have a separate vector tracking price action (a very large size vector).

My conditions are such,

If price does travels x points (within 0-30 or 30-0 seconds), make decision.

If price doesn't travel x points (within 0-30 or 30-0 seconds), ArrayInitialize().


What say you to this Simon?


Thank you
Reason: