What is the most efficient way to compare Buffers?

 

In my EA I do a lot of comparisons among Custom Indicators' Buffers.

Just to make it easier for understanding, consider the comparison like:

if(MA[1] > MA[2] && MA[2] > MA[3] && MA[3} < MA[4])
{
        if(RSI[1] > UpperLevel && RSI[1] > RSI[2])  {
                ...do something  } else {
                ...do another thing }
}


So, considering the two above Indicators, would it be faster (and memory efficient) to continue this approach, or to adopt the following procedure?

  1. To create custom Buffers within each indicator, loading (as an example) a BOOL value;
  2. Make the above comparison inside the CALCULATE() routine and load the custom buffer with the result;
  3. Check these buffers in my EA.

Using the sample above, I would have this code in my EA:
CopyBuffer(MA_handle, 3, 0, 3, MA_CompareArray);
CopyBuffer(RSI_handle, 3, 0, 3, RSI_CompareArray);

if(MA_CompareArray[0] == true && RSI_CompareArray[0] == true)
{                ...do something  } else {
                ...do another thing }
}


I appreciate any light on this.

 
AliceRioBR:

In my EA I do a lot of comparisons among Custom Indicators' Buffers.

Just to make it easier for understanding, consider the comparison like:


So, considering the two above Indicators, would it be faster (and memory efficient) to continue this approach, or to adopt the following procedure?

  1. To create custom Buffers within each indicator, loading (as an example) a BOOL value;
  2. Make the above comparison inside the CALCULATE() routine and load the custom buffer with the result;
  3. Check these buffers in my EA.

Using the sample above, I would have this code in my EA:


I appreciate any light on this.

In the second case, your indicator calculations will be in another thread, therefore, and depending on the charts thread, these indicators are executed, you might have slower calculation results. But you will have under all circumstances multi-threadding synchronisation tasks to take care of.

Since the first approach is (in CPU-terms) very slim, I suggest you stay with that.

All indicators on a chart run in the same thread, as far as I am aware, this is also true for indicators loaded via EA iCustom. All charts of one symbol share the same thread. Depending on what's going on in this thread, your indicator might be "late" for your EA.

As the EA runs within a separate thread, doing the calculation there, will ensure timely results and chronologically correct execution without the need to synchronize with external data sources.


 
Dominik Christian Egert #:
In the second case, your indicator calculations will be in another thread, therefore, and depending on the charts thread, these indicators are executed, you might have slower calculation results. But you will have under all circumstances multi-threadding synchronisation tasks to take care of.

Since the first approach is (in CPU-terms) very slim, I suggest you stay with that.

All indicators on a chart run in the same thread, as far as I am aware, this is also true for indicators loaded via EA iCustom. All charts of one symbol share the same thread. Depending on what's going on in this thread, your indicator might be "late" for your EA.

As the EA runs within a separate thread, doing the calculation there, will ensure timely results and chronologically correct execution without the need to synchronize with external data sources.


Thank you Dominic, your answer enlighted me a lot!

Exactly because indicators run in their thread, I supposed that transferring the calculation to their buffers would get faster results and better efficiency.