How to make an EA that trades only at control points?

 

Hi All,

Does anyone know how to make an EA that only trades at control points?

or only trade at every 5 minute? or every 10 minute?

Thank you!

 

It depends on your EA... You can make it only once on openning bar.

https://www.mql5.com/en/forum

 
boostrade:
Hi All,

Does anyone know how to make an EA that only trades at control points?

or only trade at every 5 minute? or every 10 minute?

Thank you!

The prinicpal code stanza for a time filter is like the below:

static datetime last_time = 0;

datetime now = TimeCurrent();

if ( now - last_time < 5 * 60 ) {

// Too close in time since previous trading

return( 0 );

}

last_time = now;

The static variable last_time is a keeper of the last time the execution went past the filter, which here is expressed as a required least time period (at least 5 minutes between now and the last time).

To synchronise with bar opening, you'd use Time[0], the opening time of the bar, rather than TimeCurrent(), which is the time stamp of the "tick", and with the filter condition saying "now-last_time > 0" (i.e., this tick is not just another tick during the same bar as of the previous tick).

You also have to choose where in the code to place the stanza; typically it would be after the management of opened trades, if any, and before the computations that gather information for the decision logic. That is, you tycpially will want the EA to manage open trades on every tick, but not have it waste cycles on other computations. Of course, if your EA uses indicators, then you also need to consider whether the indicators require all ticks, or is happy enough to be invoked at the trading rate.

Reason: