EA Problem start() not executing

 

I am new to MetaTrader and I am having troubles with my EA.

I activated an EA in my demo account and start() is not getting called. I was developing the EA a couple weeks ago and it was working well both on the demo and strategy tester. I have been away for a couple weeks, and upon my return; after activating it, I was surprised because nothing was opening. I started to debug and realized that start() is not getting called. Both init() and deinit() do get called when I place or eliminate the EA on or from the chart. My first statement in init() is Print("blablabla"), but it never gets printed.

The only thing that come to mind is the following.

As I wanted the EA on a 3H chart, a few weeks ago, I was advised to use the Period_Converter_Opt to generate a 3H chart. I did that offline as per the instructions.

The 3H charts indicate (Offline) in the header which may be the reason why the 3H chart EA were not getting called, but now I have tried to see if it works on the standard charts, and testing on the 1M chart on the demo account, start() is not getting called either.

If I run Strategy Tester, it does get called and the EA is executed properly.

If anyone can help with this, I would really appreciate it.

Thanks,

 

Try the below Expert on M1_Chart. If it works then the problem is within your code. If you don't want to post your Expert then de-bug it line_by_line with Print() statements.

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void start(){
    Print("Symbol="+Symbol(),"____Bid="+Bid,"____Ask="+Ask);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
ubzen:

Try the below Expert on M1_Chart. If it works then the problem is within your code. If you don't want to post your Expert then de-bug it line_by_line with Print() statements.



Hi: I do not thiink that it is in the code because it was working a couple weeks ago and without any change start is not getting called. My feeling is that it may be some configuration issue on the client, but as I am new to MT4, I am not sure. No problem inserting the EA, didn't want to overload this given that the first statement that was a print was not executing. Any way, here it is. I inserted your print as well, but obviously that is not getting called either. Any help will be greatly appreciated.

//Globals

//Control
extern double lots=0.1;
extern datetime startTime;
extern datetime nowTime;
 extern int tradeCounter=0;
extern int stopLoss=40;
extern int takeProfit=60;
string symb;
//EMA
extern int emaSlowPeriod=10;
extern int emaFastPeriod=5;
extern int emaMODE=MODE_EMA;
extern int emaSlowPrice=PRICE_OPEN;
 extern int emaFastPrice=PRICE_CLOSE;
//RSI
extern int RSIPeriod=14;
extern int maxRSI=70;
extern int minRSI=30;
//Stochastik
extern int stoch_k=14;
extern int stoch_d=3;
extern int stoch_slow=3;
extern int maxSTOCH=80;
extern int minSTOCH=20;



//+------------------------------------------------------------------+
//| expert initialization function |
 //+------------------------------------------------------------------+
int init()
 {
 startTime=0; 
 Print("EA INITIALIZED");
 return(0);
 }
//+------------------------------------------------------------------+
 //| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
 {
 Print("EA DE-INITIALIZED");
 return(0);
 }
//+------------------------------------------------------------------+
 //| expert start function |
//+------------------------------------------------------------------+
int start()
 {
 Print("Symbol="+Symbol(),"____Bid="+Bid,"____Ask="+Ask);
 Print("EA STARTED");
 //Variables
 int totalTrades;
 int symbCnt=0;
 int orderReturn;
 //bool mod;
   
 //Do we have Enough Informatioon
 if (Bars < emaSlowPeriod) {
   Print("Not enough bars in the window to process. Stopping Process!!!");
   return(0);
 }
 //Are we overleveraged?

 symb=Symbol();

 //Initialize indicators
 //EMA
 double fastEma1=iMA(NULL,0,emaFastPeriod,0,emaMODE,emaFastPrice,1);
 double fastEma2=iMA(NULL,0,emaFastPeriod,0,emaMODE,emaFastPrice,2);
 double slowEma1=iMA(NULL,0,emaSlowPeriod,0,emaMODE,emaSlowPrice,1);
 double slowEma2=iMA(NULL,0,emaSlowPeriod,0,emaMODE,emaSlowPrice,2);

 //MAIN LOGIC
 //Limit Orders? 

 totalTrades=OrdersTotal();
 for (int i=0;i<totalTrades;i++) {
   if (OrderSelect(i,SELECT_BY_POS)==true) {
      //Print("FOR Iteration ", i, " Working Symbol: ", symb, " Selected Symbol: ", OrderSymbol());
      if (OrderSymbol()==symb) {
         symbCnt++;
         //Print("Caught Symbol and count is ", symbCnt);
      }
   }
   else {
      Print("ERROR OrderSelect: ",GetLastError());
      return(0);
   }
 }

 if (symbCnt>0) {
   Print("REPEAT ", symbCnt, " Funtion Value is: ", OrderSymbol(), " My Symbol is: ", symb, " Already has open trades. Exiting");
   return(0);
 }


 //LONG
 if (fastEma1 > slowEma1 && fastEma2 < slowEma2) {
   tradeCounter++;
   Print(" LONG Activated Clossing Shorts");
   closeShorts();
   //Print("Clossing Short Return");
   if (inRangeRSI(OP_BUY)==1) {
      if (inRangeSTOCH(OP_BUY)==1) {
         orderReturn=placeOrder(OP_BUY);
         totalTrades++; 
      }
   }
 }

 //SHORT
 if (fastEma1 < slowEma1 && fastEma2 > slowEma2) {
   tradeCounter++;
   Print(" SHORT Activated Clossing Longs");
   closeLongs();
   //Print("Clossing Short Return");
   if (inRangeRSI(OP_SELL)==1) {
      if (inRangeSTOCH(OP_SELL)==1) {
         orderReturn=placeOrder(OP_SELL);
         totalTrades++; 
      }
   }
 }

 //Finish
 double free=AccountFreeMargin();
 Comment("3H Cross: ", Symbol(), " Account Free Margin is ", DoubleToStr(free,2), "\n", "Current Time is ", TimeToStr(TimeCurrent()), " Open Trades: ",totalTrades);

 Print("EA FINISHED");
 return(0);
 }
//+------------------------------------------------------------------+

void closeShorts() {
 return(0);
}

void closeLongs() {
 return(0);
}

int inRangeRSI(int orderType) {
 //Initialize Indicators 
 
 double currentRSI=iRSI(NULL,0,RSIPeriod,PRICE_CLOSE,0);
 double previousRSI=iRSI(NULL,0,RSIPeriod,PRICE_CLOSE,1);
 
 //Print("RSI-Current: ", currentRSI, " RSI-Previous: ", previousRSI);
 
 switch (orderType){
   case OP_BUY:
      if (currentRSI>minRSI && currentRSI<maxRSI && currentRSI>previousRSI) {
         //Print("RSI !!! Values is: ", currentRSI);
         return(1);
      }
      else
         return(0);
      break;
  
   case OP_SELL:
      if (currentRSI>minRSI && currentRSI<maxRSI && currentRSI<previousRSI) {
         //Print("RSI !!! Values is: ", currentRSI);
         return(1);
      }
      else
         return(0);
      break; 
  }
 Print("Critical Error, Variable not well assigned in switch statement");
 return(0); 
}


int inRangeSTOCH(int orderType) {
 //Initialize Indicators 
 
 double currentSTOCH=iStochastic(NULL,0,stoch_k,stoch_d,stoch_slow,MODE_SMA,0,MODE_SIGNAL,0);
 double previousSTOCH=iStochastic(NULL,0,stoch_k,stoch_d,stoch_slow,MODE_SMA,0,MODE_SIGNAL,1);
 
 //Print("Sochastic-Current: ", currentSTOCH, " Sochastic-Previous: ", previousSTOCH);
 
 switch (orderType){
   case OP_BUY:
      if (currentSTOCH > minSTOCH && currentSTOCH < maxSTOCH && currentSTOCH > previousSTOCH) {
         //Print("STOCHASTIC !!! Value is: ", currentSTOCH);
         return(1);
      }
      else
         return(0);
      break;
  
   case OP_SELL:
      if (currentSTOCH > minSTOCH && currentSTOCH < maxSTOCH && currentSTOCH < previousSTOCH) {
         //Print("STOCHASTIC !!! Value is: ", currentSTOCH);
         return(1);
      }
      else
         return(0);
      break; 
  }
 Print("Critical Error, Variable not well assigned in switch statement");
 return(0); 
}



 int placeOrder(int orderType) {
 int orderTicket;
 int orderErr;
 int k;
 bool mod;
 switch (orderType) { 
   case OP_BUY : //BUY
      orderTicket=OrderSend(Symbol(),OP_BUY,lots,Ask,3,getLongStop(),getLongLimit(),"BUYING Order Number: ",tradeCounter,0,Yellow);
      if (orderTicket<0) {
         orderErr=GetLastError();
         Print("LONG. Main Order Failed with error #", orderErr);
         return(orderErr); 
      }
      else {
         nowTime=TimeCurrent();
         Print("LONG. Successful Order Created at ",TimeToStr(TimeCurrent(),TIME_SECONDS));
         //Sleep(3000);
         return(0); 
      }
      break;
   case OP_SELL : //SELL
      orderTicket=OrderSend(Symbol(),OP_SELL,lots,Bid,3,getShortStop(),getShortLimit(),"SELLING Order Number: ",tradeCounter,0,Yellow);
      if (orderTicket<0) {
         orderErr=GetLastError();
         Print("SHORT. Main Order Failed with error #", orderErr);
         return(orderErr); 
      }
      else {
         nowTime=TimeCurrent();
         Print("SHORT. Successful Order Created", TimeToStr(TimeCurrent(),TIME_SECONDS));
         //Sleep(3000);
         return(0);
      }
      break;
   }
}

double getLongStop() {
 double tmp;
 tmp=Ask - (stopLoss*Point*10);
 //Print("ASK is: ", Ask, " Stop is: ",tmp);
 return(tmp);
}

double getLongLimit() {
 double tmp;
 tmp=Ask + (takeProfit*Point*10);
 //Print("ASK is: ", Ask, " Limit is: ",tmp);
 return(tmp);
}

double getShortStop() {
 double tmp;
 tmp=Bid + (stopLoss*Point*10);
 //Print("BID is: ", Bid, " Stop is: ",tmp);
 return(tmp);
}

double getShortLimit() {
 double tmp;
 tmp=Bid - (takeProfit*Point*10);
 //Print("BID is: ", Bid, " Limit is: ",tmp);
 return(tmp);
}


 
Your code looks fine. You should always keep Print() statement intervals to check the how control is flowing...
 
You have demo account is it expired ?? invalid account ??
 
deVries:
You have demo account is it expired ?? invalid account ??

I suppose that had it expired it would not let me in, but let me check with FXCM because that is the best explanation so far.
 

Same problem with me. I'm using a demo account. I have tried a very simple code that just sends an alert for each of init(), denit() and start() but I never get the alert in start().

This is my first attempt in MQL and it's very frustrating. Please post any possible solutions.  

 
1807649:

Same problem with me. I'm using a demo account. I have tried a very simple code that just sends an alert for each of init(), denit() and start() but I never get the alert in start().

This is my first attempt in MQL and it's very frustrating. Please post any possible solutions.  

Did you click the button to run EAs ?

 

Do you have a Smiling face with your EA name in the top right corner of your chart or a cross ? 

 

The problem was with my demo account. I don't know what exactly was the issue, but I have created a new demo account with a different broker and it works fine.  

Reason: