Hi,
If I used an array to log the bar index and price of a pair of MAs if they were to cross, is it possible to use the array function to find the price of the previous crossing, if so, how would I write it?
TIA
RR
Arrays are not historicized, so you cannot see the value retained the previous bar for element, say 5, of the array:
a = $MyArray[5][1] //not allowed
x = $MyArray[5]
a = x[1] //allowed, but you need a variable for each element of the array
You need to store each crossover in an array element:
Once Count = 0
If close CROSSES OVER average[20] then
Count = Count + 1
$CrossBar[Count] = barindex
Endif
Count will retain the number of crossovers and each $CrossBar[] element will retain the barindex of the crossover. You
Thank you very much, Roberto.
RR
Sorry for the final YOU, I had nothing more to write.
I must have have pressed some unwanted dictionary word on my mobile 🙂
If you only want to know the price and barindex of the last crossing then you don’t need to use array variables. However if you want to store the price or barindex of all historical crosses then you do need to use array variables.