How many EAs per chart on MT5?

 

Hi All,

How many EAs per chart on MT5? Only one??? Is there a way around that?

Thanks!

Jose

 
  1. One.
  2. Open a second chart with the same symbol.
 

I am using an EA to fetch data. The second EA would be the strategy. So, just not possible. Thanks!

 
netojose:

I am using an EA to fetch data. The second EA would be the strategy. So, just not possible. Thanks!

Use an indicator to fetch data.

Write the EA to fetch data and execute the strategy.

 
netojose:

I am using an EA to fetch data. The second EA would be the strategy. So, just not possible. Thanks!

Why do you want to use 2 EAs ?
 
Keith Watford: Use an indicator to fetch data.

Indicators can not sleep — fetch over the network is not possible.

 
netojose: I am using an EA to fetch data. The second EA would be the strategy. So, just not possible. Thanks!

What part of "Open a second chart with the same symbol" was unclear? Fetch EA on one, strategy EA on the other. No one said "just not possible."

 
William Roeder:

Indicators can not sleep — fetch over the network is not possible.

Indicators cannot sleep, this is true.

But Fetch over network is possible. I implemented it and have it working like an EA does, but inside my indicator.


Example function on the indicator:


int copied=CopyRates(Symbol(),TimeFrame,0,quantity,ra); 
   if (copied < quantity) {
      
      DisplayCompleto("Downloading data " + per + "...     ",clrSkyBlue);

      downloadFlag = 1;        
      Print(__FUNCTION__, ": ->CheckBars '" , quantity, "' barras, ", EnumToString(TimeFrame));
      if (CheckBars(quantity, TimeFrame)  == false) {
         return 1;
      }
      downloadFlag = 0;
      return 0;     
   }


Now the functions inside my library to handle full data download inside any indicator:


The download is handled by the function CheckBars(), using a pseudo sleep function for 5000ms, until the download is completed. 

After sucessful download and bars are build, return code will be zero, and the indicator is ready to go with all data. 


// Functions to download data from server. Just call CheckBars on the indicator, other
// functions here are for internal use of CheckBars()
//


//+------------------------------------------------------------------+
//| Checks data by specified symbol's timeframe and                  |
//| downloads it from server, if necessary                           |
//+------------------------------------------------------------------+
bool CheckBars(const int size, ENUM_TIMEFRAMES TimeFrame) {
   
   if(size>TerminalInfoInteger(TERMINAL_MAXBARS)) {
      //--- Definitely won't have such amount of data
      printf(__FUNCTION__ + ": requested too much data (%d)",size);
      return(false);
   }
   
   if(CheckLocalBarsHistory(size, TimeFrame)) {
      return(true);
   }
 
   Print(__FUNCTION__, ": Going to download ", size, " bars ", PeriodToString(TimeFrame), " " , _Symbol );

   if(DownloadServerBarsHistory(size, TimeFrame)) {
      return(true);
   }
      
   return(false);
}
  
  

//+------------------------------------------------------------------+
//| Checks data in terminal                                          |
//+------------------------------------------------------------------+
bool CheckLocalBarsHistory(const int size, ENUM_TIMEFRAMES TimeFrame) {

   datetime times[1];
   long     bars=0;

   //--- Enough data in timeseries?
   if(Bars(_Symbol,TimeFrame)>=size) {
      Print("Yes, already has that bar range on local cache. I have " , size, "bar of period ", PeriodToString(TimeFrame), " " , _Symbol);
      return(true);
   }

   //--- segunda tentativa
   int barCount = SeriesInfoInteger(_Symbol,PERIOD_M1,SERIES_BARS_COUNT,bars);
   
   Print(__FUNCTION__, ": Checking.. Local cache has '", barCount, "' bars, but I need " , size, " more bars to ", PeriodToString(TimeFrame), " " , _Symbol );   

   if(barCount) {
   
     //--- Do I have M1 data to build other timeframes bars?
     if(bars>size*PeriodSeconds(TimeFrame)/60) {
      
         //--- force timeseries build
         Print(__FUNCTION__, ": Building bars for ",  PeriodToString(TimeFrame), " ", _Symbol);
         //Noticia("Construindo barras localmente " + PeriodToString(TimeFrame));
         MeioDisplayEsquerda("Creating bars for " + PeriodToString(TimeFrame),  clrLightYellow);
         CopyTime(_Symbol,TimeFrame,size-1,1,times);

         //--- check date
         if(SeriesInfoInteger(_Symbol,TimeFrame,SERIES_BARS_COUNT,bars)) {

            //--- Timeseries generated using data from terminal
            if(bars>size) {
               Print(__FUNCTION__, ": TimeSeries generated to: ", PeriodToString(TimeFrame));
               Noticia("TimeSeries " +  PeriodToString(TimeFrame) + "successfully generated"); 
               return(true);
            }   
         }   
      }
   }
  return(false);
}




//+------------------------------------------------------------------+
//| Downloads missing Bars data from server                          |
//+------------------------------------------------------------------+
bool DownloadServerBarsHistory(const int size, ENUM_TIMEFRAMES TimeFrame) {

   //--- load symbol history info
   datetime first_server_date=0;


   if(!SeriesInfoInteger(_Symbol,PERIOD_M1,SERIES_SERVER_FIRSTDATE,first_server_date)) {
      Print("Downloading bars from server: " + _Symbol + " Timeframe: " + PeriodToString(TimeFrame));
   }
   
   Print(__FUNCTION__, ": Server has [" , size, "] bars to be downloaded", PeriodToString(TimeFrame), " " , _Symbol, " start: ", first_server_date );
   
   //--- Enough data on server?
   if(first_server_date>TimeCurrent()-size*PeriodSeconds(TimeFrame)) {
      Print("Insufficient data on broker server to " + _Symbol + " Timeframe: " + PeriodToString(TimeFrame));
      return(false);
   }   
    //Print("Bar data OK on server to " + _Symbol + " Timeframe: " + PeriodToString(TimeFrame));
  
  
   //--- load data step by step
   datetime times[1];

   int timerEntrou=0;
   if(timer_5seg()) {
   
      Print("Downloading " + IntegerToString(size) + " bars " + _Symbol + " periodo " + PeriodToString(TimeFrame)); 
      DisplayCompleto("Baixando Barras " + PeriodToString(TimeFrame),  clrLightYellow);

      //--- wait for timeseries build
      if(!SeriesInfoInteger(_Symbol,TimeFrame,SERIES_SYNCHRONIZED)) {
         Print(__FUNCTION__, ": Timeframe out of sync: " , IntegerToString(size), " Timeframe:", PeriodToString(TimeFrame), " " , _Symbol );
      }
      
      //--- ask for built bars
      int bars=Bars(_Symbol,TimeFrame);
      if(bars>size) {
         Print("Sucess: Total local bars to " + _Symbol + " ='" + IntegerToString(bars) + "' bars");
         return(true);
      }
      
      
      //--- copying of next part forces data loading
      if(CopyTime(_Symbol,TimeFrame,size-1,1,times)==1) {
         Print(" Sucess: Loaded bars to " + _Symbol);
         return(true);
      }
      
      //DEBUG
      //Print(__FUNCTION__, " 'force data loading' failed!, Size: " , IntegerToString(size), ", bars:", IntegerToString(bars) , ", Timeframe:", PeriodToString(TimeFrame), " " , _Symbol);
      timerEntrou=1;
   }
   
   if (timerEntrou)    {
      //Print(__FUNCTION__, " falhou, retornando false. Size: " , IntegerToString(size), " Timeframe:", PeriodToString(TimeFrame), " " , _Symbol );
   }
  //--- failed
  return(false);  
}



double Timerintervalo_5s = 0;  // This is defined outside the function below.


bool timer_5seg() {

   double sleep = 5000;
   double agora = GetTickCount();
   
   bool res = false;
   
   if (Timerintervalo_5s < agora 
      || agora < Timerintervalo_5s-(sleep*2)
      ) { 
      Timerintervalo_5s = agora + sleep; 
      res = true;
   }
   
   return res;
}


 

here is the working visual example

(notice the source code messages in Brazilian Portuguese on the image below):

["Baixando barras" = "Downloading bars"],

["Poucas velas" = "Not enough bars"] 

["Criando barras" = "Creating Bars"]

["Baixando precos" = "Downloading Prices"]

["Baixando dados" = "Downloading data"]


(i translated most of them to english while pasting my code above)


Working example


The code is non-blocking, pseudo sleep runs exactly like a real sleep() function. Notice there is no EA attached nor running. 

I cleaned the cache to demonstrate the first loading and download of bars of the above Symbol.

Everything above is just 1 indicator attached to the graph (except the last subwindow containing the colored snake)


Please fell free to ask any questions. I hope my code can help you download the data for your application.

 
rrocchi: But Fetch over network is possible. I implemented it and have it working like an EA does, but inside my indicator.

I don't think that is the type of data fetch the OP was talking about. If it was, he wouldn't need two EAs.