Download MetaTrader 5

Cross SMA: what is wrong?

To add comments, please log in or register
Sell products right in MetaTrader. Millions of traders are waiting for this!
8tango
107
8tango 2016.09.08 10:13 

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

Alain Verleyen
Moderator
30722
Alain Verleyen 2016.09.08 16:29  

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

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

8tango
107
8tango 2016.09.09 09:25  

Hi Alain,

Je suis français.

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

trade

Alain Verleyen
Moderator
30722
Alain Verleyen 2016.09.09 09:41  
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.
8tango
107
8tango 2016.09.09 11:39  
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.

Ziheng Zhuang
1521
Ziheng Zhuang 2016.09.10 14:11  
   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
  }  
Mohammad Soubra
24928
Mohammad Soubra 2016.09.13 09:22  
Maybe you have errors on the trades itself
Please see the logs and let us know which error number you may received
To add comments, please log in or register