My EA never sends order

 

Hi,

I'm just starting out to use MQL4, and I want to code an EA which would act like the default Moving Average EA of MetaTrader, I have no error when I compile, but it never sends any order when I try it with the Strategy Backtester..

Here is the code:

int start()
  {
//----
      double MA = 0.0; 
      int ticket;
      
      MA = iMA(NULL, 0, 9, 0, MODE_SMA, PRICE_CLOSE, 0);  
            
      if(Open[1] > MA && Close[1] < MA){ 
         if(OrdersTotal() == 1 && OrderType() == OP_BUY){
            OrderClose(ticket, Lots, Ask, 5, Red);
            }
         
         ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, 3, Bid - TakeProfit * 0.5 * Point, "", 12345, 0, Green);
         OrderSelect(ticket, SELECT_BY_POS);
         }
         
      if(Open[1] < MA && Close[1] > MA){
         if(OrdersTotal() == 1 && OrderType() == OP_SELL){
            OrderClose(ticket, Lots, Bid, 5, Red);
               }
            ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, 3, Ask + TakeProfit * Point, "", 12345, 0, Green);
            OrderSelect(ticket, SELECT_BY_POS);
            }
            
            
 //----
   return(0);

I also wanted to know if the OrderSelect instruction was useful here ?

Thanks for help ! and sorry for my english.

 
Check the logs and check the error messages. Follow the solution. Check your codes one line at a time if you're new. if(Open[1] > MA && Close[1] < MA){ Print("____Made-It-Here_____");}. Make that line the EA and test in the back-tester. Then Add the next command and do the same again.
 

Your OrderSend() parameters are wrong

ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, 3, Bid - TakeProfit * 0.5 * Point, "", 12345, 0, Green);

you have your Bid - TakeProfit * 0.5 * Point as your stoploss but there is no Take Profit where it should be.

As ubzen said, always check your tester log it would have shown ordersend errors, the tester journal probably would have too.

 
Problem resolved, TakeProfit variable was missing.. Thanks !
Reason: