double v1,v2,v1_prev,v2_prev;
bool found=false;
for (int i=0;i<Bars-1;i++) {
v1=iMA(Symbol(),Period(),62,0,MODE_EMA,PRICE_CLOSE,i)
v1_prev=iMA(Symbol(),Period(),62,0,MODE_EMA,PRICE_CLOSE,i+1)
v2=iMA(Symbol(),Period(),800,0,MODE_SMA,PRICE_CLOSE,i)
v2_prev=iMA(Symbol(),Period(),800,0,MODE_SMA,PRICE_CLOSE,i+1)
if ((v1>v2 && v1_prev<v2_prev) || (v1v2_prev)) {
found=true;
break;
}
}
int time = (Time[0] - Time) / 60;
if (!found) { time = -1; }
Excuse the code, I'm at work, but that should basically be what you need.
"int time" should be equal to the number of minutes since the last crossover. If you want the number of seconds, just get rid of the "/ 60" If time is -1, then it hasn't seen a crossover.

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello,
I need someone to program an EA that shows me how many bars have passed since a MA cross. For example, if the 62 EMA crosses the 800 SMA I want to be able to glance at my screen and see how many bars have passed since that cross.
Thanks,
Todd