Running more than one EA at a time

 
My EA runs fine when it is running on its own but if I try to run the same EA on a different Symbol at the same time on the same profile then the second one doesn't run very well or at all or there are lots of errors. This happens even if I use Symbol() and different magic numbers for the two separate charts. It even happens if I run different versions of the same code (i.e. the EA file names and the magic numbers are different but the code is identical otherwise). Have I got some sort of conflict with Global variables perhaps or is there some other reason why the second one just hangs? Thanks.
 
Sneck55:
My EA runs fine when it is running on its own but if I try to run the same EA on a different Symbol at the same time on the same profile then the second one doesn't run very well or at all or there are lots of errors. This happens even if I use Symbol() and different magic numbers for the two separate charts. It even happens if I run different versions of the same code (i.e. the EA file names and the magic numbers are different but the code is identical otherwise). Have I got some sort of conflict with Global variables perhaps or is there some other reason why the second one just hangs? Thanks.

As it should not be a problem to run the same EA on different charts (I do it without any problems) you should provide the code.. ?
 

Yeah. If the second one hangs, most probably it is trying to use the same resource like the first one.


Sneck55


Better show us the code and we will point to you which one is the culprit, if it is not time consuming.

 
use the SRC-button!!
 
gooly: use the SRC-button!!
What part of SRC was unclear? Why didn't you? Edit your post!

  1. Play video
    Please edit your post.
    For large amounts of code, attach it.

  2.          if(BuyTicket != 0)                                        
                {                                                      
                if(SmallMA<MediumMA)
                {
                for(Counter = 0; Counter <=OrdersTotal()-1; Counter++)
                {
                   :
                    Counter--;
                }
    If the power fails, OS crashes, terminal or chart is accidentally closed, the next time BuyTicket will be lost. You will have an open order but never try to close it. You don't need to remember the ticket number when you use a OrderSelect loop.
  3. You MUST count down when closing/deleting. Going back one will not work if another EA closes an order. Loops and Closing or Deleting Orders - MQL4 forum
  4. Simplify your booleans
    // if(SmallMA>MediumMA&&MediumMA>LargeMA) MABuyFanning = true;
    // else MABuyFanning = false;
       MABuyFanning = (SmallMA>MediumMA&&MediumMA>LargeMA);
  5. if(NewBar == true)
    You would never write if( (2+2) == 4) == true) would you? if(2+2 == 4) is sufficient. So Don't write if(bool == true), just use if(bool) or if(!bool).
 
SRC button was used to make the post
 
Sneck55:
SRC button was used to make the post

yep, but the first line "Sorry for the delay...." is not code and it ruined everything
 
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

extern bool CheckOncePerBar = true;
extern double FixedLotSize = 1;
extern double SystemStopLoss = 150;
extern double TakeProfit = 0;
extern int Slippage = 5;
extern int MagicNumber = 3574;

//Global Variables
int BuyTicket;
int SellTicket;
double InternalStopLoss;
double CalcDigits;
double CalcPoint;
bool MABuyFanning;
bool MASellFanning;
int SelectedOrder;
bool Closed;
int ErrorCode;
string ErrLog;
double BuyStopLoss;
double SellStopLoss;
bool NewBar;
double ThisBarOpen;
double SmallMA;
double MediumMA;
double LargeMA;
int Counter;



//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
CalcDigits = MarketInfo(Symbol(),MODE_DIGITS);//MODE_DIGITS is count of digits after decimal point
if(CalcDigits == 0) CalcPoint = 1;//Dow      
if(CalcDigits == 1) CalcPoint = 0.1;   
if(CalcDigits == 2) CalcPoint = 0.01;//Gold & Nymex
if(CalcDigits == 3) CalcPoint = 0.01;//Yen
if(CalcDigits == 4) CalcPoint = 0.0001;//Not used
if(CalcDigits == 5) CalcPoint = 0.0001;//Non-Yen forex
InternalStopLoss = SystemStopLoss*CalcPoint;
   
   return(INIT_SUCCEEDED);
  }
//-----------------------------------------------

void OnTick()
{

   if(CheckOncePerBar == true)
      {
      if(ThisBarOpen != Open[0])
         {
         ThisBarOpen = Open[0];
         NewBar = true;
         }
      else NewBar = false;
      }
    else NewBar = true;

if(NewBar == true)
{


//Reset Moving Averages
SmallMA = iMA(NULL,0,8,0,1,0,0);
MediumMA = iMA(NULL,0,10,0,1,0,0);
LargeMA = iMA(NULL,0,50,0,1,0,0);


   if(SmallMA>MediumMA&&MediumMA>LargeMA) MABuyFanning = true;
   else MABuyFanning = false;
      
   if(SmallMA<MediumMA&&MediumMA<LargeMA) MASellFanning = true; 
   else MASellFanning = false;   



if(BuyTicket == 0 && MABuyFanning == true)
 {
      RefreshRates();
      BuyStopLoss = Bid - InternalStopLoss;
   //   while(IsTradeContextBusy()) Sleep(10);
      BuyTicket = OrderSend(Symbol(),OP_BUY,FixedLotSize,Ask,Slippage,BuyStopLoss,0,"Buy Order",MagicNumber,0,Green);
          if(BuyTicket == -1)
            {
            ErrorCode = GetLastError();
            Alert("Symbol: ",Symbol(),"Error in buy routine: ",ErrorCode);
            ErrLog = StringConcatenate("Bid: ",MarketInfo(Symbol(),MODE_BID)," Ask: ",MarketInfo(Symbol(),MODE_ASK)," Lots: ",FixedLotSize," Stop Loss: ",BuyStopLoss);
            Print(ErrLog);
            //Buy ticket revert to 0 so it can try again in case of slow connection/timeout etc.
            BuyTicket = 0;
            } 
 }   


if(SellTicket == 0 && MASellFanning == true)
 {
      RefreshRates();
      SellStopLoss = Ask + InternalStopLoss;
    //  while(IsTradeContextBusy()) Sleep(10);
      SellTicket = OrderSend(Symbol(),OP_SELL,FixedLotSize,Bid,Slippage,SellStopLoss,0,"Sell Order",MagicNumber,0,Red);
          if(SellTicket == -1)
            {
            ErrorCode = GetLastError();
            Alert("Symbol: ",Symbol(),"Error in sell routine: ",ErrorCode);
            ErrLog = StringConcatenate("Bid: ",MarketInfo(Symbol(),MODE_BID)," Ask: ",MarketInfo(Symbol(),MODE_ASK)," Lots: ",FixedLotSize," Stop Loss: ",SellStopLoss);
            Print(ErrLog);
            SellTicket = 0;
            } 
  }  

//Exits

         if(BuyTicket != 0)
            {
            if(SmallMA<MediumMA)
            {
            for(Counter = 0; Counter <=OrdersTotal()-1; Counter++)
               {
               SelectedOrder = OrderSelect(Counter,SELECT_BY_POS);
               if(OrderMagicNumber() == MagicNumber && OrderSymbol() == Symbol() && OrderType() == OP_BUY)
                  {
                 // while(IsTradeContextBusy()) Sleep(10);
                  Closed = OrderClose(OrderTicket(),OrderLots(),MarketInfo(Symbol(),MODE_BID),Slippage,Red);
                  if(Closed == true) BuyTicket = 0;
                  else Alert("Symbol: ",Symbol()," Ticket: ",BuyTicket," unable to close buy order(s): buy ma convergence close routine");                  
                  }
            Counter--;               
                }
            }
            }

         if(SellTicket != 0)
            {
            if(SmallMA>MediumMA)
            {
            for(Counter = 0; Counter <=OrdersTotal()-1; Counter++)
               {
               SelectedOrder = OrderSelect(Counter,SELECT_BY_POS);
               if(OrderMagicNumber() == MagicNumber && OrderSymbol() == Symbol() && OrderType() == OP_SELL)
                  {
               //   while(IsTradeContextBusy()) Sleep(10);
                  Closed = OrderClose(OrderTicket(),OrderLots(),MarketInfo(Symbol(),MODE_ASK),Slippage,Red);
                  if(Closed == true) SellTicket = 0;
                  else Alert("Symbol: ",Symbol()," Ticket: ",SellTicket," unable to close sell order(s): sell ma convergence close routine");                  
                  }
            Counter--;               
                }
            }
            }
}            
return;   
}
 
Sneck55: SRC button was used to make the post
qjol: yep, but the first line "Sorry for the delay...." is not code and it ruined everything
Why didn't you edit your original post?
 
The code is extremely simple and yet the more windows I run it on the worse it performs. I have been running it on 4 different Symbols but it even starts to fail on 1 symbol after a few minutes.

Also it starts off fine but the longer I run it (after a couple of hours or so) the slower and slower and less accurate it becomes.  Sometimes it can take up to a minute to remove

each EA from each window with the little circle by the cursor just going round and round for ages. I have a good fast PC which I have just defragged and scanned for viruses - I have

tried it on my laptop too with exactly the same results. I have tried downloading all the M1 history but it makes no difference. Could it be some sort of memory leak issue perhaps?

Is MT4 trying to use the same resources over and over again? Clearly I won't be able to trust it to trade on my live account until the issue is resolved!
 
This is interesting...
Reason: