Changing the ROC periods depending of the date

Hello,

For a strategy I need to change the periods of the ROC indicator
depending of the date to take in account the market rhythm change.

For instance I would like to do (not a code just to explain)
If datenum() > 1150101 then periods =10 else periods =25

But if I do so:
datenum() > 1150101 results is an ARRAY
While
CASE, IF, WHILE, FOR statements has to be Numeric or Boolean type

Concerning IIf:
periods = IIf(datenum() > 1150101, 12, 22); => give me an ARRAY while ROC() is expecting a NUMBER for the periods

Could you please tell me how to change the periods of the ROC indicator depending of the date?

Thanks in advance

[quote=“Gilles, post:1, topic:418, full:true”]
But if I do so:
datenum() > 1150101 results is an ARRAY
While
CASE, IF, WHILE, FOR statements has to be Numeric or Boolean type[/quote]

Please read the help section "Common coding mistakes"
https://www.amibroker.com/guide/a_mistakes.html

Also read "Understanding how AFL works"
https://www.amibroker.com/guide/h_understandafl.html

ROC 2nd argument expects number not array!
Read function reference guide
https://www.amibroker.com/guide/a_funref.html

periods1 = 10;
periods2 = 22;
myroc= IIf(datenum() > 1150101, ROC(C, periods1), ROC(C, periods2));
5 Likes