Singular to multiple currency pairs

 

Hi, this is a part of my EA, how can i convert this to a multi-symbol EA? Where's the best place to learn this?


datetime old_time;
string symbol_loop[] = {"USDJPY", "EURUSD", "USDCAD", "GBPUSD"};
   
   
int RSI_Handle;
int bb_Handle;


#include <Trade/Trade.mqh>
CTrade trade;
 
//+-------------------------------------------------------------------------------------------------------+
//|  OnInit                                                                                               |
//+-------------------------------------------------------------------------------------------------------+  

int OnInit()
  {

  RSI_Handle = iRSI(Symbol(), PERIOD_CURRENT, 14, PRICE_CLOSE); 
  bb_Handle = iBands(Symbol(), PERIOD_CURRENT, 14, 0, 2, PRICE_CLOSE);

      return(INIT_SUCCEEDED);
  }

//+-------------------------------------------------------------------------------------------------------+
//|  On DeInit                                                                                            |
//+-------------------------------------------------------------------------------------------------------+

void OnDeinit(const int reason)
  {


  }


//+-------------------------------------------------------------------------------------------------------+
//|  OnTick                                                                                               |
//+-------------------------------------------------------------------------------------------------------+

void OnTick(){  
  // Calculating current time
  datetime GMT = iTime(_Symbol, PERIOD_M15, 1);  
  // Check for new 15m candlestick
  if(GMT > old_time){    
      //If so, resets GMT to current value                                         
      old_time = GMT;         
   // Following code executed ONLY when new bar is complete


      
      double bid = SymbolInfoDouble(Symbol(), SYMBOL_BID);
      double ask = SymbolInfoDouble(Symbol(), SYMBOL_ASK);

      double open = Open(0);
      double close = Close(0);
      double high = High(0);
      double low = Low(0);
      
      //Relative Strength Index
      double rsivalue[];
      ArraySetAsSeries(rsivalue, true);
      CopyBuffer(RSI_Handle, 0, 1, 10, rsivalue);
      double RSI_Value = NormalizeDouble(rsivalue[0], 2);
      
      //Bollinger Bands
      
      double bbUpper[];          
      ArraySetAsSeries(bbUpper, true);
      CopyBuffer(bb_Handle, UPPER_BAND, 1, 2, bbUpper);
      double BB_Upper = NormalizeDouble(bbUpper[0], Digits());
   
      double bbLower[];
      ArraySetAsSeries(bbLower, true);   
      CopyBuffer(bb_Handle, LOWER_BAND, 1, 2, bbLower);
      double BB_Lower = NormalizeDouble(bbLower[0],  Digits());  
   
   }

}




double Open(int pShift)
{
   //Creates an object array of MqlRates structure
   MqlRates bar[];              
   //Sets our array as a series array (so current bar is position 0, previous bar is 1...)                
   ArraySetAsSeries(bar,true);    
   //Copies the bar price information of bars position 0, 1 and 2 to our array "bar"
   CopyRates(_Symbol,PERIOD_CURRENT,1,5,bar);   
   
   //Returns the close price of the bar object
   return bar[pShift].open;                    
}


double Close(int pShift)
{
   MqlRates bar[];              
   ArraySetAsSeries(bar,true);    
   CopyRates(_Symbol,PERIOD_CURRENT,1,5,bar);   
   
   return bar[pShift].close;                    
}


double High(int pShift)
{
   MqlRates bar[];              
   ArraySetAsSeries(bar,true);    
   CopyRates(_Symbol,PERIOD_CURRENT,1,5,bar);   
   
   return bar[pShift].high;                    
}


double Low(int pShift)
{
   MqlRates bar[];              
   ArraySetAsSeries(bar,true);    
   CopyRates(_Symbol,PERIOD_CURRENT,1,5,bar);   
   
   return bar[pShift].low;                    
}
 
luccc:

Hi, this is a part of my EA, how can i convert this to a multi-symbol EA? Where's the best place to learn this?


Have a look at this example:  

https://github.com/darwinex/advanced-mql-programming/blob/master/episode001/multi-symbol.mq5

advanced-mql-programming/episode001/multi-symbol.mq5 at master · darwinex/advanced-mql-programming
advanced-mql-programming/episode001/multi-symbol.mq5 at master · darwinex/advanced-mql-programming
  • darwinex
  • github.com
Contribute to darwinex/advanced-mql-programming development by creating an account on GitHub.
 

are there other resources which may help?

 
luccc #:

are there other resources which may help?

Here you go a whole video with code.


https://www.youtube.com/watch?v=7MivXntsHrI

mql5 EA Trades Multiple Symbols with the RSI Strategy | Part 2
mql5 EA Trades Multiple Symbols with the RSI Strategy | Part 2
  • 2023.09.10
  • www.youtube.com
*Complete MT5 Programming Course: https://en.bmtrading.de/mt5-masterclass/*Complete MT5 Martingale Class: https://en.bmtrading.de/mt5-martingale-class/*Recom...