iMA calculation weird behavior

 

Hi,

I am finding some weird behavior with my following code. The MA calculation seems to be wrong sometimes for Period_D1. The behavior is not consistent. I find it working fine most times. Am I doing something wrong here. I have given the function definition of isTrendMaSatisified which calculates the iMA. This function is called for different periods like Period_H1, Period_H4 and Period_D1. I have given one sample output where the iMA is wrong for Period_D1. I have highlighted it. Has anyone seen such behavior? Would it be possible that the local variables of the function ma5 & ma12 are not cleared correctly? I am not able to diagnose this issue. Any help is highly appreciated.


2009.05.25 15:32:33 find_currs_ma_hmp AUDCADFXF,H1: Debug: str = CADJPYFXF look for signal = 0 period = 60 (ma5,ma12) = (84.3216,84.3154) period = 240 (ma5,ma12) = (84.2966,84.0927) period = 1440 (ma5,ma12) = (84.4478,84.5274)

2009.05.25 15:35:42 find_currs_ma_hmp AUDCADFXF,H1: Debug: str = CADJPYFXF look for signal = 0 period = 60 (ma5,ma12) = (84.3316,84.32) period = 240 (ma5,ma12) = (84.3066,84.0974) period = 1440 (ma5,ma12)= (83.872,83.3324)


bool
isTrendMaSatisified(string str, int type, int period)
{
double ma5 = iMA(str,period,5,0,MODE_EMA,PRICE_CLOSE,0);
double ma12 = iMA(str,period,12,0,MODE_EMA,PRICE_CLOSE,0);
debugStr = StringConcatenate(debugStr,"period = ",period,"mas = (",ma5,",",ma12,") ");
if (type == OP_BUY) {
return (NormalizeDouble(ma5,5) > NormalizeDouble(ma12,5));
}

else if (type == OP_SELL) {
return (NormalizeDouble(ma5,5) < NormalizeDouble(ma12,5));
}
return (0);
}


Thanks,
Suresh.

 
g123sk :

Hi,

I am finding some weird behavior with my following code. The MA calculation seems to be wrong sometimes for Period_D1. The behavior is not consistent. I find it working fine most times. Am I doing something wrong here. I have given the function definition of isTrendMaSatisified which calculates the iMA. This function is called for different periods like Period_H1, Period_H4 and Period_D1. I have given one sample output where the iMA is wrong for Period_D1. I have highlighted it. Has anyone seen such behavior? Would it be possible that the local variables of the function ma5 & ma12 are not cleared correctly? I am not able to diagnose this issue. Any help is highly appreciated.


2009.05.25 15:32:33 find_currs_ma_hmp AUDCADFXF,H1: Debug: str = CADJPYFXF look for signal = 0 period = 60 (ma5,ma12) = (84.3216,84.3154) period = 240 (ma5,ma12) = (84.2966,84.0927) period = 1440 (ma5,ma12) = (84.4478,84.5274)

2009.05.25 15:35:42 find_currs_ma_hmp AUDCADFXF,H1: Debug: str = CADJPYFXF look for signal = 0 period = 60 (ma5,ma12) = (84.3316,84.32) period = 240 (ma5,ma12) = (84.3066,84.0974) period = 1440 (ma5,ma12)= (83.872,83.3324)


bool
isTrendMaSatisified(string str, int type, int period)
{
double ma5 = iMA(str,period,5,0,MODE_EMA,PRICE_CLOSE,0);
double ma12 = iMA(str,period,12,0,MODE_EMA,PRICE_CLOSE,0);
debugStr = StringConcatenate(debugStr,"period = ",period,"mas = (",ma5,",",ma12,") ");
if (type == OP_BUY) {
return (NormalizeDouble(ma5,5) > NormalizeDouble(ma12,5));
}

else if (type == OP_SELL) {
return (NormalizeDouble(ma5,5) < NormalizeDouble(ma12,5));
}
return (0);
}


Thanks,
Suresh.

 
You may be able to solve your "weird" behavior problem using the iMA function by specifying a shift of 1 instead of 0. My experience with this function is that when you use 0 shift, your MA calculation is being reshaped at every tick, since Close(0) is constantly moving with the tick trades until the next period bar is reached. By using 1 shift, your MA calculation should track better and not be giving false indications of when to trade.