EA not trading on live account

 
I’m having issues with my EA that I’ve spent coding over the past few weeks. 

Simply put, when I run a backtest it works perfectly, but doesn’t open trades when I tried to put it on my live account.

My broker is XM (pretty sure it’s STP)
I have autotrading enable etc, just wondering if it’s something to do with my order send function.

I’m not getting any errors, it simply just doesn’t trade

I can chuck the code in if need be.

Thanks in advance 
 
Harry Ward :
I’m having issues with my EA that I’ve spent coding over the past few weeks. 

Simply put, when I run a backtest it works perfectly, but doesn’t open trades when I tried to put it on my live account.

My broker is XM (pretty sure it’s STP)
I have autotrading enable etc, just wondering if it’s something to do with my order send function.

I’m not getting any errors, it simply just doesn’t trade

I can chuck the code in if need be.

Thanks in advance 

You MUST check for errors returned when submitting a trade order. You don't.

Start checking (start printing first) the result of the trade order.

 
Vladimir Karputov:

You MUST check for errors returned when submitting a trade order. You don't.

Start checking (start printing first) the result of the trade order.

There are no errors returned when I use the EA that is why I am confused

 
Harry Ward :

There are no errors returned when I use the EA that is why I am confused

And where are the errors? You must analyze the result of a trade and analyze whether there is an error or not.

Example of actions: sent a Buy trade order and printed the result:

ResultRetcode

Gets the code of request result

ResultRetcodeDescription

Gets the code of request result as a string

Documentation on MQL5: Standard Library / Trade Classes / CTrade / Buy
Documentation on MQL5: Standard Library / Trade Classes / CTrade / Buy
  • www.mql5.com
Successful completion of the Buy(...) method does not always mean successful execution of the trade operation. It is necessary to check the result of trade request (trade server return code) using ResultRetcode() and value returned by ResultDeal().
 
Vladimir Karputov:

And where are the errors? You must analyze the result of a trade and analyze whether there is an error or not.

Example of actions: sent a Buy trade order and printed the result:

ResultRetcode

Gets the code of request result

ResultRetcodeDescription

Gets the code of request result as a string

//+------------------------------------------------------------------+
//|                                                   ExpoProfit.mq4 |
//|                                                       Harry Ward |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Harry Ward"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

int maxOrders = 1;
int buyOrders = 0;
int sellOrders = 0;
double lotSize = 0.01*(AccountBalance()/10);

input int                inpPeriod  = 84;          // Period
input double             inpDivisor = 2.0;         // Divisor ("speed")
input ENUM_APPLIED_PRICE inpPrice   = PRICE_CLOSE; // Price

input   string  InpTradeComment         =       __FILE__;       //      Trade comment
input   int             InpMagicNumber                  =       69420;          //      Magic number

const string   IndicatorName        = "HMA Dynamic Color";

void OnTick()
  {
        double        currentSMA         = iMA(NULL, 0,100,0,MODE_EMA,PRICE_CLOSE,0); 
        
   if (!NewBar())       return;
        
   if (iCustom(NULL,0,IndicatorName, 84, true, true, true,1, 0) < currentSMA)
   {
      buyOrders = 0;
   }
   if ((iCustom(Symbol(),Period(),IndicatorName, inpPeriod, inpDivisor, inpPrice, true,0, 0) > 0) && (iCustom(Symbol(),Period(),IndicatorName, inpPeriod, inpDivisor, inpPrice, true,0, 0) < 2) && (iCustom(Symbol(),Period(),IndicatorName, inpPeriod, inpDivisor, inpPrice, true,0, 0) > currentSMA) && (buyOrders<1))
   {
      sellOrders = 0;
   }
   if ((iCustom(Symbol(),Period(),IndicatorName, inpPeriod, inpDivisor, inpPrice, true,1, 1) > 0) && (iCustom(Symbol(),Period(),IndicatorName, inpPeriod, inpDivisor, inpPrice, true,1, 1) < 2) && (iCustom(Symbol(),Period(),IndicatorName, inpPeriod, inpDivisor, inpPrice, true,1, 1) > currentSMA) && (sellOrders<1))
   {
      OrderSend(Symbol(),OP_SELL,lotSize,Bid,3,0,0,"ExpoProfit",0,0,clrRed);
      sellOrders = sellOrders + 1;
      lotSize = lotSize*2;
   }
   if ((iCustom(Symbol(),Period(),IndicatorName, inpPeriod, inpDivisor, inpPrice, true,0, 0) > 0) && (iCustom(Symbol(),Period(),IndicatorName, inpPeriod, inpDivisor, inpPrice, true,0, 0) < 2) && (iCustom(Symbol(),Period(),IndicatorName, inpPeriod, inpDivisor, inpPrice, true,0, 0) < currentSMA) && (buyOrders<1))
   {
      OrderSend(Symbol(),OP_BUY,lotSize,Ask,3,0,0,"ExpoProfit",0,0,clrGreen);
      buyOrders = buyOrders + 1;
      lotSize = lotSize*2;
   }
   if ((iCustom(NULL,0,IndicatorName, 84, true, true, true,0, 0)> currentSMA) && (countBuyPositions()>0) && (iCustom(NULL,0,IndicatorName, 84, true, true, true,1, 0)>currentSMA))
   {
      closeAllBuy(); 
      lotSize = 0.01*(AccountBalance()/10); 
      buyOrders = 0;
   }
   if ((iCustom(NULL,0,IndicatorName, 84, true, true, true,1, 0) < currentSMA) && (countSellPositions()>0))
   {
      closeAllSell();
      lotSize = 0.01*(AccountBalance()/10);
      sellOrders = 0;
   }
  }

void closeAllBuy()
{
   for (int i = OrdersTotal();i >= 0; i--) {
   
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
      
         if (OrderSymbol() == Symbol())
         
            if (OrderType()==OP_BUY)
            { 
               OrderClose(OrderTicket(),OrderLots(),Bid,3,NULL);
            }
   }
}

void closeAllSell()
{
   for (int i = OrdersTotal();i >= 0; i--) {
   
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
      
         if (OrderSymbol() == Symbol())
            
            if (OrderType()==OP_SELL)
            { 
               OrderClose(OrderTicket(),OrderLots(),Ask,3,NULL);
            }
   }
}
bool    NewBar() {

        static datetime priorTime       =       0;
        datetime                                currentTime     =       iTime(Symbol(), Period(), 0);
        bool                                    result          =       (currentTime!=priorTime);
        priorTime                                                       =       currentTime;
        return(result);
        
}
int countBuyPositions()
{
   int numberOfBuyPositions = 0;
   for(int i = OrdersTotal()-1; i >= 0 ; i--) {
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      string currencyPair = OrderSymbol();
      if (_Symbol == currencyPair)
         if(OrderType()==OP_BUY)
         {
            numberOfBuyPositions = numberOfBuyPositions +1;
         }
   }
   return numberOfBuyPositions;
}

int countSellPositions()
{
   int numberOfSellPositions = 0;
   for(int i = OrdersTotal()-1; i >= 0 ; i--) {
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      string currencyPair = OrderSymbol();
      if (_Symbol == currencyPair)
         if(OrderType()==OP_SELL)
         {
            numberOfSellPositions = numberOfSellPositions +1;
         }
   }
   return numberOfSellPositions;

This is my code, I don't know what youre asking me to do

 
Harry Ward:

This is my code, I don't know what youre asking me to do

Your code is MQL4.

Topics concerning MT4 and MQL4 have their own section.

You have been answered as if you were using MQL5.

In future please post in the correct section.

I will move your topic to the MQL4 and Metatrader 4 section.

 
Keith Watford:

Your code is MQL4.

Topics concerning MT4 and MQL4 have their own section.

You have been answered as if you were using MQL5.

In future please post in the correct section.

I will move your topic to the MQL4 and Metatrader 4 section.

Ok thanks, sorry about that

Reason: