why my EA doesnt open orders

 

please help me im stuck with my EA i will give you my all model if you help me

//+------------------------------------------------------------------+
//|                                                        SHAUL.mq4 |
//|                                                        |
//|                                                http://ftsa.co.il |
//+------------------------------------------------------------------+
#property link      ""
#include <stderror.mqh>
#include <stdlib.mqh>
#define IDLE 0
#define SIGNAL_BUY   1
#define SIGNAL_SELL  2
#define SIGNAL_TRBUY 3
#define SIGNAL_TRSELL 4
#define SIGNAL_P 5
#define SIGNAL_L 6
bool trade=false;
int tickets=0;
int ticketb=0;
int Order = IDLE;
int Barw;
int barc;
double BOLH;
double BOLL;

extern int TP=120;    //take profit
extern int SL=60;      //stop loss
extern double lotSize=0.1;
extern double DEV=3.0;
extern int Per=12;
extern int Bar_wait=10;
extern int MagicNumber=7272;



//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
{
//----
   if (OrdersTotal()==0)   
   {trade=false;}

   if (OrdersTotal()!=0)
   {
       for (int i=1; i<=OrdersTotal(); i++)       //Cycle for all orders..
      {                                        //displayed in the terminal
       if(OrderSelect(i-1,SELECT_BY_POS)==true)//If there is the next one
        {                                     
          if (OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
          {
           trade=true;
           
               break;
            }
          else {trade=false;}
          }
        } 
     
   } 


//////////////////// INDICATORS\

BOLH=iCustom(NULL,0,"Bands",Per,0,DEV,MODE_UPPER,1);////the last zero its the shift   
BOLL= iCustom(NULL,0,"Bands",Per,0,DEV,MODE_LOWER,1);////the last zero its the shift 
Comment("bollh = " ,BOLH); // show us the price of the boll high


//////////////////CHECK FOR BUY

if (trade==false && Order==IDLE)
{

if (  Open[0]<=BOLL && Open[1]<BOLL )

{Order=SIGNAL_BUY;}
    Alert("buy_signal");
      
}
//////////////////////////////


//////////////////CHECK FOR SELL

if (trade==false && Order==IDLE)
{

if (  Open[0]>=BOLH && Open[1]>=BOLH )

{Order=SIGNAL_SELL;}
      Alert("sell_signal");
      
}

/////////////////////////BUY
if (trade==false)
{
  if (Order == SIGNAL_BUY  )
  {

  ticketb=OrderSend(Symbol(),OP_BUY,lotSize,Ask,3,0, 0,"SHAUL",MagicNumber,Green);   //open
  OrderModify(ticketb,0,Ask-(SL*Point),Ask+(TP*Point),0,Green);

      if(OrderSelect( ticketb, SELECT_BY_TICKET )==true)
      {
       Alert("LONG ORDER OPENED IN SHAUL"," Symbol= ",Symbol()," Period=",Period(), " Ticket= ",ticketb);
      Order = SIGNAL_TRBUY;
      
       
        
      }
      else
      {
      Print("OrderSelect returned the error of ",GetLastError());
      Alert("EROR LONG ORDER IN SHAUL "," Symbol= ",Symbol()," Period=",Period()," EROR= ",GetLastError());
      Order= IDLE;
      }
   }
} 
/////////////////////////////////// END


/////////////////////////sell
if (trade==false)
{
  if (Order == SIGNAL_SELL  )
  {

  tickets=OrderSend(Symbol(),OP_SELL,lotSize,Bid,3,0, 0,"SHAUL",MagicNumber,Green);
  OrderModify(tickets,0,Ask+(SL*Point),Ask-(TP*Point),0,Green);

      if(OrderSelect( tickets, SELECT_BY_TICKET )==true)
      {
       Alert("SHORT ORDER OPENED IN SHAUL"," Symbol= ",Symbol()," Period=",Period(), " Ticket= ",ticketb);
      Order = SIGNAL_TRSELL;
      
        
      }
      else
      {
      Print("OrderSelect returned the error of ",GetLastError());
      Alert("EROR SHORT ORDER IN SHAUL "," Symbol= ",Symbol()," Period=",Period()," EROR= ",GetLastError());
      Order= IDLE;
      }
   }
} 
/////////////////////////////////// END


   return(0);
  }
//+------------------------------------------------------------------+
 

Your algorithm needs some structure, start with the easy stuff first.

if (  Open[0]<=BOLL && Open[1]<BOLL )
That could be your problem, usually the argument NEVER goes in the same direction. If one is less then < the other have to be > then in order to form a cross section. More than likely your bands are keeping up with your Bars.
 

Replace

if (OrdersTotal()==0)   
   {trade=false;}

to

if (OrdersTotal()==0)   
   {trade=false;Order = IDLE;}

and

OrderModify(ticketb,0,Ask-(SL*Point),Ask+(TP*Point),0,Green);

to

if(OrderSelect( ticketb, SELECT_BY_TICKET )==true)
OrderModify(ticketb,OrderOpenPrice(),Ask-(SL*Point),Ask+(TP*Point),0,Green);
 
  1.   if (OrdersTotal()==0)   
       {trade=false;}
       if (OrdersTotal()!=0)
       {
           for (int i=1; i<=OrdersTotal(); i++)       //Cycle for all orders..
          {                                        //displayed in the terminal
           if(OrderSelect(i-1,SELECT_BY_POS)==true)//If there is the next one
            {                                     
              if (OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
              {
               trade=true;
                   break;
                }
              else {trade=false;}
              }
            } 
       } 
    
    This code will set trade to false if the latest trade is not by this EA. The EA should ignore all trade except its own. Since you MUST count down while closing/deleting, get in the habit of always. Simplify:
    trade=false;
    for (int i=OrdersTotal()-1; i>=0; i--) if(
       OrderSelect(i,SELECT_BY_POS)
    && OrderSymbol()==Symbol() 
    && OrderMagicNumber()==MagicNumber){ trade=true; break; }
    

  2. if (trade==false && Order==IDLE)
    
    If trade is false then the Order is irreverent, plus you never set order back to IDLE, so it never trades again. Restructure to this pattern
    if (!trade){
       if (  Open[0]<=BOLL && Open[1]<BOLL ){
          ticketb=OrderSend(Symbol(),OP_BUY ...
       } else if(  Open[0]>=BOLH && Open[1]>=BOLH ){
          tickets=OrderSend(Symbol(),OP_SELL ...
       }
    }
    and you can then drop the unnecessary code like Order, SIGNAL_SELL
  3. ubzen comment is also valid
    If one is less then < the other have to be >
 
WHRoeder:
  1. This code will set trade to false if the latest trade is not by this EA. The EA should ignore all trade except its own. Since you MUST count down while closing/deleting, get in the habit of always. Simplify:
  2. If trade is false then the Order is irreverent, plus you never set order back to IDLE, so it never trades again. Restructure to this patternand you can then drop the unnecessary code like Order, SIGNAL_SELL
  3. ubzen comment is also valid
    If one is less then < the other have to be >

Doesn't it just mean that the Open of the last bar is less than BOLL and that the current open is less than BOLL? It looks ok to my novice eye.
Reason: