Your code if( (iMA(Symbol(),0,2,1,MODE_SMA,PRICE_CLOSE,0) > iMA(Symbol(),0,10,1,MODE_SMA,PRICE_CLOSE,0)if a > b && b < a will never be true.
&& (iMA(Symbol(),0,2,0,MODE_SMA,PRICE_CLOSE,0) < iMA(Symbol(),0,10,0,MODE_SMA,PRICE_CLOSE,0) ))){
SELL(Symbol(),1,0,0,0,"sell 1") ;
}Write self-documenting code. double fastCur = iMA(Symbol(),0,2,1,MODE_SMA,PRICE_CLOSE,0);
double fastPre = iMA(Symbol(),0,2,1,MODE_SMA,PRICE_CLOSE,1);
double slowCur = iMA(Symbol(),0,10,1,MODE_SMA,PRICE_CLOSE,0)
double slowPre = iMA(Symbol(),0,10,1,MODE_SMA,PRICE_CLOSE,1)
bool isUp = fastCur > slowCur;
bool wasUp = fastPre > slowPre;
bool cross = isUp && !wasUp;
if(cross){
SELL(Symbol(),1,0,0,0,"sell 1") ;
}
if a > b && b < a will never be true.
huge mistake, thank you
I realized that this way I'm opening trades in the wrong bar, I don't want to work with open bars but closed bars only
should I add 1 to the shifts?
double fastCur = iMA(Symbol(),0,2,1,MODE_SMA,PRICE_CLOSE,1);
double fastPre = iMA(Symbol(),0,2,1,MODE_SMA,PRICE_CLOSE,2);
double slowCur = iMA(Symbol(),0,10,1,MODE_SMA,PRICE_CLOSE,1)
double slowPre = iMA(Symbol(),0,10,1,MODE_SMA,PRICE_CLOSE,2)
bool isUp = fastCur > slowCur;
bool wasUp = fastPre > slowPre;
bool cross = isUp && !wasUp;
if(cross){
SELL(Symbol(),1,0,0,0,"sell 1") ;
}
double fastPre = iMA(Symbol(),0,2,1,MODE_SMA,PRICE_CLOSE,2);
double slowCur = iMA(Symbol(),0,10,1,MODE_SMA,PRICE_CLOSE,1)
double slowPre = iMA(Symbol(),0,10,1,MODE_SMA,PRICE_CLOSE,2)
bool isUp = fastCur > slowCur;
bool wasUp = fastPre > slowPre;
bool cross = isUp && !wasUp;
if(cross){
SELL(Symbol(),1,0,0,0,"sell 1") ;
}
Exactly what you said you wanted.
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
I want to build an EA that sell 1 lot when I have a moving average crossover, no take profit or stop loss
First I check if there were no crossover in the previous bar
( iMA(Symbol(),0,2,1,MODE_SMA,PRICE_CLOSE,0) > iMA(Symbol(),0,10,1,MODE_SMA,PRICE_CLOSE,0)
then if there is a crossover
iMA(Symbol(),0,2,0,MODE_SMA,PRICE_CLOSE,0) < iMA(Symbol(),0,10,0,MODE_SMA,PRICE_CLOSE,0)
Are this conditions good?
if ( ( iMA(Symbol(),0,2,1,MODE_SMA,PRICE_CLOSE,0) > iMA(Symbol(),0,10,1,MODE_SMA,PRICE_CLOSE,0) && ( iMA(Symbol(),0,2,0,MODE_SMA,PRICE_CLOSE,0) < iMA(Symbol(),0,10,0,MODE_SMA,PRICE_CLOSE,0) )))
{ SELL(Symbol(),1,0,0,0,"sell 1") ;}
To work only with completed bars is this the way?
thank you
int PreviousBarCount = 0;
extern bool CompletedBars = true;
-------------------------------------
// Check for completed bars
if ((PreviousBarCount==Bars) && CompletedBars)