clarificaiton on sleep() function

 

I need clarification on the sleep() function. First, suppose I set the sleep function for 10 seconds or Sleep(10000). Does this mean that the ea is suspended for 10 seconds regardless of how many ticks come in on the chart or is the sleep function dependent on ticks coming in to keep a "clock" ticking down? Second, can I have the sleep function imbedded within an if construction or does it have to be outside of the if?

 
As far as I'm aware the Sleep function just stops your code for the 10 seconds then continues on with the rest of the code till it comes to the end of the start function. Ticks only set of the start() if it's not all ready started so all new ticks won't reset it.
 
forestmyopia:

I need clarification on the sleep() function. First, suppose I set the sleep function for 10 seconds or Sleep(10000). Does this mean that the ea is suspended for 10 seconds regardless of how many ticks come in on the chart or is the sleep function dependent on ticks coming in to keep a "clock" ticking down? Second, can I have the sleep function imbedded within an if construction or does it have to be outside of the if?

The Documentation tells you . . . Sleep()

"The Sleep() function suspends execution of the current expert within the specified interval." it doesn't rely on ticks . . . you use it as you would do any other Function . . . it returns nothing (void)

 
RaptorUK:

The Documentation tells you . . . Sleep()

"The Sleep() function suspends execution of the current expert within the specified interval." it doesn't rely on ticks . . . you use it as you would do any other Function . . . it returns nothing (void)


Thanks for the clarification. I am now implenting the sleep function to filter out an inherent problem associated with all moving average crossover systems. I have a very successful system that uses the crossover of two ma's to enter a trade, but I use the same two ma's to exit the trade within a window of time to reduce my stop losses. Of course this causes a problem unless an adequate filter is implemented.

For example, right at the exact point where a faster ma crosses up above a slower ma, a long trade is triggered, but the faster ma can easily cross down at this point, closing out the trade. You can expect this "jitter" to always occur at the crossover point. The way around this is using the sleep function. After the trade is entered, I now invoke the sleep function for a period of time before the monitor crossover down function is entered. This allows the faster ma to distance itself from the noise region before any crossover down monitoring is invoked.

If a "real" crossover down occurs after this rest period, then this means the market is truly in whipsaw, and no more trades are entered at this time. This method actually reduces my losses. Typically, a 1 lot trade using a traditional 30 point stop loss would incur a 300.00 dollar loss if the trade goes against me. However, using this time delay method, I can typically incur only a 150.00 loss. I use a 3 and 20 simple ma on the 1 hour chart.

After another sufficient amount of time if the trade is trending in the right direction, I switch over to another pair of ma's with their own unique biasing applied that keeps the trade in the trend as long as it can. I get incredible, consistent results with this method because the reward/loss ratio and win probability is high, giving a great positive expectation value.

 
forestmyopia:


Thanks for the clarification. I am now implenting the sleep function to filter out an inherent problem associated with all moving average crossover systems. I have a very successful system that uses the crossover of two ma's to enter a trade, but I use the same two ma's to exit the trade within a window of time to reduce my stop losses. Of course this causes a problem unless an adequate filter is implemented.

Are you perhaps using bar 0 of the indicator to make the entry/exit decision? What people seem to do is to use bar 1 on the first tick of a new bar so that all the up and down chatter during the bar is eliminated. Only closed bars represent signals that you would see on a historical chart.
 
dabbler:
Are you perhaps using bar 0 of the indicator to make the entry/exit decision? What people seem to do is to use bar 1 on the first tick of a new bar so that all the up and down chatter during the bar is eliminated. Only closed bars represent signals that you would see on a historical chart.

No, I'll have to look into it. Thanks for the suggestion.
 
https://www.mql5.com/en/forum/127105
forestmyopia:

I need clarification on the sleep() function. First, suppose I set the sleep function for 10 seconds or Sleep(10000). Does this mean that the ea is suspended for 10 seconds regardless of how many ticks come in on the chart or is the sleep function dependent on ticks coming in to keep a "clock" ticking down? Second, can I have the sleep function imbedded within an if construction or does it have to be outside of the if?



 

Don't dredge up old posts. Thread start date 2012.02.17 04:20 . I don't think the OP is still waiting two years.

 
WHRoeder:

Don't dredge up old posts. Thread start date 2012.02.17 04:20 . I don't think the OP is still waiting two years.


ok,


I could not find any good solution.
But it works.

Reason: