Is there any problem about using ArraySetAsSeries() inside OnCalculate()?

 

I dont know if this is the proper way of indexing the OnCalculate() standard arrays (see image).

Thks


 
  1. Please don't post image of code. When you post code please use the CODE button (Alt-S)! (For large amounts of code, attach it.) Please edit your (original) post.
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  2. The arrays passed have no direction. It is up to you how you want the reference them.
 
whroeder1:
  1. Please don't post image of code. When you post code please use the CODE button (Alt-S)! (For large amounts of code, attach it.) Please edit your (original) post.
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  2. The arrays passed have no direction. It is up to you how you want the reference them.

Sorry, didn't know about the images. I'll not do it again.

Thank you.

 
Daniel Arges:

Sorry, didn't know about the images. I'll not do it again.

Thank you.

The arrays don't have a direction, but the series data DOES -- based on the value of the array's series flag. Just to be clear we are talking about the typical indexing of an array. Arrays are typically indexed from left (first element) to right (last/most recent element). The following example represents the array's series flag being set to false (MQL5 default)

New series data gets appended to the end and always has a higher index than the last/older bar. This is how you index data when series=false
[0, 1, 2, 3, 4]
[0, 1, 2, 3, 4, 5] <- new series data appended to array

In those regards, when you set the series flag to true (default for MQL4) then new data is inserted into the array at index 0 and the remainder of the data is shifted over. Think of it like a queue. 

New series data gets pushed into the queue; entire array shifts right.
[0, 1, 2, 3, 4]
new series inserted into array -> [0, 1, 2, 3, 4, 5]

So just a quick visual recap:

series=true (MQL4 default)
[most_recent_data(index=0) ----> oldest_data(index=n)]

series=false(MQL5 default)
[oldest_data(index=0) ----> most_recent_data(index=n)]