**laplacianlab:**

Hi there MQL5 experts!,

I recently created a very lightweight indicator (4 lines of code but is a bit slow, however) which takes the SMA from any given symbol and divides by the SMA from any other. It is something like a SymbolA-SymbolB ratio.

My onCalculate's most slow part is the following, this is the part i'd like to optimize:

Then I do this:

The rest of the algorithm is very easy!, it just loops data and calculate the ratio this way, this is the idea:

I know you can optimize onCalculate methods. I've done some research and found the solution in algorithms which calculate themselves the data, a very simple example would be SMA. However I think this is different because I want to take data already calculated from SMA function, and "the problem" here is that the number of rates of any pair of symbols will be always different, in principle.

Can you help me to optimize this idea's algorithm? I need to optimize this part, thks in advance!:

If I understood well, this code:

if(CopyBuffer(MASymbolAHandler,0,0,rates_total,MASymbolABuffer)<=0) return(0);

is executed on each tick, so of course it's very slow as you copy all the data on each tick. You don't have to recalculate your ratio for all bars on each tick.

Anyway, it will be more easy to help you if you post full code.

Hi there MQL5 experts!,

I recently created a very lightweight indicator (4 lines of code but is a bit slow, however) which takes the SMA from any given symbol and divides by the SMA from any other. It is something like a SymbolA-SymbolB ratio.

My onCalculate's most slow part is the following, this is the part i'd like to optimize:

Then I do this:

The rest of the algorithm is very easy!, it just loops data and calculate the ratio this way, this is the idea:

I know you can optimize onCalculate methods. I've done some research and found the solution in algorithms which calculate themselves the data, a very simple example would be SMA. However I think this is different because I want to take data already calculated from SMA function, and "the problem" here is that the number of rates of any pair of symbols will be always different, in principle.

Can you help me to optimize this idea's algorithm? I need to optimize this part, thks in advance!: