Moving Average Conditions

I am trying to come up with a simple trend model:
v1 = MA(BARS=8, CALC=Close);
v2 = MA(BARS=21, CALC=Close);
v3 = MA(BARS=89, STYLE=Exponential, CALC=Close);

if v1 > v2 and v2 > v3 = 1
if v1 > v2 and v2 < v3 = 2
if v1 < v2 and v2 > v3 = 3
if v1 < v2 and v2 < v3 = 4

What would be the best way to handle these if statements?

Thanks,
Dan

Hi Dan,

For IF statement logic see this post: https://forum.optuma.com/topic/using-the-if-function-to-create-a-ranking-value/

In your example you need to nest two IF statements inside of the first:

v1 = MA(BARS=8, CALC=Close);
v2 = MA(BARS=21, CALC=Close);
v3 = MA(BARS=89, STYLE=Exponential, CALC=Close);

R1 = v1>v2 and v2>v3;
R2 = v1>v2 and v2<v3;
R3 = v1<v2 and v2>v3;
R4 = v1<v2 and v2<v3;

IF(R1, 1,IF(R2, 2,IF(R3, 3, 4)))