Calculate if an indicator's value has risen over x periods

328 Views Asked by At

I am looking for a function or way to calculate if a value from an indicator has risen over x periods. I'm aware of the rising() and falling() built in functions, but when plugging in an indicator it doesn't seem to be working. It appears those functions are only for price. Are there any resources that may help me figure this out? For an example, let's say I want to see if the ema has been steadily rising for the last 10 periods.

1

There are 1 best solutions below

0
On

So how specific are you wanting to be? If you want to see if the EMA has been up in every period, you could do something like:

f_isAlwaysUp(src, periods) =>
    bool success = true
    for i = 0 to periods - 1 // would need to update this if your source does not start with index 0
        if src[i] >= src[i-1]
            success := false
            break
    success

Or if you're just wanting to see if it's higher than it was 10 periods ago, just ema > ema[10].