trend identifier(crossing averages) EA please help
Do not double post.
I have deleted your duplicate post.
Use the insert code button (Alt + S) when posting code. I have edited your post for you this time.
This code only executes when a new bar emerges. In this case the iMA values that you get for shift 0 and 1 are almost identical. You need to look at the last two bars like so:
double mediumMovingAvg =iMA(NULL,0,20,1,MODE_EMA,PRICE_CLOSE,1); double lastMediumMovingAvg=iMA(NULL,0,20,1,MODE_EMA,PRICE_CLOSE,2); double fastMovingAvg =iMA(NULL,0, 8,0,MODE_EMA,PRICE_CLOSE,1); double lastFastMovingAvg =iMA(NULL,0, 8,0,MODE_EMA,PRICE_CLOSE,2); double slowMovingAvg =iMA(NULL,0,80,0,MODE_SMA,PRICE_CLOSE,1); double lastSlowMovingAvg =iMA(NULL,0,80,0,MODE_SMA,PRICE_CLOSE,2);
And then you check for a double upcross for long and a double downcross for short. That is, only when fast MA crosses medium MA and fast MA crosses slow MA you raise the alarm, how often is this to happen within a single tick?
I'd go with something like that:
if(lastFastMovingAvg<lastMediumMovingAvg && fastMovingAvg>mediumMovingAvg // up cross && mediumMovingAvg>slowMovingAvg)
and similar for down trend:
if(lastFastMovingAvg>lastMediumMovingAvg && fastMovingAvg<mediumMovingAvg // down cross && mediumMovingAvg<slowMovingAvg)
Here is the code below...