Why does my EA work in strategy tester with EURUSD, but not with GBPJPY or GBPUSD?

 

Hello, I just built my first EA, and I tried to test it in the strategy tester. Data is complete, other EA work on the same properties on GBPJPY nad GBPUSD, so I dont understand why isnt my EA working? It turns out that the EA did not open any trades on these pairs, where as it does work correctly on EURUSD pair. Does anybody have any kind of suggestions concerning this problems? Here is the code to my EA, if you had any general comments concerning my EA, please let me know as I am a total newbie, and I would be greatful for any help. Tomek

//+------------------------------------------------------------------+
//|                                                         tom2.mq4 |
//|                                                  Tomasz Bulinski |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Tomasz Bulinski"


// external variables


extern double LotSize = 0.1;
extern double StopLoss = 10;
extern double TakeProfit = 10;



//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  { 
  
static datetime Time0;
    if (Time0 == Time[0]) return(0); Time0 = Time[0];  
  
int cnt;  
double nowmain;      // new main line
double b4main;       // past main line
double b4plusdi;     // past line +DI
double b4minusdi;    // past line -DI
double nowplusdi;    // present line +DI
double nowminusdi;   // present line -DI
double mainstoch;    // main stochastic line
double signalstoch;  // signal stochastic line 
int ticket;          // ticket number
double price;        // price
int stoploss;        // stoploss
double OpenPrice; 
double BuyStopLoss;
double BuyTakeProfit; 
int total = OrdersTotal(); 
double MA9;           // moving average 9
double MA20;          // moving average 20
double MA9b4;         // moving average 9 past
double Heiken_op; 
double Heiken_cl; 
double Heiken_op2;
double Heiken_cl2;
double mainstoch2;
double signalstoch2;
double mainstoch1;
double signalstoch1;

mainstoch1 = iStochastic(0,0,5,3,3,MODE_SMA, Close, 0, 1);
signalstoch = iStochastic (0,0,5,3,3,MODE_SMA, Close, 1,1);
mainstoch =  iStochastic(0,0,5,3,3,MODE_SMA, Close, 0, 2);
signalstoch = iStochastic (0,0,5,3,3,MODE_SMA, Close, 1,2);
mainstoch2 =  iStochastic(0,0,5,3,3,MODE_SMA, Close, 0, 3);
signalstoch2 = iStochastic (0,0,5,3,3,MODE_SMA, Close, 1,3);
b4main = iADX(0,0,14,PRICE_CLOSE,MODE_MAIN,2);    // past main line
nowmain = iADX(0,0,14,PRICE_CLOSE,MODE_MAIN,0); // formula for the new main line
b4plusdi = iADX(0, 0, 14, PRICE_CLOSE, MODE_PLUSDI, 2); 
b4minusdi = iADX(0, 0, 14, PRICE_CLOSE, MODE_MINUSDI, 2);
nowplusdi = iADX(0, 0, 14, PRICE_CLOSE, MODE_PLUSDI, 0);
nowminusdi = iADX(0, 0, 14, PRICE_CLOSE, MODE_MINUSDI, 0); 
MA9 = iMA(0,0,9,1,0,0,0);
MA9b4 = iMA(0,0,9,1,0,0,1);
MA20 = iMA(0,0,20,1,0,0,0);
Heiken_op = iCustom(NULL,0,"Heiken Ashi",Red,White,Red,White,2,1);
Heiken_cl = iCustom(NULL,0,"Heiken Ashi",Red,White,Red,White,3,1);


OpenPrice = Ask;
BuyStopLoss = OpenPrice - (StopLoss * Point);
BuyTakeProfit = OpenPrice + (TakeProfit * Point);




   // Check for Open

if  ((nowmain>20) && (b4plusdi<b4minusdi) && (nowplusdi>nowminusdi) && ((mainstoch>signalstoch)||(mainstoch1>signalstoch1) || (mainstoch2>signalstoch2))
&& (mainstoch<40)&& (Heiken_op>Heiken_cl) &&(MA9b4<MA9)) //condition
{ticket = OrderSend(Symbol(),OP_BUY,LotSize,OpenPrice,2, BuyStopLoss, BuyTakeProfit,0,Green);}



 // Check for close

 for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY) // long position is opened
{
// should it be closed?
if((b4plusdi>b4minusdi) && (nowplusdi<nowminusdi))
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet);
// close position
return(0); // exit
      }
    }
  }
}  

return(0);
}


                      
        

 

Are you on a 5 digit or 4 digit broker ? if you are on a 4 digit broker then your stop is 1 pip and may be too close . . .

What errors are generated when a trade was attempted ? was a trade attempted ? if you don't know this how can you hope to fault find your problem ?

At least do this . . .

  // Check for Open

if  ((nowmain>20) && (b4plusdi<b4minusdi) && (nowplusdi>nowminusdi) && ((mainstoch>signalstoch)||(mainstoch1>signalstoch1) || (mainstoch2>signalstoch2))
&& (mainstoch<40)&& (Heiken_op>Heiken_cl) &&(MA9b4<MA9)) //condition
{ticket = OrderSend(Symbol(),OP_BUY,LotSize,OpenPrice,2, BuyStopLoss, BuyTakeProfit,0,Green);}


Print ("Last error = ", GetLastError());   // <--------------   add this line

if you don't get an error then you need to start looking at the values in your if statement . . .

 

Because they have different "characteristics" - one EA will not conquer them all.

But it is clear your code has one big problem - it doesn't have any Print() statements.

Code that doesn't have sufficient Print() statements will simply not work. ;-)

 
Thanks guys for your fast reply!
 
  1. You must count down when closing orders in the presence of multiple orders (multiple charts). No magic number makes the EA incompatable with any other including itself on other timeframes.
        for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
            OrderSelect(pos, SELECT_BY_POS)                 // Only my orders w/
        &&  OrderMagicNumber()  == magic.number             // my magic number
        &&  OrderSymbol()       == Symbol() ){              // and my pair.
    

  2. Always test return codes
    ticket = OrderSend(Symbol(),OP_BUY,LotSize,OpenPrice,2, BuyStopLoss, BuyTakeProfit,0,Green);
    if (ticket < 0) Alert("OrderSend failed: ", GetLastError());

  3. EA's must adjust TP, SL, AND SLIPPAGE for 5 digit brokers. On ECN brokers you must open and THEN set stops.
    //++++ These are adjusted for 5 digit brokers.
    int     pips2points;    // slippage  3 pips    3=points    30=points
    double  pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
    int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
    int     init(){
        if (Digits == 5 || Digits == 3){    // Adjust for five (5) digit brokers.
                    pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
        } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
        // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl