i have a problem with Ema of Cross in the mql4.
i want to konw how could i realize when the two Ema lines had crossd then appear a sylbol in the chart like following picture.
thanks a lot
In essence you must find state of (b-y) at a bar and state of (b-y) at bar+1 to be oposite.
b[]=Blue y[]=Yellow i = bar FirstCrossing=0; SecondCrossing=0; if ((b[i+1]-y[i+1]) <=0 && (b[i]-y[i])>0) FirstCrossing=1; i--; to second crossing if ((b[i+1]-y[i+1]) >=0 && (b[i]-y[i])<0) SecondCrossing=1; , , , ,
bbbbbbbyyyyyyyyy
yyyyyyyybbbbbbbb
............^
Ideal cross
Please Notice "=0" it may be placed at i+1 or i or both depends on your need. However, cross point may take several bars.
bbbbbbb00000yyyyyy
yyyyyyyy00000bbbbbb
............^
....................^
Possible crosses detected.
This will be considered as cross too
bbbbbbb00000bbbbbbb
yyyyyyyy00000yyyyyyyy
The actual code will depend on what you want.
Set the buffers to type arrow (SetIndicatorStyle, SetIndicatorArrow).
Then:
ema1= iMa(......, shift); ema2= iMa(......, shift); ema1x= iMa(......, shift+2); ema2x= iMa(..... , shift+2), diffnow= ema1 - ema2; diffprev= ema1x - ema2x; if (diffnow>0 && difprev<0) { ExtMapBufLong[shift+1]= Low[shift+1]; } if (diffnow<0 && difprev>0) { ExtMapBufShort[shift+1]= High[shift+1]; }
Not perfect but a good approximation.
Markus
i have a problem with Ema of Cross in the mql4.
i want to konw how could i realize when the two Ema lines had crossd then appear a sylbol in the chart like following picture.
thanks a lot
In essence you must find state of (b-y) at a bar and state of (b-y) at bar+1 to be oposite.
b[]=Blue y[]=Yellow i = bar FirstCrossing=0; SecondCrossing=0; if ((b[i+1]-y[i+1]) <=0 && (b[i]-y[i])>0) FirstCrossing=1; i--; to second crossing if ((b[i+1]-y[i+1]) >=0 && (b[i]-y[i])<0) SecondCrossing=1; , , , ,
bbbbbbbyyyyyyyyy
yyyyyyyybbbbbbbb
............^
Ideal cross
Please Notice "=0" it may be placed at i+1 or i or both depends on your need. However, cross point may take several bars.
bbbbbbb00000yyyyyy
yyyyyyyy00000bbbbbb
............^
....................^
Possible crosses detected.
This will be considered as cross too
bbbbbbb00000bbbbbbb
yyyyyyyy00000yyyyyyyy
The actual code will depend on what you want.
thank u for your answer
i think the "cross" same with to you.
I)bbbbbbbyyyyyyyyy
yyyyyyyybbbbbbbb
............^
corss
II)bbbbbbb00000yyyyyy
yyyyyyyy00000bbbbbb
....................^
cross
III)bbbbbbb00000bbbbbbb
yyyyyyyy00000yyyyyyyy
................................
not cross
Create a custom indicator with two ExtMapBuffers.
Set the buffers to type arrow (SetIndicatorStyle, SetIndicatorArrow).
Then:
ema1= iMa(......, shift); ema2= iMa(......, shift); ema1x= iMa(......, shift+2); ema2x= iMa(..... , shift+2), diffnow= ema1 - ema2; diffprev= ema1x - ema2x; if (diffnow>0 && difprev<0) { ExtMapBufLong[shift+1]= Low[shift+1]; } if (diffnow<0 && difprev>0) { ExtMapBufShort[shift+1]= High[shift+1]; }
Not perfect but a good approximation.
Markus
thanks,i try it.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
i have a problem with Ema of Cross in the mql4.
i want to konw how could i realize when the two Ema lines had crossd then appear a sylbol in the chart like following picture.
thanks a lot