If statement error - statement has to be numeric (not array)

Can someone tell me why the if function fails?
Thanks.

Estrategia=0;




//Determinamos el tipo de estrategia

Canario1=Foreign("EEM","Close");
ImpCanario1=12*Canario1/Ref(Canario1,-1) + 4*Canario1/Ref(Canario1,-3) + 2*Canario1/Ref(Canario1,-6) + Canario1/Ref(Canario1,-12)-19;

Canario2=Foreign("AGG","Close");
ImpCanario2=12*Canario2/Ref(Canario2,-1) + 4*Canario2/Ref(Canario2,-3) + 2*Canario2/Ref(Canario2,-6) + Canario2/Ref(Canario2,-12)-19;

Estrategia=IIf(ImpCanario1>0 AND ImpCanario2>0,2,IIf((ImpCanario1>0 AND ImpCanario2<0) OR (ImpCanario1<0 AND ImpCanario2>0),1,0));


if (Estrategia == 2) 
{	
			Tipo="A";

}

image

@antoniomartngarca,
Estrategia is converted into an array during the multiple IIF() statements line. AmiBroker is running that code for each symbol and each date in your run.
See Understanding how AFL works.
In Linux we say, "Everything is a file." In AmiBroker it is, "[nearly] everything is an array."

1 Like

You should just DOUBLE CLICK on error message (the pale red line). This will bring you the MANUAL PAGE with description of the error AND explaination WHY.

That is proper solution to ALL ERRORS. CLICK ON THE MESSAGE!

Also it is NOT true that everything is an array. And NOT true that IIF always generates array.

IIF will output array as a result IF and ONLY IF any of arguments passed to it is already an array. The arguments that you passed to IIF are arrays.

And by all means USE THE DEBUGGER to VIEW what is inside variables!

To get better understanding of what is happening in your code and how functions work, use advice given here: How do I debug my formula?

Thanks to Thomas and Ghanson for your answers.

1 Like

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.