Heeelp!!! Expert advisor works at backtest, but not at live trading... Pls have a look

 

 I also have the same problem. Ea works great on backtesting but not on live trade. There s no problem with my brooker. The script s below. I dont know anything about writing an expert advisor. Please have look and tell why it s not working.

regards 

 

//+------------------------------------------------------------------+
//|                                                    EMA_CROSS.mq4 |
//|                                                      Coders Guru |
//|                                         http://www.forex-tsd.com |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| TODO: Add Money Management routine                               |
//+------------------------------------------------------------------+

#property copyright "Coders Guru"
#property link      "http://www.forex-tsd.com"

//---- input parameters
extern double    TakeProfit=130;
extern double    StopLoss = 100;
extern double    Lots=1;
extern double    TrailingStop=20;

extern int ShortEma = 10;
extern int LongEma = 80;

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

int Crossed (double line1 , double line2)
   {
      static int last_direction = 0;
      static int current_direction = 0;
      
      //Don't work in the first load, wait for the first cross!
      static bool first_time = true;
      if(first_time == true)
      {
         first_time = false;
         return (0);
      }
      
      if(line1>line2)current_direction = 1; //up
      if(line1<line2)current_direction = 2; //down

      if(current_direction != last_direction) //changed 
      {
            last_direction = current_direction;
            return (last_direction);
      }
      else
      {
            return (0); //not changed
      }
   }

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//---- 

   int cnt, ticket, total;
   double SEma, LEma;
   
   
   if(Bars<100)
     {
      Print("bars less than 100");
      return(0);  
     }
   if(TakeProfit<10)
     {
      Print("TakeProfit less than 10");
      return(0);  // check TakeProfit
     }
     
     
   SEma = iMA(NULL,0,ShortEma,0,MODE_EMA,PRICE_CLOSE,0);
   LEma = iMA(NULL,0,LongEma,0,MODE_EMA,PRICE_CLOSE,0);
   
   
   static int isCrossed  = 0;
   isCrossed = Crossed (LEma,SEma);
   
   total  = OrdersTotal(); 
   if(total < 1) 
     {
       if(isCrossed == 1)
         {
            //ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,"EMA_CROSS",12345,0,Green);
            ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"EMA_CROSS",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);
         }
         if(isCrossed == 2)
         {

            //ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,"EMA_CROSS",12345,0,Red);
            ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"EMA_CROSS",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);
         }
         return(0);
     }
     
     
   for(cnt=0;cnt<total;cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      //OrderPrint();
      if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())
        {
         if(OrderType()==OP_BUY)   // long position is opened
           {
            // should it be closed?
           
           /* REMOVED - Trailling stop only close
           if(isCrossed == 2)
                {
                 OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position
                 return(0); // exit
                }
           */
           
            // check for trailing stop
            if(TrailingStop>0)  
              {                 
               if(Bid-OrderOpenPrice()>Point*TrailingStop)
                 {
                  if(OrderStopLoss()<Bid-Point*TrailingStop)
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
                     return(0);
                    }
                 }
              }
           }
         else // go to short position
           {
            // should it be closed?
            
            /* REMOVED - Trailling stop only close
            if(isCrossed == 1)
              {
               OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position
               return(0); // exit
              }
            */
            
            // check for trailing stop
            if(TrailingStop>0)  
              {                 
               if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
                 {
                  if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
                     return(0);
                    }
                 }
              }
           }
        }
     }

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

This EA seems to wok in higher timeframe and trend markets. Look for your backtest for a longer period of a flat market....

Or just change the timeframe for this EA to e.g. m1 and you'll see it isn't profitable even in the backtests.

 

Thank you so  much for your answer. but i change settings of it(MA, profit, stop loss, trailing stop loss) while i m adding it on chart. And i set the time frame on chart to 30M before i add the expert advisor. i use EUR/USD 

Still it doesnt work. When i add the ea on chart there s a smile at right corner but it doesnt trade. I think it has a problem on script. Isnt it?

 
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Don't double post and resurrect old threads unless you have a very good reason. Many things have changed since build 600.
  3. If your EA is trying to trade, there would be a error message for your OrderSends. You should already know why.
  4. You aren't adjusting for 4/5 digit brokers
  5. Check your return codes (OrderSelect, OrderModify, and OrderClose) What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  6. total  = OrdersTotal(); 
    if(total < 1) 
    No OrderSelect loop with filtering means your code is incompatible with every EA (including itself on other charts and manual trading.) Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 forum
  7. for(cnt=0;cnt<total;cnt++){
     OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
    :
              OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position
              return(0); // exit
    In the presence of multiple orders (one EA multiple charts, multiple EA's, manual trading) you must count down when closing/deleting/modifying in a position loop. Get in the habit of always counting down. Loops and Closing or Deleting Orders - MQL4 forum
 
WHRoeder:

  1. Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Don't double post and resurrect old threads unless you have a very good reason. Many things have changed since build 600.
  3. If your EA is trying to trade, there would be a error message for your OrderSends. You should already know why.
  4. You aren't adjusting for 4/5 digit brokers
  5. Check your return codes (OrderSelect, OrderModify, and OrderClose)What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  6. No OrderSelect loop with filtering means your code is incompatible with every EA (including itself on other charts and manual trading.) Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 forum
  7. In the presence of multiple orders (one EA multiple charts, multiple EA's, manual trading) you must count down when closing/deleting/modifying in a position loop. Get in the habit of always counting down. Loops and Closing or Deleting Orders - MQL4 forum
THNX for ur answer. I have found that it works on chart. But it doesnt work as same as backtest results. Why do you think? I dont have much idea about writing a script. May u explain it like you r talking like a child :) or may u fix the scripts. That will help me a lot...
 
sah16:
THNX for ur answer. I have found that it works on chart. But it doesnt work as same as backtest results. Why do you think? I dont have much idea about writing a script. May u explain it like you r talking like a child :) or may u fix the scripts. That will help me a lot...
Please write in English. If you are too lazy to type "you", non-native English speakers may be too lazy to try to help you.
 
sah16 But it doesnt work as same as backtest results. Why do you think? I dont have much idea about writing a script. May u explain it like you r talking like a child :) or may u fix the scripts. That will help me a lot...
  1. Please don't write ur - it's "you are" or "your" - MQL4 forum
  2. "Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. There are no mind readers here.
  3. I provided you multiple reasons "why I think."
  4. learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem.
Reason: