First EA not working in strategy tester. Troubleshooting help

 

Hi, I have spend months learning MQL4 and have just finished writing my first EA, or so I hoped. Unfortunatly when I go to test it in the strategy tester, nothing happens, it takes no trades, shows no results, and doesn't run through the chart. I was hoping someone here could help me locate my issue as I am unable to find the problem. Thanks!

I have based the trigger function on an indicator that I made that correctly shows the signals as intended so I do not think that is the error though I could be wrong.

extern double MinStop=7; //pips
extern double MaxStop=30; //pips
extern double Slippage=20; //Slippage
extern double RiskPercent=.02; //percent of account risk
extern double AccountTradeValue=1000; //dollar amount to be traded with
double pips;
input string  Password="1EAJ";//Please Enter Your Password.
extern int    InpBandsPeriod=8;      // Bands Period
extern int    InpBandsShift=0;        // Bands Shift
extern double InpBandsDeviations=1.0; // Bands Deviations
extern ENUM_MA_METHOD InpMAMethod=MODE_EMA;  // Method
extern int MagicNumber=1234;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
// Determine what a pip is.
   pips=Point; //.00001 or .0001. .001 .01.
   if(Digits==3 || Digits==5)
      pips*=10;
//---
   if(Password!="1EAJ")
     {
      MessageBox("Please reload the Expert with the correct password.","Wrong Password Entered!");
      Comment(WindowExpertName(),"is NOT running because you have entered the wrong password!"+
              "\nPlease reload the Expert with the correct password.");
      ExpertRemove();
      return(INIT_FAILED);
     }
   if(!IsExpertEnabled())
     {
      MessageBox("You need to enable AutoTrading","Please enable Autotrading!");
      Comment(WindowExpertName(),"is NOT running because you have AutoTrading Disabled!"+
              "\nPlease Enable AutoTrading and reload the expert.");
      ExpertRemove();
      return(INIT_FAILED);
     }
   if(!IsTradeAllowed())
     {
      MessageBox("You need to \"Allow Live Trading\"","Please check \"Allow Live Trading\"!");
      Comment(WindowExpertName(),"is NOT running because you do not have \"Allow Live Trading\" enabled!"+
              "\nPlease Enable \"Alow Live Trading\" and reload the expert.");
      ExpertRemove();
      return(INIT_FAILED);
     }
   if(!IsDllsAllowed())
     {
      MessageBox("DLLs are NOT enabled!","Please enable DLLs!");
      Comment(WindowExpertName(),"is NOT running because you have DLLs Disabled!"+
              "\nPlease Enable DLLs and reload the expert.");
      ExpertRemove();
      return(INIT_FAILED);
     }
   if(!IsLibrariesAllowed())
     {
      MessageBox("Allow import of external experts is NOT enabled!","Please enable it!");
      Comment(WindowExpertName(),"is NOT running because you have external experts Disabled!"+
              "\nPlease Enable them and reload the expert.");
      ExpertRemove();
      return(INIT_FAILED);
     }
   Comment("Expert Loaded Successfully");
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   Comment(" ");
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   CheckForSignal();
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//|  TRIGGER FUNCTION                                                                |
//+------------------------------------------------------------------+
void CheckForSignal()
  {
   static datetime candletime=0;
   if(candletime!=Time[0])
     {
      // Upper Band
      double EMAUpper=iMA(NULL,0,InpBandsPeriod,InpBandsShift,InpMAMethod,PRICE_HIGH,1);
      double StandardDevUpper=iStdDev(NULL,0,InpBandsPeriod,InpBandsShift,InpMAMethod,PRICE_HIGH,1);
      StandardDevUpper=StandardDevUpper*InpBandsDeviations+EMAUpper;

      double EMAUpperPrev=iMA(NULL,0,InpBandsPeriod,InpBandsShift,InpMAMethod,PRICE_HIGH,2);
      double StandardDevUpperPrev=iStdDev(NULL,0,InpBandsPeriod,InpBandsShift,InpMAMethod,PRICE_HIGH,2);
      StandardDevUpperPrev=StandardDevUpperPrev*InpBandsDeviations+EMAUpperPrev;

      // Lower Band
      double EMALower=iMA(NULL,0,InpBandsPeriod,InpBandsShift,InpMAMethod,PRICE_LOW,1);
      double StandardDevLower=iStdDev(NULL,0,InpBandsPeriod,InpBandsShift,InpMAMethod,PRICE_LOW,1);
      StandardDevLower=EMALower-StandardDevLower*InpBandsDeviations;

      double EMALowerPrev=iMA(NULL,0,InpBandsPeriod,InpBandsShift,InpMAMethod,PRICE_LOW,2);
      double StandardDevLowerPrev=iStdDev(NULL,0,InpBandsPeriod,InpBandsShift,InpMAMethod,PRICE_LOW,2);
      StandardDevLowerPrev=EMALowerPrev-StandardDevLowerPrev*InpBandsDeviations;

      // Sell Signal
      if(Close[1]>StandardDevUpper && Close[2]<StandardDevUpperPrev)
         EnterTrade(OP_SELL);
      // Buy Signal
      else if(Close[1]<StandardDevLower && Close[2]>StandardDevLowerPrev)
         EnterTrade(OP_BUY);
      candletime=Time[0];
     }
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//|     TRADE PLACING FUNCTION                                                             |
//+------------------------------------------------------------------+
void EnterTrade(int type)
  {

   int err=0;

   double price=Bid;
   double range=Close[1]-Open[1];
   if(range<(MinStop*pips))
      range=MinStop*pips;
   else if(range>(MaxStop*pips))
      range=MaxStop*pips;
   double sl=Close[1]+range;
   double tp=Open[1];
   double LotSize=(AccountTradeValue*RiskPercent/(range/pips)/10);
   if(type==OP_BUY)
     {
      price=Ask;
      range=Open[1]-Close[1];
      if(range<(MinStop*pips))
         range=MinStop*pips;
      else if(range>(MaxStop*pips))
         range=MaxStop*pips;
      sl=Close[1]-range;
      tp=Open[1];
      LotSize=(AccountTradeValue*RiskPercent/(range/pips)/10);
     }
//----
   int ticket=OrderSend(Symbol(),type,LotSize,price,Slippage,0,0,"Tripple EMA Trade",MagicNumber,0,Magenta);
   if(ticket>0)
     {
      if(OrderSelect(ticket,SELECT_BY_TICKET))
        {
         if(!OrderModify(ticket,price,sl,tp,0,Magenta))
           {
            err=GetLastError();
            Print("Encountered an error during modification!"+(string)err);
           }
        }
      else
        {//in case it fails to select the order for some reason 
         Print("Failed to Select Order ",ticket);
         err=GetLastError();
         Print("Encountered an error while seleting order "+(string)ticket+" error number "+(string)err);
        }
     }
   else
     {//in case it fails to place the order and send us back a ticket number.
      err=GetLastError();
      Print("Encountered an error during order placement!"+(string)err);
      if(err==ERR_TRADE_NOT_ALLOWED)MessageBox("You can not place a trade because \"Allow Live Trading\" is not checked in your options. Please check the \"Allow Live Trading\" Box!","Check Your Settings!");
     }
  }
//+------------------------------------------------------------------+
 
  1. Use the debugger or print out your variables, including prices and find out why.

  2. There is no need to open an order and then set the stops. Simplify your code - do it in one step. TP/SL on OrderSend has been fine for years.
              Build 500 2013.05.09 № 9
              Need help me mql4 guru add take profit to this EA - Take Profit - MQL4 programming forum

  3. Why did you post your MT4 question in the Root / MT5 EA section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.