Small question - Moving Average

 

Hi all,

For some reason this formula is not working....

I know there is problem with the way I have set the trading conditions, but really cant understand what's wrong there.

int start()
  {

int Moving21, Moving21P; 
bool BuySignal, SellSignal;
Moving21=iMA(NULL,PERIOD_M15,21,0,MODE_SMA,PRICE_CLOSE,1);
Moving21P=iMA(NULL,PERIOD_M15,21,0,MODE_SMA,PRICE_CLOSE,2);
if(Moving21P<Moving21 && Moving21P>Moving21)BuySignal=True; else BuySignal=false; if(Moving21>PMoving21 && Moving21<PMoving21)SellSignal=True; else SellSignal=false;
if(BuySignal==True)
OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"MA",12345,0,Green);
   
if(SellSignal==True)
OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"MA",12345,0,Red);

   return(0);
}

When i use instead the following conditions it work....

if(Close[1]>Moving21)BuySignal=True;
else BuySignal=false;

if(Close[1]<Moving21)SellSignal=True;
else SellSignal=false;

But that's not produce the results I want. Why this work and not the original formula above ???

Can anyone help ?

Many Thx.

MovingAverage

 

if(Moving21P<Moving21 && Moving21P>Moving21)BuySignal=True;

What does that line say?

if(Moving21>PMoving21 && Moving21<PMoving21)SellSignal=True;
This one too...

 
phy wrote >>

if(Moving21P<Moving21 && Moving21P>Moving21)BuySignal=True;

What does that line say?

if(Moving21>PMoving21 && Moving21<PMoving21)SellSignal=True;
This one too...

You are right those lines does not mean anything at all....

In fact I am trying to reproduce that:

if(Open[2]<Moving21P && Open[1]>Moving21)BuySignal=True;
else BuySignal=false;

if(Open[2]>Moving21P && Open[1]<Moving21)SellSignal=True;
else SellSignal=false;

if Open price shift 2 is below MA shift 2, and Open price shift 1 is above MA shift 1 --> Open long position

if Open price shift 2 is above MA shift 2, and Open price shift 1 is below MA shift 1 --> Open short position

Is there something I need to correct here ? The EA does not trade with this code.

Thx,

MovingAverage

 

Your correction looks ok.

Reason: