Techniques to detect indicator line cross

 

Hey there,

I am having a hard time to detect line crosses with MQL4. I need it to be as accurate as possible, as the human brain and eye detects it.

I have tried many techniques but all of them don't do the job accurately and fast enough.

For example see the picture below, where the three lines cross. I have thought about dividing the three EMA's values with each other, and calculating the slope. If the slope of all three lines are downwards, and the reationship of the three indicator towards another equals to more or less 1, then a crossover. Can this work?

The normal formula of if (fast EMA > slow Ema && fast EMA < slow EMA) is not working for me, I need an alternative.

Would appreciate any input to this problem.

Thanks!

 
Looks like this idea is actually working
 

i think you would have to examine each line individualy to discover exactly what is happening when they cross at first glance it would seem if you took the values of each line before they cross the highest one first crosses the other two, then the middle one crossed the lowest one, if this is true i am inclined to believe it is true but im not 100% sure that is exactly what happens as i havent studied the interactions of multiple ma lines but if it is you have the dynamics of what happens when they cross

I think what i would then do rather than try to find a highly efficient formula to calculate this in one line of code it would probably be easier to create an array to hold the value of each line then code a function to firstly compare the highest line with the other two (if the previous value of it was above them both and the current value of it is either below them both or below one of them, give it a value for doing that, something like a 1 if it crossed the middle line and then another 1 if it subsequently crosses the lower line or a 2 if it crossed them both in one tick, and put those values in the array then run a check on the middle line if its previous value was above the lower line and current value is below it you give it a value for doing that too, then when the highest line gains a value of 2 and the middle line gains a value of 1 you know the complete cross has taken place.

That might be a way to calculate for it all crossing downwards then you would have to do the reverse to detect an upwards cross I'm not saying that would definately work but it might be a starting point towards defining a function to do that.

Also you could take a look at this indicator to see how he did it: 3MA cross with alert https://www.mql5.com/en/code/7438

 

SDC, thanks for the help! I really appreciate it.

What I tried yesterday is to calculate two line crosses, and if more than three two line crosses were valid in one bar then that would count as a three line cross, but that did not work for all the situations.

 
I looked at that indicator, it is not accurate enough, unfortunately
 
Jeez don't know how I am going to do this accurately
 
What makes this even more difficult is the fact that in a sideways trend the lines are on top of each other, and that can also go through as a cross. The code must ignore such a situation
 

Hi Saidar,

Are you trying to make this an indicator? or simply put the condition to be calculated in EA?

 

Hey cameofx,

Actually it does not matter, I want to use it for both. If I use an indicator I wont be alerted with false alerts, if I use an EA, well, then it will be more profitable.

 

you didnt like my idea with the array ?

 
Saidar:
What makes this even more difficult is the fact that in a sideways trend the lines are on top of each other, and that can also go through as a cross. The code must ignore such a situation

i came across that too when i was figuring out MA crosses the trouble is the end of a sideways move is often the best cross of all the problem is how to know when it is the end
Reason: