EA does not follow indicator signals

 

Hello,

I'm backtesting an EA that relies on a home made indicator.

The indicator does some tests on multiple timeframes, from M1 to H1 and draw a red bar if SELL advise, and green bar if BUY advise.

in the EA I do basicaly:

if indicator == -1 => buy

if indicator == 1 => sell

else => do nothing

Difficult to do more simple, but what I really do not understand is that when I use the back testing functionality on the M1 chart, my EA don't always open the deals when there are some indicator bars.

sometimes there are 3 bars the EA open only 2 deals, or sometime it just ignores a sell signals, or it opens a position while no signal at all.

I hope it's not a basic mistake, but I'm really stuck on this one, and any help would be greatly appreciated.

Regards,

indicator:

//+------------------------------------------------------------------+
//| GIMultiFrame.mq4 |
//| Copyright © 2009, |
//| https://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, "
#property link "https://www.metaquotes.net/"

#property indicator_separate_window
#property indicator_minimum -1
#property indicator_maximum 1
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_color2 Red
//---- buffers
double BuyBuffer[];
double SellBuffer[];

int time_periods[] = {PERIOD_M1, PERIOD_M5, PERIOD_M15, PERIOD_M30, PERIOD_H1, PERIOD_H4, PERIOD_D1};

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexBuffer(0,BuyBuffer);
SetIndexStyle(1,DRAW_HISTOGRAM);
SetIndexBuffer(1,SellBuffer);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars = IndicatorCounted();
if (counted_bars > 0)
counted_bars--;
int limit = Bars - counted_bars;
//----
for (int i = 0; i < limit; i++)
{
// alligator 1 hour ok
// RSI 1 hour < 50
// ADX 1 hour < 40
double lips1h = iAlligator(NULL, PERIOD_H1, 13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN, MODE_GATORLIPS, i);
double teeth1h = iAlligator(NULL, PERIOD_H1, 13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN, MODE_GATORTEETH, i);
double rsi1h = iRSI(NULL, PERIOD_H1, 14, PRICE_CLOSE, i);
double adx1h = iADX(NULL, PERIOD_H1, 14, PRICE_CLOSE, MODE_EMA, i);

double lips1m = iAlligator(NULL, PERIOD_M1, 13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN, MODE_GATORLIPS, i);
double teeth1m = iAlligator(NULL, PERIOD_M1, 13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN, MODE_GATORTEETH, i);
double rsi1m = iRSI(NULL, PERIOD_M1, 14, PRICE_CLOSE, i);

if ( lips1h > teeth1h &&
rsi1h > 50 &&
// adx1h > 20 &&
lips1m > teeth1m &&
rsi1m < 40)
{
BuyBuffer[i] = -1;
SellBuffer[i] = 0;
}
else if( lips1h < teeth1h &&
rsi1h < 50 &&
// adx1h > 20 &&
lips1m < teeth1m &&
rsi1m > 55)
{
SellBuffer[i] = 1;
BuyBuffer[i] = 0;
}
else
{
BuyBuffer[i] = 0;
SellBuffer[i] = 0;
}


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

//+------------------------------------------------------------------+
//| GExpert.mq4 |
//| Copyright © 2009, |
//| https://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, "
#property link "https://www.metaquotes.net/"

//#include <GInclude.mqh>

int TTE = 0;
int UDFID = 123456;
int pips_profit = 500;
int pips_loss = 250;
double nbLots = 0.1;
int slippage = 5;
//int GWAIT = 121;

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
double GIBuyValue = 0;
double GISellValue = 0;
int ticket = 0;

if (AccountFreeMargin() < 1000)
{
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}

if (iCustom(NULL, 0, "GIMultiFrame", 0, 0) != 0)
{
ticket = OrderSend(Symbol(), OP_BUY, nbLots, Ask, slippage, Ask - pips_loss * Point, Ask + pips_profit * Point, "GExpert", UDFID, TTE, Green);
// Print("buy time is ", DoubleToStr(TimeHour(TimeCurrent()), 0), ":");
if (ticket < 0)
{
Print("error buy ", GetLastError());
return (0);
}
}
else if (iCustom(NULL, 0, "GIMultiFrame", 1, 0) != 0)
{
ticket = OrderSend(Symbol(), OP_SELL, nbLots, Bid, slippage, Bid + pips_loss * Point, Bid - pips_profit * Point, "GExpert", UDFID, TTE, Red);
if (ticket < 0)
{
Print("error sell ", GetLastError());
return (0);
}
}

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

Reason: