Can you read all buffers instead of reading them one by one using iCustom() ?

 

I am looking to use PipFinite's Trend Laser indicator. This indicator has multiple buffers. Reading them one by one is so slow that I can only test one day's data in 8 hours!

Is there a way to read all the buffers into some sort of an array and then process that array instead of calling iCustom multiple times?

 

One way to do it is to read iCustom once per bar, example :

static datetime mybarcheck = EMPTY_VALUE;

if(Time[0]!=mybarcheck)
{

//read i custom here, and use value

mybarcheck = Time[0];

}

Other way is to read indicator at every X tick, code is similar.

Next one is to check iCustom on every new minute. For that purpose you can use Minute() function instead of Time[0] variable, and code is the same.

But the best option is to ask author of the indicator to fix lagging indicator and make it work faster :)
 

 

Thanks Bart. I will speak with the author.

 
Ashish Kulkarni:

I am looking to use PipFinite's Trend Laser indicator. This indicator has multiple buffers. Reading them one by one is so slow that I can only test one day's data in 8 hours!

Is there a way to read all the buffers into some sort of an array and then process that array instead of calling iCustom multiple times?

Short answer : No.

Only if you have the source code you can implement some other ways. But usually it's not needed, and the indicator just need to be improved as Bartlomiej said.

 
alphatrading: Not possible without having the source code. With source code you can pass an array pointer to the indicator called by iCustom(). Then the indicator can pass back whatever you want, not only single buffer values.

Array pointer via iCustom() parameters???? Since when????

One cannot define arrays as input parameters for an Indicator. The only time, this rule can be "broken" in iCustom() is only in MQL5 when you pass a handle to another indicator for the OnCalulation() event handler for Applied Price instead of OHLC values.

 
alphatrading:

At least since 2006 and build 225. Just because there is no such command or official documentation doesn't mean it's not possible. Just look into the old DLL source code distributed by Metaquotes to get a glimpse of how to get an array pointer. And I never said to pass arrays as input parameters. Just read carefully.

For example this is what I pass to every indicator called by iCustom(). In MQL it's an array,in C it's a struct. I pass apointer to it via iCustom() and the indicator can communicate withthe EA and passes back whatever I want. This way for example I get runtime and error status back and can act in the EA which wouldn't be possible with standard built-in MQL commands.

The last parameter to my iCustom() calls is always an array pointer.

See also https://github.com/rosasurfer/mt4-expander/blob/master/header/struct/xtrade/ExecutionContext.h

OK! So it apparently can be done (on MT4), but I would not recommend anyone use it and even less for a newbie like the OP.

It is unorthodox, undocumented, requires DLL calls, requires altering the Custom Indicator as well, and offers no guarantee of it working in the future.

It will also not work on the MQL Virtual Hosting nor will it work for Market products!

Yes, it's a possible solution, but only for a very "niche" and sophisticated requirement for advanced coders.

 
Fernando Carreiro:

OK! So it apparently can be done (on MT4), but I would not recommend anyone use it and even less for a newbie like the OP.

It is unorthodox, undocumented, requires DLL calls, requires altering the Custom Indicator as well, and offers no guarantee of it working in the future.

It will also not work on the MQL Virtual Hosting nor will it work for Market products!

Yes, it's a possible solution, but only for a very "niche" and sophisticated requirement for advanced coders.


When it comes to MT4, there was even an article about passing arrays between indicators.

 

As a partial workaround for MT5 one could mention the second variant of OnCalculate handler:

int OnCalculate(const int rates_total,      // size of the price[] array 
                const int prev_calculated,  // bars handled on a previous call 
                const int begin,            // where the significant data start from 
                const double& data[]        // array to calculate 
);

An indicator with such handler can be applied on another indicator and receive its buffer's elements as entire array in the data parameter.


 
Stanislav Korotky: As a partial workaround for MT5 one could mention the second variant of OnCalculate handler: An indicator with such handler can be applied on another indicator and receive its buffer's elements as entire array in the data parameter.

Actually, I did touch that subject but only briefly:

Forum on trading, automated trading systems and testing trading strategies

Can you read all buffers instead of reading them one by one using iCustom() ?

Fernando Carreiro, 2017.09.22 20:32

Array pointer via iCustom() parameters???? Since when????

One cannot define arrays as input parameters for an Indicator. The only time, this rule can be "broken" in iCustom() is only in MQL5 when you pass a handle to another indicator for the OnCalulation() event handler for Applied Price instead of OHLC values.

 
Fernando Carreiro:

Actually, I did touch that subject but only briefly:

Sorry, I don't understand this wording: "pass a handle to another indicator for the OnCalulation() event handler for Applied Price instead of OHLC values". Where and how to pass a handle? How do you obtain the handle?

 
Stanislav Korotky: Sorry, I don't understand this wording: "pass a handle to another indicator for the OnCalulation() event handler for Applied Price instead of OHLC values". Where and how to pass a handle? How do you obtain the handle?

It is the exact same thing that you just expressed in your own post except done in code instead of visually on the chart.

I've never used it myself, but there was a thread recently discussing it. I will try doing a search to see if I can find it and reference it here.

EDIT: Here is the quote from the documentation:

To receive values of a custom indicator from other mql5 programs, the iCustom() function is used, which returns the indicator handle for subsequent operations. You can also specify the appropriate price[] array or the handle of another indicator. This parameter should be transmitted last in the list of input variables of the custom indicator.

When you call a custom indicator from mql5-program, the Applied_Price parameter or a handle of another indicator should be passed last, after all input variables of the custom indicator.

// Instead of an Applied Price, you can pass an Indicator Handle!
int handle_customMA=iCustom(Symbol(),PERIOD_CURRENT, "Custom Moving Average", 13, 0, MODE_EMA, PRICE_TYPICAL);
Reason: