Cross SMA: what is wrong?

 

Hi,

I try to code an EA.

Buy signal: bar n-2 close below my SMA + bar n-1 close above SMA => Open BUY

Sell signal: bar n-2 close above my SMA + bar n-1 close below SMA => Open SELL

Please find below a picture of the signal.

CrossSMA

My code is:

double sma_1 = iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,1);
double sma_2 = iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,2);
if(Close[2]>sma_2 && Close[1]<sma_1){int GetSignalSell = 1;}
if(Close[2]<sma_2 && Close[1]>sma_1){int GetSignalBuy = 1;}            

This code doesn't work fine, what is wrong in this code?

Thank you for your help.

Bruno

 

This code doesn't work fine, what is wrong in this code?

Doesn't work is meaningless. What results do you have ?

 

Hi Alain,

Je suis français.

Find below the open trades of my EA, why some of trades are not take?

trade

 
8tango:

Hi Alain,

Je suis français.

Personne n'est parfait.


Find below the open trades of my EA, why some of trades are not take?


Not possible to say without all the relevant code. The code posted above seems ok.
 
Alain Verleyen:
Personne n'est parfait.

Tu m'étonnes... d'autant plus qu'on à Hollande comme président.... et qu'il veut se représenter aux prochaines présidentielles... on en peut plus... vous ne vous le voulez pas en Belgique ? Vous avez déjà Gérard Depardieu, Arthur, Daniel Auteuil, José Garcia, la famille Meunier, (propriétaire de Carrefour), la famille Mulliez (propriétaire d’Auchan), ainsi que Bernard Darty (fondateur des magasins Darty), etc... vous pouvez aussi prendre Hollande, svp :)

If the code posted above seems ok for you, it mean that there is a mistake into my EA code.

 
   double sma_1 = iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,1);
   double sma_2 = iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,2);
   int GetSignalSell = 0, GetSignalBuy= 0;
   if(Close[2]>sma_2 && Close[1]<sma_1){GetSignalSell = 1;}
   if(Close[2]<sma_2 && Close[1]>sma_1){GetSignalBuy  = 1;} 
  
  if(GetSignalSell==1)
  {
    // sell
  }
  
  if(GetSignalBuy==1)
  {
   //buy
  }  
 
Maybe you have errors on the trades itself
Please see the logs and let us know which error number you may received
Reason: