Hi everyone. I am trying to write a function that tells me when two moving averages cross over. For some reason my function always returns 0. Here is part of my code:
int mafast1=iMA(NULL,0, MAPeriod1, 0, MODE_EMA, PRICE_CLOSE, 1);
int maslow1=iMA(NULL,0, MAPeriod2, 0, MODE_EMA, PRICE_CLOSE, 1);
int mafast2=iMA(NULL,0, MAPeriod1, 0, MODE_EMA, PRICE_CLOSE, 2);
int maslow2=iMA(NULL,0, MAPeriod2, 0, MODE_EMA, PRICE_CLOSE, 2);
int macross=macross(mafast1, maslow1, mafast2, maslow2);
int macross(int fast1, int slow1, int fast2, int slow2)
{
if(fast1>slow1&&fast2<slow2)
{
return(1);
}
else if(fast1<slow1&&fast2>slow2)
{
return(-1);
}
else
return(0);
}
I think I am using the iMA function wrong or something; please help me if you know why macross always returns 0. Thank you in advance.