mql4 passing an dynamic array of class objects to a function

 
H‌i All,

‌I am a self taught mql4 hack needing a bit of assistance to get a complex (to me anyway) data type defined - and have been trying for several nights. A bit of help would be greatly appreciated. I am writing an EA to apply a trading methodology that uses a combination of M1, M5 and M15 time frames. The EA is written for M1 charts - but keeps tabs on what the indicators in M5 and M15 charts would look like. Each time frame is represented in a Dynamic Array of Pointers to Class objects (CEvents).


‌TArrayPtr   <CEvents>   M1PtrArray;

TArrayPtr   <CEvents>   M5PtrArray;

TArrayPtr   <CEvents>   M15PtrArray;

The timeframes operate quite independently and for trading logic reasons would prefer to keep them in separate arrays. W‌hen a signal occurs in any timeframe, I add the signal to the appropriate time frame array. These can become quite large (>2000 entries) - hence use of dynamic arrays.

CEvents *ptr = new CEvents();   // create the class object,

M1PtrArray.Append(ptr); // Append this to the correct array (could be any combination of M1, M5 and M15)

ptr.Initialise(M1PtrArray); // Updates a bunch of metadata on the last CEvent object in the array by calling the Initialize method:

M‌y challenge is that the Initialise() method needs to reference properties in the previous CEvent in the same array and this is not accessible unless I pass a reference to the array. I‌ am struggling to correct define this ...? A bit beyond my depth.

W‌ould greatly appreciate the insight I am missing.

H‌ave attached a minimal version with the issues exposed (does not compile) .

T‌hank you in advance,

L‌ex



Files:
PublicEA.mq4  2 kb
 
lex2pb: M‌y challenge is that the Initialise() method needs to reference properties in the previous CEvent in the same array and this is not accessible unless I pass a reference to the array.
Pass what is required, only what is required. The array is not required. Ask TArrayPtr for the previous element and pass that as a reference.
 
whroeder1:
Pass what is required, only what is required. The array is not required. Ask TArrayPtr for the previous element and pass that as a reference.

I had rules out passing the pointer to the previous element as the class library does not know which Array it was working with. However as you have correctly pointed out - that does not actually matter ;~)

‌Thanks you for taking the time to respond. I will keep you in the loop on the results of the bot ;) Initial forward results are very promising.

T‌hx, Lex

Reason: