Strategy tester problems.

 

Hi all,

Im encountering problems with the strategy tester in mt4 with my own EA. I know the EA works because it works fine on the demo account feature. However, when I use it on the ST, the ST stops at the first tick. It loads the trades but then stops (ive checked using visual mode). 

Any ideas? 

No errors pop up when live trading on the demo account. 

Cheers

 

I doubt that anyone can suggest anything without seeing the code.


Topics concerning MT4 and MQL4 have their own section.

In future please post in the correct section.

I have moved your topic to the MQL4 and Metatrader 4 section.

 
Lakseote:

Hi all,

Im encountering problems with the strategy tester in mt4 with my own EA. I know the EA works because it works fine on the demo account feature. However, when I use it on the ST, the ST stops at the first tick. It loads the trades but then stops (ive checked using visual mode). 

Any ideas? 

No errors pop up when live trading on the demo account. 

Cheers

//+-----------------------------------------------------+
//|Trailing stops                                       |
//+-----------------------------------------------------+
void TrailStops()
{
  for (int i=0; 1 < OrdersTotal(); i++)  {
    if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) {
      if (OrderSymbol()==Symbol())   {
        if(OrderType()==OP_BUY)    {
            if (OrderStopLoss() < (Ask - 5))    {
              if(!OrderModify(OrderTicket(),OrderOpenPrice(),Ask-3*Point ,OrderTakeProfit(),0,clrNONE))   {
                Print("OrderModify error ", GetLastError());   }}}}           
        if(OrderType()==OP_SELL) {
          if(OrderStopLoss() > (Bid + 5))   {
            if(!OrderModify(OrderTicket(),OrderOpenPrice(),Bid + 3*Point,OrderTakeProfit(),0,clrNONE)) {
              Print("OrderModify error ", GetLastError()); }}}}            
   }               
}                  

  
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {

double atr = iATR(NULL,0,3,0);
double atrMultiple = 2.5;
int stopLoss = (int)(atr * atrMultiple/Point);
int takeProfit = stopLoss;  
double buyprice=Ask;
double sellprice=Bid;
double maxloss=10;
double buyProfit=Ask+takeProfit*Point;
double sellProfit=Bid-stopLoss*Point;

 
  if (OrdersTotal() > 0) {
     TrailStops();
     return;
  }
  
//--- place market order to buy 1 lot
   int ticketB=OrderSend(Symbol(),OP_BUY,1,buyprice,3,Bid-stopLoss*Point,buyProfit,"Buy",420,NULL,clrNONE);
   if(ticketB<0)
     {
      Print("Buy OrderSend failed with error #",GetLastError());
     }
   else
      Print(" Buy OrderSend placed successfully");
//--- place market sell order to sell 1 lot
   int ticketS=OrderSend(Symbol(),OP_SELL,1,sellprice,3,Ask+stopLoss*Point,sellProfit,"Sell",42069,NULL,clrNONE);
      if(ticketS<0)
      {
         Print("Sell OrderSend failed with error #",GetLastError());
      }
      else
         Print(" Sell OrderSend placed successfully");
 

With many symbols these will never be true

          if (OrderStopLoss() < (Ask - 5))
          // 
          if(OrderStopLoss() > (Bid + 5)) 

Your code will not place any new trades until all open trades are closed.