cant count orderstotal in EA

 

Have been coping together simple stochastic buy/sell code.

Problem is it wont count positions, it states like it is always 0.

void OnTick ()
        {
        // We create an empty string for the signal
        string signal="";


   // Define the EA
   double K0=iStochastic(_Symbol,_Period,14,3,3,MODE_SMA,0,MODE_MAIN,0);
   double D0=iStochastic(_Symbol,_Period,14,3,3,MODE_SMA,0,MODE_SIGNAL,0);
   double K1=iStochastic(_Symbol,_Period,14,3,3,MODE_SMA,0,MODE_MAIN,1);
   double D1=iStochastic(_Symbol,_Period,14,3,3,MODE_SMA,0,MODE_SIGNAL,1);
   
   

   
   
   
   
   int magicNum = 1;
   int cntBuyOrders=0;
   int cntSellOrders=0;
   for(int cnt=0;cnt<OrdersTotal();cnt++){
   bool isSelected = OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
   if (OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderMagicNumber()==magicNum){
      cntBuyOrders++;
   }
   if (OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==magicNum){
      cntSellOrders++;
   }
}
   
  
  


   // sell signal
      if ((K0 > 75)&&(D0 > 75))
   // if ((D0 > K0)&&(D1 < K1))
      if ((K0 - D0 < 5)||(D0 - K0 < 5))
   
      
      {
         signal="sell";
      }
     
    
   // buy signal
      if ((K0 < 25)&&(D0 < 25))
   // if ((D0 < K0)&&(D1 > K1)) 
      if ((K0 - D0 < 5)||(D0 - K0 < 5))
      {
         signal="buy";
      }
     
     // Buy some
     if (signal=="buy" && cntBuyOrders<1)
     OrderSend (_Symbol,OP_BUY,0.02,Ask,3,0,Ask+150*_Point,NULL,0,0,Green);
     
     // Sell some
     if (signal=="sell" && cntSellOrders<1)
     OrderSend (_Symbol,OP_SELL,0.02,Bid,3,0,Bid-150*_Point,NULL,0,0,Red);
     
     
     // Chart output for the signal
     Comment ("The current signal, buyordercount, sellordercount is:",signal, cntBuyOrders, cntSellOrders);

     }

 
Please edit your post and use the code button (Alt+S) when pasting code.
EDIT your original post, please do not just post the code correctly in a new post.