My EA is trigger happy

maylortade

Active Trader
May 13, 2010
1
0
32
Hi there,

My EA pulls the trigger multiple times on the same bar. As soon as a trade closes, and the buy/sell signal is till there, it opens another trade.

Is there anyway to postpone the next trade, or to ensure it doesn't trade again until at least another bar has opened? How can I have it check how long it has been since the last trade closed

Your help will be greatly appreciated!
MT
 

Enivid

Administrator
Staff member
Nov 30, 2008
18,616
1,366
144
Odesa
www.earnforex.com
It's quite easy to do. You just have to add a code to check if the current number of bars is greater than the previous number of bars. Then you can continue trading if there were new bars and return if the amount of bars is the same. In MQL4 it would look like this:

MQL5:
	if (LastBars == Bars) return(0);
	else LastBars = Bars;

Bars is a system variable for the amount of bars in the charts. LastBars should be declared as a global variable (int).

In MQL5 you just have to use Bars() function instead of the Bars variable:

MQL5:
	if (LastBars == Bars(_Symbol, _Period)) return;
	else LastBars = Bars(_Symbol, _Period);

Hope that helps.
 
Last edited: