Multisymbol EA ... Challenge to set Assets Symbol and there class parameters. Is there better way than what I use?

 

Attached Code of My EA (relavant parts only)

//+-----------------------------------------------------------------------------------------------------------------------------+
//| INPUT:  Input for variable used in the expert advisor
//| NOTE:   Indicator parameters defaluted in CBase class (PRICE_CLOSE,VOLUME_TICK)
//+-----------------------------------------------------------------------------------------------------------------------------+

        input   group "TRADED SYMBOL(s)"
                                string                                                          InpSymbol1                                      = "UK100";                                      // EXPERT's SYMBOL1
                                string                                                          InpSymbol2                                      = "US500";                                      // EXPERT's SYMBOL2
                                string                                                          InpSymbol3                                      = "NAS100";                                     // EXPERT's SYMBOL3
                                string                                                          InpSymbol4                                      = "US30";                                               // EXPERT's SYMBOL4
                                string                                                          InpSymbol5                                      = "GER40";                                      // EXPERT's SYMBOL5

        input   group "MONEY MANAGEMENT"
                                double                                                          RiskPortfolio                   = 3.00;                                                 // RISK PERCENT FOR ENTIRE PORTFOLIP, ENTER AS 1.25 FOR 1.25%
                                double                                                          RiskPerTrade                            = 1.00;                                                 // RISK PERCENT PER TRADE, ENTER AS 0.50 FOR 0.50%
                                double                                                          InitialDeposit                  = 5000;                                                 // INITIAL DEPOSIT IN TRADE ACCOUNT
                                double                                                          MinimumDeposit                  = 4000;                                                 // MIN EQUITY TO BE MAINTAINED ON THE EXPERT

                                // iBand INDICATOR: BOLLINGER BANDS DUPLEX (with HEIKEN ASHI BAR PRICE)"
        input   int                                                                             Band_MAPeriod                           = 21;                                                           // BANDS AVERAGING PERIOD [20]
        input   double                                                          Band_SDOut                                      = 2.00;                                                 // BANDS STANDARD DEVIATION OUTER [2.00]
        input   double                                                          Band_SDInn                                      = 0.75;                                                 // BANDS STANDARD DEVIATION INNER
        input   double                                                          Band_ThldOB                                     = 1.00;                                                 // BANDS NORMALIZED (%bBB) THRESHOLD OVER BOUGHT
        input   CENUM_APPLIED_PRICE             Band_AppliedPrice               = priceHA_CLOSE;                // BANDS APPLIED PRICE TYPE [PRICE_CLOSE]
        input   ENUM_MA_METHOD                          Band_MAMethod                           = MODE_LWMA;                            // BANDS APPLIED MA AVERAGING METHOD [MODE_SMA]

//+-----------------------------------------------------------------------------------------------------------------------------+
//| Currently declaring EA Class for Each Symbol ...................................
//| Instead looking for option to create array of symbols and run a for..loop to instantize class(s
//+-----------------------------------------------------------------------------------------------------------------------------+
        CBaseExpert                                     *Expert_US30;
        CBaseExpert                                     *Expert_US500;
        CBaseExpert                                     *Expert_NAS100;
        CBaseExpert                                     *Expert_UK100;
        CBaseExpert                                     *Expert_GER40;
//+-----------------------------------------------------------------------------------------------------------------------------+
//| EXPERT:       OnInit() Initialization Function
//+-----------------------------------------------------------------------------------------------------------------------------+
int OnInit() {

        //+---------------------------------------------------------------------------------------------------------------------------+
        //| SET UP EXPERT CLASS FOR MULTI SYMBOLs
        //+---------------------------------------------------------------------------------------------------------------------------+
                // SYMBOL US30: (US30 WALL STREET INDEX alias DOW JONES INDUSTRIAL AVERAGE INDEX)
                Expert_US30 = new CBaseExpert(InpSymbol1,RiskPortfolio,RiskPerTrade);
                SetParamInpSymbol1();
                Expert_US30.OnInit();

                // SYMBOL US500: (The S&P 500 Index alias US500 INDEX)
                Expert_US500 = new CBaseExpert(InpSymbol2,RiskPortfolio,RiskPerTrade);
                SetParamInpSymbol2();
                Expert_US500.OnInit();
                // SYMBOL NAS100: (The S&P 500 Index alias US500 INDEX)
                Expert_NAS100 = new CBaseExpert(InpSymbol3,RiskPortfolio,RiskPerTrade);
                SetParamInpSymbol3();
                Expert_NAS100.OnInit();
                // SYMBOL UK100: (The S&P 500 Index alias US500 INDEX)
                Expert_UK100 = new CBaseExpert(InpSymbol4,RiskPortfolio,RiskPerTrade);
                SetParamInpSymbol4();
                Expert_UK100.OnInit();
                // SYMBOL GER40: (The S&P 500 Index alias US500 INDEX)
                Expert_GER40 = new CBaseExpert(InpSymbol5,RiskPortfolio,RiskPerTrade);
                SetParamInpSymbol5();
                Expert_GER40.OnInit();
        //+---------------------------------------------------------------------------------------------------------------------------+
                return(INIT_SUCCEEDED);

} // END of function OnInit()
//+-----------------------------------------------------------------------------------------------------------------------------+
//| EXPERT:       OnDeinit() DeInitialization Function
//+-----------------------------------------------------------------------------------------------------------------------------+
void OnDeinit(const int reason) {

        //+---------------------------------------------------------------------------------------------------------------------------+
        //| ON EXIT, DELETE CLASS(s) CREATED BY EXPERT
        //+---------------------------------------------------------------------------------------------------------------------------+
                delete Expert_US30;
                delete Expert_US500;
                delete Expert_NAS100;
                delete Expert_UK100;
                delete Expert_GER40;

} // END of function OnDeinit()
//+-----------------------------------------------------------------------------------------------------------------------------+
//| EXPERT:       OnDeinit() DeInitialization Function
//+-----------------------------------------------------------------------------------------------------------------------------+
double OnTester() {

        //+---------------------------------------------------------------------------------------------------------------------------
} // END of function OnTester()
/*
//+-----------------------------------------------------------------------------------------------------------------------------+
//| EXPERT:       OnTimer()
//+-----------------------------------------------------------------------------------------------------------------------------+
void OnTimer() {


} // END of function OnTester()
//+-----------------------------------------------------------------------------------------------------------------------------+
//| EXPERT:       OnTick() Tick Function
//+-----------------------------------------------------------------------------------------------------------------------------+
void OnTick() {

                // CHECK AND EXIT, IF TRADING IS NOT ALLOWED
          if(!TerminalInfoInteger(TERMINAL_TRADE_ALLOWED))                                                                                                                                                                                                                                                              return;
          if(!MQLInfoInteger(MQL_TRADE_ALLOWED))                                                                                                                                                                                                                                                                        return;
          if(!AccountInfoInteger(ACCOUNT_TRADE_EXPERT))                                                                                                                                                                                                                                                                 return;
          if(!AccountInfoInteger(ACCOUNT_TRADE_ALLOWED))                                                                                                                                                                                                                                                                return;

                // UPDATE PERFORMANCE MATRIC DATA, THE METHOD HAS INBUILT NEW BAR CONTROL
                cPerformance.UpdateEquityHistory();
                // UPDATE EQUITY BALACNE, THE METHOD HAS INBUILT NEW BAR FUNCTION
                UpdateEquityHistory();

                Expert_US30.OnTick();
                Expert_US500.OnTick();
                Expert_NAS100.OnTick();
                Expert_UK100.OnTick();
                Expert_GER40.OnTick();

} // END of function OnTick()
//+-----------------------------------------------------------------------------------------------------------------------------+
//| METHOD:                             SetParamInpSymbol1()
//| APPLICATION:        SET INDICATOR PARAMETERS FOR SYMBOL1
//+-----------------------------------------------------------------------------------------------------------------------------+
void SetParamInpSymbol1(void) {

                Expert_US30.SetParamSTTriplex(STF_ATRPeriod,STF_ATRMultiple,STM_ATRPeriod,STM_ATRMultiple,STS_ATRPeriod,STS_ATRMultiple);
                Expert_US30.SetParamBand(Band_MAPeriod,Band_SDOut,Band_SDInn,Band_AppliedPrice,Band_MAMethod,Band_ThldOB);
                Expert_US30.SetParamHullMA(HullMA_Period,HullMA_Divisor,HullMA_AppliedPrice);
                Expert_US30.SetParamRVI(RVI_MAPeriod,RVI_Thld);
                // SET NOISE FILTERS
                Expert_US30.SetParamER(ER_MAPeriod,ER_ThldNoise);
                // SET OSCILLATORS
                Expert_US30.SetParamAroon(Aroon_Period,Aroon_ThldHI);
                Expert_US30.SetParamMFI(MFI_MAPeriod,MFI_OnBBPeriod,MFI_OnBBSD,MFI_ThldOB);
                Expert_US30.SetParamSMFI(SMFI_MFIPeriod,SMFI_Stoch1Period,SMFI_EMAPeriod,SMFI_ThldOB);
                Expert_US30.SetParamSRSI(SRSI_RSIPeriod,SRSI_Stoch1Period,SRSI_EMAPeriod,SRSI_AppliedPrice,SRSI_ThldOB);
                // SET VOLATILITY FILTERS
                Expert_US30.SetParamATR(ATR_Period);
                Expert_US30.SetParamNATR(NATR_Period,RATR_Period,NATR_ThldHigh,NATR_ThldStrong);
                // SET VOLUME FILTERS
                Expert_US30.SetParamRVOL(RVOL_MAPeriod,RVOL_ThldHI,RVOL_ThldLO);
                // SET TRAIL STOP LOSS OR TARGET PROFIT INDICATORs
                Expert_US30.SetParam_iSAR(SARStep,SARStepMax);

} // END of function SetParamInpSymbol1()
//+-----------------------------------------------------------------------------------------------------------------------------+
//| METHOD:                             SetParamInpSymbol2()
//| APPLICATION:        SET INDICATOR PARAMETERS FOR SYMBOL1
//+-----------------------------------------------------------------------------------------------------------------------------+
void SetParamInpSymbol2(void) {

                Expert_US500.SetParamSTTriplex(STF_ATRPeriod,STF_ATRMultiple,STM_ATRPeriod,STM_ATRMultiple,STS_ATRPeriod,STS_ATRMultiple);
                Expert_US500.SetParamBand(Band_MAPeriod,Band_SDOut,Band_SDInn,Band_AppliedPrice,Band_MAMethod,Band_ThldOB);
                Expert_US500.SetParamHullMA(HullMA_Period,HullMA_Divisor,HullMA_AppliedPrice);
                Expert_US500.SetParamRVI(RVI_MAPeriod,RVI_Thld);
                // SET NOISE FILTERS
                Expert_US500.SetParamER(ER_MAPeriod,ER_ThldNoise);
                // SET OSCILLATORS
                Expert_US500.SetParamAroon(Aroon_Period,Aroon_ThldHI);
                Expert_US500.SetParamMFI(MFI_MAPeriod,MFI_OnBBPeriod,MFI_OnBBSD,MFI_ThldOB);
                Expert_US500.SetParamSMFI(SMFI_MFIPeriod,SMFI_Stoch1Period,SMFI_EMAPeriod,SMFI_ThldOB);
                Expert_US500.SetParamSRSI(SRSI_RSIPeriod,SRSI_Stoch1Period,SRSI_EMAPeriod,SRSI_AppliedPrice,SRSI_ThldOB);
                // SET VOLATILITY FILTERS
                Expert_US500.SetParamATR(ATR_Period);
                Expert_US500.SetParamNATR(NATR_Period,RATR_Period,NATR_ThldHigh,NATR_ThldStrong);
                // SET VOLUME FILTERS
                Expert_US500.SetParamRVOL(RVOL_MAPeriod,RVOL_ThldHI,RVOL_ThldLO);
                // SET TRAIL STOP LOSS OR TARGET PROFIT INDICATORs
                Expert_US500.SetParam_iSAR(SARStep,SARStepMax);

} // END of function SetParamInpSymbol2()

I am successfully using indicator class initialiazation as below with the help of Array of TimeFrame. Trying to apply same concept to Symbol definition and set symbol parameters 

                // INDICATOR HANDLE TIMEFRAME: WE SET TIME FRAME ARRAY LOWEST TO HIGHER PERIODs
                TFCount[3] = mTFH01;
                TFCount[2] = mTFM15;
                TFCount[1] = mTFM05;
                TFCount[0] = mTFM01;

                // INSTANTIATE INDICATOR CLASS(s) FOR ALL FOUR TIME FRAME WITH THE LOOP
for(int i = 0; i < _TFCount; i++) {

	// Indicators for the STRATEGY
      cDTBBB[i] = new CDTB_BB(mSymbol,TFCount[i],Param_iBand,Param_iHullMA,Param_iRVOL);
      cBand[i]  = new CiBand(mSymbol,TFCount[i],Param_iBand.maPeriod,Param_iBand.sdOut,Param_iBand.sdInn,Param_iBand.appliedPrice,Param_iBand.maMethod,Param_iBand.thldOB);

                        // Indicators for Stop Loss and / or Target Profit
 }   
MQL5.community - User Memo
MQL5.community - User Memo
  • www.mql5.com
You have just registered and most likely you have questions such as, "How do I insert a picture to my a message?" "How do I format my MQL5 source code?" "Where are my personal messages kept?" You may have many other questions. In this article, we have prepared some hands-on tips that will help you get accustomed in MQL5.community and take full advantage of its available features.
 
I won't recommend it:
  1. a multi-asset EA runs in one thread so that one asset blocks all the others
    while each EA for a single asset runs in its own thread,
  2. OnTick is triggered by ticks of its chart symbol what if there aren't any ticks for a while.
  3. If the setup for each symbol is different this part becomes terribly long and the variable names as well...
 
Carl Schreiber #:
I won't recommend it:
  1. a multi-asset EA runs in one thread so that one asset blocks all the others
    while each EA for a single asset runs in its own thread,
  2. OnTick is triggered by ticks of its chart symbol what if there aren't any ticks for a while.
  3. If the setup for each symbol is different this part becomes terribly long and the variable names as well...

@Carl Schreiber

Thanks Carl for your valuable feed back.

However I have created an ExpertClass with its own OnTick() and with internal subClasses to handle trading strategies. Each class have its own IsNewBar() for given Symbol it was loaded. I have run it on strategy tester and it worked for all the Symbols.

This serves me to have an EA (in form of class) for each symbol. This each EAClass is than called from main EA.mq5 file to run the multiple symbols.

The current issue is only to simplify the loading of each EA class for different symbols and simplifying the SetParam_Indicator() for each Symbol.

For now I have coded them manually and with repeated codes. However I wish to make it dynamic, so just change the Symbols in a array and on rerun the the EA class declration and SetParamIndicators are done for new value.

Hope it make sense and I am still open to learn any other structure/method to create an multi symbol EA.

 
Anil Varma #:

@Carl Schreiber

Thanks Carl for your valuable feed back.

However I have created an ExpertClass with its own OnTick() and with internal subClasses to handle trading strategies. Each class have its own IsNewBar() for given Symbol it was loaded. I have run it on strategy tester and it worked for all the Symbols.

This serves me to have an EA (in form of class) for each symbol. This each EAClass is than called from main EA.mq5 file to run the multiple symbols.

The current issue is only to simplify the loading of each EA class for different symbols and simplifying the SetParam_Indicator() for each Symbol.

For now I have coded them manually and with repeated codes. However I wish to make it dynamic, so just change the Symbols in a array and on rerun the the EA class declration and SetParamIndicators are done for new value.

Hope it make sense and I am still open to learn any other structure/method to create an multi symbol EA.

Declare an array of pointers

CBaseExpert* experts_arr[5];

void OnInit()
{
    experts_arr[0] = new CBaseExpert().OnInit(InpSymbol);
}
 
Dominik Christian Egert #: Declare an array of pointers

@Dominik Christian Egert Thanks man.

This is really so simple and how dumb I am not been able to think of it.

 
Topic has been moved to the section: Expert Advisors and Automated Trading