EA stripped of all trading condition still makes trades !!

 

To say that I am puzzled is an understatement.

I removed all the Buy Sell and Exit conditions from this EA, Ran the Strategy Tester and it still makes trades.

It seemed that no matter what trading conditions I entered weird trades would take place, beginning and ending at random. 
Oblivious to the Macd RSI or MA cross that I had configured, eventually I stripped away every condition and ran it expecting no trades to occur.  

To my surprise... it gained $340 in 11 trades that were not supposed to happen. 


If anyone knows what or why, some clarity would be greatly appreciated. 


The is the Macd Sample EA updated with the False Trigger Protection https://www.mql5.com/en/articles/2110

//+------------------------------------------------------------------+
//|                                                  MACD Sample.mq4 |
//|                   Copyright 2005-2014, MetaQuotes Software Corp. |
//|                                              http://www.mql4.com |
//|                                                                  |
//|                                  Updated to macd_sample_plus.mq4 |
//|                            https://www.mql5.com/en/articles/2110 |
//+------------------------------------------------------------------+
#property copyright   "2005-2014, MetaQuotes Software Corp."
#property link        "http://www.mql4.com"
#property version       "1.0"


// https://www.screencast.com/t/apJJc4zqT2pE

// https://www.screencast.com/t/fDyPMb6GW  Gained $340 in 11 trades

extern double TakeProfit = 100000;  //set to an unreasonable amount
extern double Lots = 1;
extern double TrailingStop = 0;
extern int StopLoss=100000;         //set to an unreasonable amount  


//--- enter new variable (value in seconds for 1 bar of this TF, for М15 equals 60 с х 15 = 900 с)
datetime Time_open=1800;
//--- enter new variable (time of opening the bar with 1st entry)
datetime Time_bar = 0;



//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick(void)
  {

   int    cnt,ticket,total;
//---
// initial data checks
// it is important to make sure that the expert works with a normal
// chart and the user did not make any mistakes setting external 
// variables (Lots, StopLoss, TakeProfit, 
// TrailingStop) in our case, we check TakeProfit
// on a chart of less than 100 bars
//---

   if(Bars<100)
     {
      Print("bars less than 100");
      return;
     }
   if(TakeProfit<10)
     {
      Print("TakeProfit less than 10");
      return;
     }
     
     
//--- to simplify the coding and speed up access data are put into internal variables


// Removed Macd, RSI, MA etc.
       


   total=OrdersTotal();
   if(total<1)
     {
      //--- no opened orders identified
      if(AccountFreeMargin()<(1000*Lots))
        {
         Print("We have no money. Free Margin = ",AccountFreeMargin());
         return;
        }
      //--- check for long position (BUY) possibility
      
      //--- enter new string (removes ban on repeated entry if a new bar is opened)
      if( (TimeCurrent() - Time_bar) > 900 ) Time_open = 900; 
      

      
//BUY     
      
       if(   // trade conditions removed
       
          (TimeCurrent()-Time[0])<Time_open)                   
        {
             
         ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"macd sample",16384,0,Green);  
         
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
             {
              Print("BUY order opened : ",OrderOpenPrice());
            
              Time_open = TimeCurrent()-Time[0]; //enter new string (store interval from the bar opening time with the entry until the exit moment)
              Time_bar = Time[0]; //enter new string (remember opening time of the bar that had 1st entry)
            
             }
           }
         else
            Print("Error opening BUY order : ",GetLastError());
         return;
        }
      //--- check for short position (SELL) possibility
      
      
      //--- enter new string (removes ban on repeated entry if a new bar is opened)
      if( (TimeCurrent() - Time_bar) > 900 ) Time_open = 900;       
      
      
      
 //SELL    
 
      if(  // Trade conditions removed
      
       (TimeCurrent()-Time[0])<Time_open)       
         
        {
    
         
       ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,"macd sample",16384,0,Red);  
         
         
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
              {
               Print("SELL order opened : ",OrderOpenPrice());
               
              Time_open = TimeCurrent()-Time[0]; //enter new string (store interval from the bar opening time with the entry until the exit moment)
              Time_bar = Time[0]; //enter new string (remember opening time of the bar that had 1st entry)               
               
             }
           }
         else
            Print("Error opening SELL order : ",GetLastError());
        }
      //--- exit from the "no opened orders" block
      return;
     }

//--- it is important to enter the market correctly, but it is more important to exit it correctly...   
   for(cnt=0;cnt<total;cnt++)
     {
      if(!OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
         continue;
      if(OrderType()<=OP_SELL &&   // check for opened position 
         OrderSymbol()==Symbol())  // check for symbol
        {
         //--- long position is opened
         if(OrderType()==OP_BUY)
           {
           
           
//-BuyExit -- should it be closed?


            if(       // Exit conditions removed
              
                Bid > OrderOpenPrice() &&  // enter new string - optional (price in a positive area in regards to the entry level)
               TimeCurrent() == Time[0] ) // enter new string (simple improvement of exit algorithm: exit is strictly at the moment of opening current candlestick)
              {
               //--- close order and exit
               if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet))
                  Print("OrderClose error ",GetLastError());
               return;
              }
            //--- check for trailing stop
           if(TrailingStop>0)
             {


             // Trailing Stop removed



              }
           }
         else // go to short position
           {
           
           
//-Sell Exit -- should it be closed?


            if(      // Exit conditions removed 
               
            
                Ask < OrderOpenPrice() &&  // enter new string - optional (price in a positive area in regards to the entry level)
               TimeCurrent() == Time[0] ) // enter new string (simple improvement of exit algorithm: exit is strictly at the moment of opening current candlestick)
              {
               //--- close order and exit
               if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet))
                  Print("OrderClose error ",GetLastError());
               return;
              }
            //--- check for trailing stop
            if(TrailingStop>0)
              {


              // Trailing Stop removed



              }
           }
        }
     }
//---

}

//+------------------------------------------------------------------+
False trigger protection for Trading Robot
False trigger protection for Trading Robot
  • 2016.08.26
  • Aleksandr Masterskikh
  • www.mql5.com
This article describes different ways to increase the stability of operation of trading robots by removing possible repeated triggers (chatter): both using entry and exit algorithms separately, as well as connecting them. Nature of problem The problem of false triggers is particularly prominent during dips and sharp rises in the market when...
 
Aimak:
I can see two OrderSend in the code you provided, so it will open a new trade at new bar if there is no open trade

Thanks for the reply, Aimak.

I assume it is the False Trigger Protection that is causing it to wait for a new bar to open a trade.

How does it closing the trades?

And how is it deciding when to close?

When I enter conditions like BUY when fastMA is greater than the slowMA and Exit when.... But that isn't what happens. It is more like a gremlin is pulling strings behind the scene.

I've tried things like Buy at two Red candles followed by two Green Candles and Exit at 2 Red candles. If only that is what it actually did, it would make some logical sense. 

---------------------------

I just tried it again with a fastMA mediumMA and slowMA. The Buy and Short happen logically but the exits are whenever the gremlin chooses. It ignores multiple Exit conditions and then latter chooses one to Exit near. Typically always in profit. Is there something built into Metatrader or the the EA code that telling it to close only in profit? 

  

Hopefully someone will be kind enough to copy the EA code below and run the Strategy Tester and see what happens. I end up with many ignored Exits.
Note: the moving averages are hardcoded to the 5 min chart. (Again just trying to remove wierd results.)

//+------------------------------------------------------------------+
//|                           macd_sample_plus.mq4   MACD Sample.mq4 |
//|                   Copyright 2005-2014, MetaQuotes Software Corp. |
//|                                              http://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright   "2005-2014, MetaQuotes Software Corp."
#property link        "http://www.mql4.com"
#property version       "1.00"


extern double StartingBalance=10000;
extern double TakeProfit = 40000;
extern double Lots = 1;
extern double TrailingStop =10000;
extern int StopLoss=100000;





//--- enter new variable (value in seconds for 1 bar of this TF, for М15 equals 60 с х 15 = 900 с)
datetime Time_open=1800;
//--- enter new variable (time of opening the bar with 1st entry)
datetime Time_bar = 0;



//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick(void)
  {
   int    cnt,ticket,total;
//---
// initial data checks
// it is important to make sure that the expert works with a normal
// chart and the user did not make any mistakes setting external 
// variables (Lots, StopLoss, TakeProfit, 
// TrailingStop) in our case, we check TakeProfit
// on a chart of less than 100 bars
//---
   if(Bars<100)
     {
      Print("bars less than 100");
      return;
     }
   if(TakeProfit<10)
     {
      Print("TakeProfit less than 10");
      return;
     }
//--- to simplify the coding and speed up access data are put into internal variables
  
        
    
      // Current chart, current period, length, shift, price
      double WWhite = iMA(NULL,PERIOD_M5,8,0,MODE_EMA,PRICE_CLOSE,1);
   
   
        // Current chart, current period, length, shift, price white
     double RRed = iMA(NULL,PERIOD_M5,26,0,MODE_EMA,PRICE_CLOSE,1);
   
      
            // Current chart, current period, length, shift, price
     double YYellow = iMA(NULL,PERIOD_M5,55,0,MODE_EMA,PRICE_CLOSE,1);
  
   
   total=OrdersTotal();
   if(total<1)
     {
      //--- no opened orders identified
      if(AccountFreeMargin()<(1000*Lots))
        {
         Print("We have no money. Free Margin = ",AccountFreeMargin());
         return;
        }
      //--- check for long position (BUY) possibility
      
      //--- enter new string (removes ban on repeated entry if a new bar is opened)
      if( (TimeCurrent() - Time_bar) > 900 ) Time_open = 900; 
      
    
      
//BUY      
      
       if(  (WWhite>RRed) && (RRed>YYellow)  &&   (TimeCurrent()-Time[0])<Time_open)                   
        
      {ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"macd sample",16384,0,Green);  
         
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
             {
              Print("BUY order opened : ",OrderOpenPrice());
            
              Time_open = TimeCurrent()-Time[0]; //enter new string (store interval from the bar opening time with the entry until the exit moment)
              Time_bar = Time[0]; //enter new string (remember opening time of the bar that had 1st entry)
            
             }
           }
         else
            Print("Error opening BUY order : ",GetLastError());
         return;
        }
      //--- check for short position (SELL) possibility
      
      
      //--- enter new string (removes ban on repeated entry if a new bar is opened)
      if( (TimeCurrent() - Time_bar) > 900 ) Time_open = 900;       
      
      
      
 //SELL     
 
      if(  (YYellow>RRed) &&  (RRed>WWhite) &&  (TimeCurrent()-Time[0])<Time_open) 
      
         
        {ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,"macd sample",16384,0,Red);  
         
         
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
              {
               Print("SELL order opened : ",OrderOpenPrice());
               
              Time_open = TimeCurrent()-Time[0]; //enter new string (store interval from the bar opening time with the entry until the exit moment)
              Time_bar = Time[0]; //enter new string (remember opening time of the bar that had 1st entry)               
               
             }
           }
         else
            Print("Error opening SELL order : ",GetLastError());
        }
      //--- exit from the "no opened orders" block
      return;
     }

//--- it is important to enter the market correctly, but it is more important to exit it correctly...   
   for(cnt=0;cnt<total;cnt++)
     {
      if(!OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
         continue;
      if(OrderType()<=OP_SELL &&   // check for opened position 
         OrderSymbol()==Symbol())  // check for symbol
        {
         //--- long position is opened
         if(OrderType()==OP_BUY)
           {
           
           
//-BuyExit -- should it be closed?

       

            if(   (YYellow>RRed)   &&  
              
                Bid > OrderOpenPrice() &&  // enter new string - optional (price in a positive area in regards to the entry level)
               TimeCurrent() == Time[0] ) // enter new string (simple improvement of exit algorithm: exit is strictly at the moment of opening current candlestick)
              {
               //--- close order and exit
               if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet))
                  Print("OrderClose error ",GetLastError());
               return;
              }
//            //--- check for trailing stop
           if(TrailingStop>0)
             {
//               if(Bid-OrderOpenPrice()>Point*TrailingStop)
//                 {
//                  if(OrderStopLoss()<Bid-Point*TrailingStop)
//                    {
//                     //--- modify order and exit
//                     if(!OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green))
//                        Print("OrderModify error ",GetLastError());
//                     return;
//                    }
//                }
              }
           }
         else // go to short position
           {
           
           
//-Sell Exit -- should it be closed?


            if(   (RRed>YYellow) &&   
               
               Ask < OrderOpenPrice() &&  // enter new string - optional (price in a positive area in regards to the entry level)
               TimeCurrent() == Time[0] ) // enter new string (simple improvement of exit algorithm: exit is strictly at the moment of opening current candlestick)
              {
               //--- close order and exit
               if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet))
                  Print("OrderClose error ",GetLastError());
               return;
              }
            //--- check for trailing stop
            if(TrailingStop>0)
              {
//               if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
//                 {
//                 if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
//                    {
//                    //--- modify order and exit
//                     if(!OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red))
//                        Print("OrderModify error ",GetLastError());
//                     return;
//                    }
//                 }
              }
           }
        }
     }
//---


}


//+------------------------------------------------------------------+