EA won't open a trade

 

Hi MQL community

Admittedly I am new to coding but have written a few successful codes but I am having trouble with this simple eaI am trying to write.

The ea will open a buy order when a spinning to candle appears and this is tied in with an alert. I have written in the code to only allow one open order at a time and this will stop duplicate orders. As you can imagine, this ea is only a small section of a larger ea I am still trying to write. 

Problem: The ea will occasionally open an order with a single alert but most other times I seems to alert with every tick but not open a single trade. 


What have I done wrong? My ea is below. 


Many thanks in advance!


//+-------------------------------------------------------------------------------------------------------------------------------------------------

extern double buystoploss   =-10;                                                             //SL for a buy open order

extern double buytakeprofit =10;                                                             //ТР for a buy opened order

extern int    buycount   =0;                                                              //Number of buy market orders placed within 24 hours

extern int    sellcount  =0;                                                              //Number of sell market orders placed within 24 hours                

//+------------------------------------------------------------------------------------------------------------------------------------------------

int start()

{

   int 

   spinningtop         =  33,                                                                       //percentage parameter of spinning candle top

   currentorder        =  OrdersTotal();                                                            //total number of open market orders 

   double 

   totalcandlelength   =  MathAbs((iHigh("EURUSD",PERIOD_M1,1))-((iLow("EURUSD",PERIOD_M1,1)))),     //total length of a single individual candle

   candlelength        =  MathAbs((iOpen("EURUSD",PERIOD_M1,1))-((iClose("EURUSD",PERIOD_M1,1)))),   //length of open and close position of each candle

   price               =  Ask;                                                                       //Price of market entry

   

//+------------------------------------------------------------------------------------------------------------------------------------------------

 if (currentorder<1 && (((candlelength/totalcandlelength)*100) <= spinningtop))                   //Limit market order at any time to n=1 & implement 33% rule                  

      {

      OrderSend("EURUSD",OP_BUY,1,Ask,10,buystoploss,buytakeprofit,NULL,0,0,clrGreen);

      buycount++;

      Alert("Buy Order No.",buycount,"  Price=",price);  

      }

return;


Reason: