Media with Levels

 
Good evening everyone I'm creating an ea that works on an average with "upper and lower level" now the code is as follows:
     int BuySell=0;
     double SLBuy = 0, TPBuy=0, SLSell = 0, TPSell =0, Vol=0;
     double Ma = iMA(NULL, 0, MediaPeriod, 0, TipoMedia, PRICE_CLOSE, 0);
     bool ticket;
     double  LivelloDownBuy = Ma +  (Level_Negativo_Down_buy * Point());
     double  LivelloUpSell = Ma +  (Level_Positivo_Up_Sell * Point());
     if((OrdiniAperti() == false))
     {
        if(Open[1] < Close[1]  && Close[1] < LivelloDownBuy && Open[1] > LivelloDownBuy)  //buy
           {
            BuySell =1;
            SLBuy = Low[0] - dStopLevel - StopLoss  * p;
            TPBuy =Ma;//Bid + TakeProfit * 10 * Point;
           //Comment("Buy" + "\nentrata: " + NormalizeDouble(Ask,Digits)+ "\nSL Buy" + SLBuy + "\nTake Profit:"+DoubleToString(TPBuy,Digits)+"\nStopLevel " + dStopLevel +"\nCalcola Size " + Vol);

            ticket = OrderSend(Symbol(),OP_BUY,Lotti,Ask,0,SLBuy, TPBuy,"MovingAvarageLevels Buy",MagicNumber,0,Blue);
            if(ticket == false)
               Print("Error modifying order!, error#", GetLastError());
           }
        if(Open[1] >Close[1] && Open[1] >LivelloUpSell && Close[1] < LivelloUpSell)//sell
           {
            BuySell =-1;
            SLSell =High[0]+ dStopLevel+ StopLoss *p; 
            TPSell =Ma;       //Ask - TakeProfit * 10 * Point;

            //Vol=CalcolaSize(OprationRisk,Ask + StopLoss);
            //Comment("Sell" "\nBid: " + Bid + "\nSL Sell" + SLSell+ "\nTP Sell" + TPSell + "\nStopLevel " + dStopLevel +"\nCalcola Size " + Vol+ "\n StopLoss:" +  StopLoss+  "\nPoint" + Point + "\n StopLoss * Point"+  StopLoss * Point);

            ticket = OrderSend(Symbol(),OP_SELL,Lotti,Bid,0,SLSell, TPSell, "MovingAvarageLevels Sell ",MagicNumber,0,Red);
            if(ticket == false)
               Print("Error modifying order!, error#", GetLastError());
           }

     }
     else if(OrdiniAperti() == true)
     {
      TpModify(Ma);
     }

      } 

I can't understand why it only opens sell operations I can't find the error can someone give me a hand?

 

Hello

i assume this 

if(Open[1] < Close[1]  && Close[1] < LivelloDownBuy && Open[1] > LivelloDownBuy)  //buy

must be like this 

if(Open[1] < Close[1]  && Close[1] > LivelloDownBuy && Open[1] < LivelloDownBuy)  //buy

Because :

  • Close[1]>Livello>Open[1]possible but
  • Close[1]<Livello<Open[1] and Open[1]<Close[1]not possible 
 
Thank you now it works