EA opens opposite trade immeadiately
Hi guys,
When my EA closes a trade, sometimes it opens an opposite trade immediately.
Basically, when the 5 period MA cross over the 21 period MA the EA opens a BUY position and vice versa. In certain conditions, when a trade is close, immediately the EA opens the opposite trade because the the 5 period MA was already above and the "cross" was not necessary.
The thing that I want to do is, for example, is that the 5 period MA should really cross the 21 period MA (coming from below), and then open the buy position.
Any new suggestion is welcome
Cheers!
double EMARapidaLastBar = iMA(NULL,0,PeriodoEMARapida,0,1,0,0); double EMALentaLastBar = iMA(NULL,0,PeriodoEMALenta,0,1,0,0); double EMARapidaPreviousBar = iMA(NULL,0,PeriodoEMARapida,0,1,0,1); <----- 1, could be shifted for as many bar past as you wish double EMALentaPreviousBar = iMA(NULL,0,PeriodoEMALenta,0,1,0,1); if( (EMARapidaLastBar > EMALentaLastBar ) && (EMARapidaPreviousBar < EMALentaPreviousBar)) ...
I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
New candle - MQL4 and MetaTrader 4 - MQL4 programming forum
Hi guys,
When my EA closes a trade, sometimes it opens an opposite trade immediately.
Basically, when the 5 period MA cross over the 21 period MA the EA opens a BUY position and vice versa. In certain conditions, when a trade is close, immediately the EA opens the opposite trade because the the 5 period MA was already above and the "cross" was not necessary.
The thing that I want to do is, for example, is that the 5 period MA should really cross the 21 period MA (coming from below), and then open the buy position.
Any new suggestion is welcome
Cheers!