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!
The next question is how can it do the same, but not just when the bar closes outside the bars but when the price just hit it.
CODE:
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!
The next question is how can it do the same, but not just when the bar closes outside the bars but when the price just hit it.
CODE:
QuoteDislikedint 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
}
Attached File(s)
boolBAD.mq4
5 KB
|
276 downloads