Discussion of article "Complex indicators made easy using objects"

 

New article Complex indicators made easy using objects has been published:

This article provides a method to create complex indicators while also avoiding the problems that arise when dealing with multiple plots, buffers and/or combining data from multiple sources.

The final result of the indicator looks like this:


Author: Manuel Alejandro Cercos Perez

 
I thought it meant graphical objects - I was surprised and started to look. It turned out to be class objects) What is the novelty?
 
Dmitriy Skub class objects) And what is new?

Just a good approach to implementation in the article, nothing new, just not a bad solution to the problem.

 

Your article was very good 😁 ... but as you mentioned, there is a slight problem involved in the performance issue. Most of the time, it won't affect anything, and you can live with it without any problems. But at times of great volatility, the system may crash or become very slow, due to the number of calls that OnCalculate may receive. But the problem is not with the function, but with the interactions that take place within it. Because with each call, MetaTrader will be forced to read the buffer of the indicators, and if the number is large, there could be problems. One way to solve this would be to use a call to OnTime, in order to lighten the load a little, since the calls would be executed not at each calculation event, but over a predefined period of time. If the idea is to operate manually, or semi-automatically, this wouldn't be a problem, as each calculation could be carried out within 200 milliseconds, for example. But it's not very suitable to use OnTime events in indicators, because of the possibility of them influencing the calculation thread, especially when the market is very volatile. One way of doing this would be to force the calculations in OnCalculate itself, so that you don't need to make CopyBuffer calls. Another thing that will reduce processor consumption by a few machine cycles is to modify the following line in the OnCalculate function:

int OnCalculate(const int rates_total, 
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
//---
   int limit = MathMax(0, prev_calculated-1);

for this one:

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
//---
   int limit = (prev_calculated <= 0 ? 0 : prev_calculated - 1);

It may not seem like much, but using the ternary operator in this case will be more efficient than making a call to the function. These small details make a big difference in times of high volatility ... 😁👍