I need code help please!

 
The idea:

Go short when bar close higher than the higher bollinger band and go long when the bar close lower than the lower bollinger band.

It sounds simple but I can't make an EA for this what works. Please help me!





int cnt, ticket, total;
double BoolHigh, BoolLow, Mahigh, Malow;
 
 
 
BoolLow = iBands(NULL,0,Bool,2,0,PRICE_CLOSE,MODE_LOWER,0); // Our Bollinger's high and low lines
BoolHigh = iBands(NULL,0,Bool,2,0,PRICE_CLOSE,MODE_UPPER,0);
 
 
total=OrdersTotal(); //it counts our orders
 
if(total < 1) //if there isn't any opened order, it check we should buy or sell
 
{
 
 
if(Bid < BoolLow)
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"My EA",12345,0,Green); //BUY and exit
 
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Error opening BUY order : ",GetLastError());
return(0);
}
if(Ask > BoolHigh) //SELL and exit
{
 
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,"My EA",12345,0,Red);
 
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
}
else Print("Error opening SELL order : ",GetLastError());
return(0);
}
 
}
for(cnt=0;cnt<total;cnt++) //If we have opened order
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
 
if(OrderType()==OP_BUY) // and if it's a long trade
{
// should it be closed?
if(Ask > BoolHigh)
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // If we should short, it closes our long, and open a short
 
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,"My EA",12345,0,Red);
 
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
}
else Print("Error opening SELL order : ",GetLastError());
 
 
return(0); // exit
}
}
 
 
if(OrderType()==OP_SELL) //If it's a short order
{
// should it be closed?
if(Bid < BoolLow) //it checks for the long signal
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); //if we should long, it closes our short and open a long
 
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"My EA",12345,0,Green);
 
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Error opening BUY order : ",GetLastError());
return(0); // exit
}



Files:
boolbad.mq4  5 kb
 

 
I'm new to programming. I've read most of the posts at least partialy. It seems to me that you may just need a simple change if(Bid <= BoolLow). The Close may not actualy have been less than the band even though the chart shows it. I do not know if = will fit your trading stradagy though.
Reason: