Do do I optimize indicator usage to improve EA Speed?

 

Hello, I have the following if statement in a for loop of my EA that runs 24 times every 1 minute bar because I want 1 minute data for 24 pairs. If I take out the iRSI function call, the speed improved drastically. Is there a different way of calling the iRSI function, or any other function to make it faster? I guess there is probably a way to make to RSI calculate data for 14 bars only instead of calculating for every bar on the chart? Maybe this is also the same for calculating the 200days moving average also and other indicator?

      if(timeTempMinor!=symbolInfo.timeMinorPrev1){
         symbolInfo.shiftM5=iBarShift(symbolInfo.symbol,PERIOD_M5,timeBarStart1m);      
         symbolInfo.shiftM15=iBarShift(symbolInfo.symbol,PERIOD_M15,timeBarStart1m);    
         symbolInfo.shiftM30=iBarShift(symbolInfo.symbol,PERIOD_M30,timeBarStart1m);
         symbolInfo.shiftH1=iBarShift(symbolInfo.symbol,PERIOD_H1,timeBarStart1m);  
         symbolInfo.shiftH4=iBarShift(symbolInfo.symbol,PERIOD_H4,timeBarStart1m);       
         datetime timeTempMajor=iTime(symbolInfo.symbol,tradingTimeFrameMajor1,symbolInfo.shiftMajor1Current+1);          
         datetime timeTemp5M=iTime(symbolInfo.symbol,PERIOD_M5,symbolInfo.shiftM5+1);
 
         symbolInfo.rsiMinorPrev1=iRSI(symbolInfo.symbol,tradingTimeFrameEntry,14,PRICE_CLOSE,symbolInfo.shiftMinorCurrent+1);
         symbolInfo.rsiMinorPrev2=iRSI(symbolInfo.symbol,tradingTimeFrameEntry,14,PRICE_CLOSE,symbolInfo.shiftMinorCurrent+2);

         symbolInfo.atrMinorPrev1=iATR(symbolInfo.symbol,tradingTimeFrameEntry,14,symbolInfo.shiftMinorCurrent+1);    
         symbolInfo.atrMinorPrev2=iATR(symbolInfo.symbol,tradingTimeFrameEntry,14,symbolInfo.shiftMinorCurrent+1);              
         symbolInfo.ema50MinorPrev1=iMA(symbolInfo.symbol,tradingTimeFrameEntry,50,0,MODE_EMA,PRICE_CLOSE,symbolInfo.shiftMinorCurrent+1);
         symbolInfo.ma200MinorPrev1=iMA(symbolInfo.symbol,tradingTimeFrameEntry,200,0,MODE_SMA,PRICE_CLOSE, symbolInfo.shiftMinorCurrent+1); 

     }

Thank you!

Van

 
  1. Why did you post your MT4 question in the Root / MT5 General section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. Why are you calling iBarShift for timeframes you are not using?
  3. I recommend: Do not trade multiple currencies in one EA.
    1. You can't use any {MT4: predefined variables, MT5: predefined variables,}
    2. Must poll (not OnTick, unless you use specific indicators)
                The Implementation of a Multi-currency Mode in MetaTrader 5 - MQL5 Articles
    3. and usually other problems, e.g. A problem with iBarShift - MQL4 programming forum - Page 2
    4. You must handle History {MT4:4066/4073 errors: Download history in MQL4 EA - MQL4 programming forum, MT5: Timeseries and Indicators Access /  Data Access - Reference on algorithmic/automated trading language for MetaTrader 5.}
    5. Code it to trade the chart pair only. Look at the others if you must. Don't assume that Time[i] == iTime(otherPair, TF, i) always use iBarShift.
    6. Then put it on other charts to trade the other pairs. Done.
 
In future please post in the correct section
I will move your topic to the MQL4 and Metatrader 4 section.
 
Keith Watford:
In future please post in the correct section
I will move your topic to the MQL4 and Metatrader 4 section.
Thanks Keith!
 
William Roeder:
  1. Why did you post your MT4 question in the Root / MT5 General section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. Why are you calling iBarShift for timeframes you are not using?
  3. I recommend: Do not trade multiple currencies in one EA.
    1. You can't use any {MT4: predefined variables, MT5: predefined variables,}
    2. Must poll (not OnTick, unless you use specific indicators)
                The Implementation of a Multi-currency Mode in MetaTrader 5 - MQL5 Articles
    3. and usually other problems, e.g. A problem with iBarShift - MQL4 programming forum - Page 2
    4. You must handle History {MT4:4066/4073 errors: Download history in MQL4 EA - MQL4 programming forum, MT5: Timeseries and Indicators Access /  Data Access - Reference on algorithmic/automated trading language for MetaTrader 5.}
    5. Code it to trade the chart pair only. Look at the others if you must. Don't assume that Time[i] == iTime(otherPair, TF, i) always use iBarShift.
    6. Then put it on other charts to trade the other pairs. Done.

Hi Will,

Sorry the code is messy right now and I did not post the complete code so there may be some misunderstanding. I am using a single EA to trade multiple currencies and it's been working fine. Here are are what I am using in answer to your recommendation. Please let me know if it's sustainable. Here are my answer to your questions above:

2: I am using those timeframes else where in the code later.

3: I am trading multiple currencies in on EA and here's my workaround:

     1) I don't need to use predefined variables. For example, for Bid and Ask, I use the method called MarketInfo and pass in the symbol I want to get the bid/ask for. I use iHigh, iLow and etc to access bar information for individual pair and etc.

     2) I am not using OnTick. I am using OnTimer to poll every second.

     3) I am not using the strategy tester and wrote my own strategy test code within the EA and iBarShift has been working fine for me with not problem.

     4)  Good to know! I noticed that I don't get enough test data on some server and some server gave me up to 80 days of data without me having to download it.

     5) I need to trade multiple pairs because my system uses information on all the pairs to prioritize which one to trade. Its been working fine for me so far. I have a object for each pair to keep track of all the information such as current shifts for different time frames and etc.


I don't see a solution for boosting performance when calling the iRSI method. Looks like I have to live with this issue?