SalgadoCapital:
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)) ...
SalgadoCapital: 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),
Don't look at bar zero, you'll get multiple cross/uncross as the bar forms.
For a new bar test, Bars is unreliable (a refresh/reconnect can change
number of bars on chart,) volume is unreliable (miss ticks,) Price is unreliable
(duplicate prices and The == operand. - MQL4 and MetaTrader 4 -
MQL4 programming forum.) Always use time.
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
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
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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!