Blog archive

MT4 Trade Only During the Last Minute of a Candle

What if you only wanted your EA to trade the last minute of a candle? Why would you want to? I tend to use this on long (in pips) candles when they are breaking out of a channel. A lot of times when a trend is switching directions, your EA will get in just outside the switch, especially if it's a scalper. The following acts as a good filter for that.

Create a variable that you can modify for the exact amount of minutes:

extern int tradeTimeLastMinutes = 1;

Somewhere before your  order execution logic, put the following calculation:

int tradeTime = Time[0]+((Period()-tradeTimeLastMinutes)*60);

Then somewhere in your conditions for order execution logic, put the following condition:

TimeCurrent() > tradeTime

Time[0] is the opening time of the current candle (in seconds). Period() is what period your're in expressed as a int. Therefore, if you're using a 15 minute period. It's 15-1, multiplied by 60, gives us 840 seconds added to the time of the last candle open. TimeCurrent() is expressed in seconds too, so our trade logic is basically comparing seconds and not opening a trade until after tradeTime.

Leave your comment