Why can't I do this?

Why does this work:


But this gives an error:


You need to update AmiBroker. StDev does allow variable period since AB 6.19.
As for why Stdev returns error in your older AB version:
Cum() returns type array and MA() function allowing type number or array as period but StDev() expecting period to be type number only (in your older AB version).

In general native indicators allowing variable period are listed here
All others don't.

But to allow any function to allow variable period read here (especially last two functions)

Hint: you would have to replace ROC by StDev in first function of last code.