# How to use if else statement with other indicator fucntions

#### mutualguru

##### Active Member
I have a code like this

Code:
``````mrsi=RSIa(C,14);
ma1=MA(C,200);
if((mrsi >70) AND C>ma1 )
var=1;
else
var=0;

if ( var == 1 )
{
Do some stuff
}
else
{
}``````
The problem is when i execute this i am getting this error

Error 6. Condition in IF, WHILE, FOR statements has to be Numeric or Boolean type. You can not use array here, please use [] (array subscript operator) to access array elements

Any idea how to solve this error

#### KelvinHand

##### Well-Known Member
I have a code like this

Code:
``````mrsi=RSIa(C,14);
ma1=MA(C,200);
if((mrsi >70) AND C>ma1 )
var=1;
else
var=0;

if ( var == 1 )
{
Do some stuff
}
else
{
}``````
The problem is when i execute this i am getting this error

Error 6. Condition in IF, WHILE, FOR statements has to be Numeric or Boolean type. You can not use array here, please use [] (array subscript operator) to access array elements

Any idea how to solve this error
mrsi and ma1 are array cannot use If...else statement.

PHP:
``````mrsi=RSIa(C,14);
ma1=MA(C,200);

//--Method 1
var = mrsi >70 AND C>ma1;

//==Method 2
var = iif( mrsi >70 AND C>ma1, 1, 0);``````

If...else can only use in single element such as Boolean or Numeric Number.
such as in a looping:

PHP:
``````mrsi=RSIa(C,14);
ma1=MA(C,200);

var=null;
for(i=0; i<Barcount; i++)
{
if (mRSI[i]>70 && c[i]>ma1[i])
var[i]=1;
else
var[i]=0;
}``````
OR

Example of input from Param...() possible of using if...else
PHP:
``````     me = Paramlist("Select w", "mutual|guru|mutualguru|");

if (me == "mutual")
{
Title = "Mutual Friend";

}
else if (me == "guru")
{
Title = "Amibroker Guru";

}
else
{

Title = "Mutual Friend and Amibroker Guru";
}``````

Last edited:

#### mutualguru

##### Active Member
Thank you for the quick reply I have changed my previous code to your 2nd method

Code:
``````mrsi=RSIa(C,14);
ma1=MA(C,200);
var = iif( mrsi >70 AND C>ma1, 1, 0);

if ( var == 1 )
{
Do some stuff
}
else
{
}``````
Here also the same error at if ( var == 1 ) . I cant use IIF here because its a multiline code