How to find 5% or more stretches above its 10-day MA for 3 or more days

Rule:
Buy when VIX stretches 5% or more above its 10-day MA for 3 or more days.

I have coded to find VIX above 10-day MA as below, but not sure about other conditions. Can anyone review my code and see if this can be improved and with additional rules.

VIX = Foreign( "$VIX", "C" );
VIX_MA10 = VIX > MA(VIX, 10);

Buy = VIX_MA10

Thanks for your help, I am new to AFL programming

1 Like
VIX = Foreign( "$VIX", "C" );
VIX_MA10 = VIX > MA(VIX, 10) * 1.05;

Buy = Sum(VIX_MA10, 3) == 3;
2 Likes

Thank you that worked!