EA not working

 
Hello lads, could somebody help me? I am totally novice with this.
I am just trying with tester this code and it is not working 100%, not every possible trade is executed. (I hope u can see, that I want to buy/sell when current price reaches min/max). Should I write some other conditions or something, or why it is not doing every trade?

void OnTick()
  {

   openOrder = false;
   
   //monitor open trades & place trailing stops
   for(counter=0;counter<OrdersTotal();counter++)   
   {
      OrderSelect(counter, SELECT_BY_POS, MODE_TRADES);     
      if (OrderMagicNumber() == magicNumber)
      {
         openOrder = true;
      }
   }


   if (!openOrder && Time[0] != previousSignal)
   {
      generateSignals();
      
      if (buySignal)
         placeBuy();
      else if (sellSignal)
         placeSell();
         
      previousSignal = Time[0];
   }

   
  }
//+------------------------------------------------------------------+


void generateSignals()
{
   buySignal = false;
   sellSignal = false;   
   
   min = NormalizeDouble(iLow(NULL,0,1),Digits);
   max = NormalizeDouble(iHigh(NULL,0,1),Digits);
   current = NormalizeDouble(MarketInfo(NULL,MODE_BID),Digits);
   
   if (min == current)
      buySignal = true;
   else if (max == current)
      sellSignal = true;
}

void placeBuy()
{
   RefreshRates();            
   ticket=OrderSend(Symbol(),OP_BUY,lots,Ask,slippage,NormalizeDouble(Bid - SL,Digits),NormalizeDouble(Ask + TP,Digits),"buy",magicNumber,0,Green);  
   if(ticket<0)
   {
      Print("BUY failed with error #",GetLastError()," at ",Ask);
      return;
   }
}

void placeSell()
{
   RefreshRates();            
   ticket=OrderSend(Symbol(),OP_SELL,lots,Bid,slippage,NormalizeDouble(Ask + SL,Digits),NormalizeDouble(Bid - TP,Digits),"sell",magicNumber,0,Red);  
   if(ticket<0)
   {
      Print("SELL failed with error #",GetLastError()," at ",Bid);
      return;
   }
 
matolfc:
Hello lads, could somebody help me? I am totally novice with this.
I am just trying with tester this code and it is not working 100%, not every possible trade is executed. (I hope u can see, that I want to buy/sell when current price reaches min/max). Should I write some other conditions or something, or why it is not doing every trade?


Bid or Ask may not be exactly equal to the trigger price and may just jump over it.

So don't use

if (min == current)

use

if (min <= current)

or

if (min - current >=0 && min - current < x)
 
GumRai: Bid or Ask may not be exactly equal to the trigger price and may just jump over it.
Exactly. The == operand. - MQL4 forum
Reason: