Hi all..
i have a problem with the EA that i wrote.. actually, the EA based on MACD indicator.. when the MACD become like 'n' shape, open post Sell, and when MACD become like 'u' shape, the EA will open Buy..
the problem is, the EA didn't open any post.. after i doing some backtest also, there no open post by this EA.. can someone please help me find what's wrong with the code??
here is the code..
Code:
extern double TakeProfit = 20;
extern double Lots = 0.1;
extern double StopLoss = 20;
extern double MagicNumber = 17384;
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalSMA=9;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
double MacdBuffer1[];
double MacdBuffer2[];
double MacdBuffer3[];
double MacdBuffer4[];
double MacdBuffer5[];
double MacdBuffer6[];
double MacdBuffer7[];
double MacdBuffer8[];
int init()
{
//----
//SetIndexBuffer(0, lag1_buffer);
//SetIndexBuffer(1, lag2_buffer);
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- macd counted in the 1-st buffer
for(int i=0; i<limit; i++)
MacdBuffer1[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
MacdBuffer2[i-1]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i-1)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i-1);
MacdBuffer3[i+1]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i+1)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i+1);
MacdBuffer4[i-2]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i-2)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i-2);
MacdBuffer5[i+2]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i+2)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i+2);
MacdBuffer6[i-3]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i-3)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i-3);
MacdBuffer7[i+3]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i+3)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i+3);
/*Alert( "MacdBuffer7[i+3] =",MacdBuffer7[i+3]);
Alert( "MacdBuffer5[i+2] =",MacdBuffer5[i+2]);
Alert( "MacdBuffer3[i+1] =",MacdBuffer3[i+1]);
Alert( "MacdBuffer1[i] =",MacdBuffer1[i]);
Alert( "MacdBuffer2[i-1] =",MacdBuffer2[i-1]);
Alert( "MacdBuffer4[i-2] =",MacdBuffer4[i-2]);
Alert( "MacdBuffer6[i-3] =",MacdBuffer6[i-3]);*/
//----
int ticket_buy, ticket_sell, total;
total=OrdersTotal();
//MACD become 'u' shape
if (MacdBuffer7[i+3]>MacdBuffer5[i+2]&&MacdBuffer5[i+2]>MacdBuffer3[i+1]&&MacdBuffer3[i+1]>MacdBuffer1[i]
&&MacdBuffer1[i]<MacdBuffer2[i-1]&&MacdBuffer2[i-1]<MacdBuffer4[i-2]&&MacdBuffer4[i-2]<MacdBuffer6[i-3])
{
if (total < 1) {
ticket_buy=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"scalp 1 min - buy",MagicNumber,0,Green);
if(ticket_buy>0)
{
if(OrderSelect(ticket_buy,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Error opening BUY order : ",GetLastError());
return(0);
} else {
}
}
//MACD become 'n' shape
if(MacdBuffer7[i+3]<MacdBuffer5[i+2]&&MacdBuffer5[i+2]<MacdBuffer3[i+1]&&MacdBuffer3[i+1]<MacdBuffer1[i]
&&MacdBuffer1[i]>MacdBuffer2[i-1]&&MacdBuffer2[i-1]>MacdBuffer4[i-2]&&MacdBuffer4[i-2]>MacdBuffer6[i-3])
{
if (total < 1) {
ticket_sell=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"scalp 1 min - sell",MagicNumber,0,Red);
if(ticket_sell>0)
{
if(OrderSelect(ticket_sell,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
}
else Print("Error opening SELL order : ",GetLastError());
return(0);
} else {
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
hope someone can help me solve the problem.. i'm not a good in programming codes.. thanks..
|