amibroker

How to set this array based on 2 other arrays in Amibroker?


I have these 2 arrays signal_arr and value_arr in Amibroker. From these 2 arrays, I want to output an array output_arr such that when signal_arr is 1, it will follow the value of value_arr. When signal_arr is 0, output_arr will retain the value of value_arr when signal_arr was last 1.

This is best illustrated by an example.

signal_arr =  [ 1   0   0   0   1   0   0   1   0   0 ]
value_arr =   [0.5 0.6 0.4 0.2 0.8 0.7 0.6 0.2 0.3 0.4]
output_arr =  [0.5 0.5 0.5 0.5 0.8 0.8 0.8 0.2 0.2 0.2]

Solution

  • Use ValueWhen.

    output_arr =  ValueWhen(signal_arr, value_arr);