Suggestions For MQL5's Lack Of Support for Array Pointers?

 

Hi

If an indicator uses multiple classes and functions, as one might have if writing a non-simplistic indicator, then the lack of support for array pointers makes it necessary to pass references to data arrays from class to class and function to function for every class and function that needs to process price data - starting from OnCalculate(). Is there really no other way?

I have tried using CopyOpen(), CopyHigh(), CopyLow(), CopyClose() instead to fetch price data, but this is apparently too slow for Strategy Tester.

Thank you.

 
Robert Andrew Northen:

Hi

If an indicator uses multiple classes and functions, as one might have if writing a non-simplistic indicator, then the lack of support for array pointers makes it necessary to pass references to data arrays from class to class and function to function for every class and function that needs to process price data - starting from OnCalculate(). Is there really no other way?

I have tried using CopyOpen(), CopyHigh(), CopyLow(), CopyClose() instead to fetch price data, but this is apparently too slow for Strategy Tester.

Thank you.

There is no difference between a reference and an array pointer in MQL.

What are you expecting as "other way" ?

 
Alain Verleyen #:

There is no difference between a reference and an array pointer in MQL.

What are you expecting as "other way" ?

I guess the lack of possibility to have a member variable inside a struct or class that is "pointing" to the array.

If mql would support reference variables, it would be possible to pass the array as reference to the constructor and store it in a member variable. This way the object would be attached to the external array.

Also pointer arithmetic like in c/c++ is not available in mql.

If that were possible, we could create objects that do fancy stuff with externally assigned memory.

Maybe that would be a feature we could bump to ask for as enhancement to the language. Have references as variables.



 
Alain Verleyen #:

There is no difference between a reference and an array pointer in MQL.

What are you expecting as "other way" ?

Thanks Alain for your reply.

OK, suppose you're writing a complex indicator, one that requires many functions and classes, and you try to follow best programming practices. How would you give access to your various functions and classes that require the price data, the OHLC and time arrays passed to your indicator in OnCalculate()? By passing them as arguments from class to class and function to function?

Rob

 
Robert Northen #:

Thanks Alain for your reply.

OK, suppose you're writing a complex indicator, one that requires many functions and classes, and you try to follow best programming practices. How would you give access to your various functions and classes that require the price data, the OHLC and time arrays passed to your indicator in OnCalculate()? By passing them as arguments from class to class and function to function?

Rob

Yes it's exactly what I am doing and there is no problem with it.
 
Dominik Christian Egert #:
I guess the lack of possibility to have a member variable inside a struct or class that is "pointing" to the array.

If mql would support reference variables, it would be possible to pass the array as reference to the constructor and store it in a member variable. This way the object would be attached to the external array.

I know but it's recurring issue triggering from time to time since years.

Also pointer arithmetic like in c/c++ is not available in mql.


If that were possible, we could create objects that do fancy stuff with externally assigned memory.

You will never have that in MQL.
Maybe that would be a feature we could bump to ask for as enhancement to the language. Have references as variables.
In the meantime we have to deal with how it is, not how we would like it to be.
 
Alain Verleyen #:
I know but it's recurring issue triggering from time to time since years. You will never have that in MQL.
In the meantime we have to deal with how it is, not how we would like it to be.
have that

Up until now, I found almost for everything a solution. There are hard limits, of course.

And there is this Wishland.....
Reason: