GrumpyDuckMan:
Hello everyone,
I am a little bit stuck on how to check for a cross over, I started writing this code.
I need a bit of guidance on how to code it better than this.
As a suggestion, look at any of the freely available MT4 EA's available in the code base that do crossovers.
For example, https://www.mql5.com/en/code/12448 (first one that came up when I Googled).
The key is:
1) Get some values, e.g.
Fast_MA_Bar_0 = iMA(NULL, 0, Fast_MA_Period, Fast_MA_Shift, Fast_MA_Method, Fast_MA_Price, i+1); Fast_MA_Bar_1 = iMA(NULL, 0, Fast_MA_Period, Fast_MA_Shift, Fast_MA_Method, Fast_MA_Price, i+2); Slow_MA_Bar_0 = iMA(NULL, 0, Slow_MA_Period, Slow_MA_Shift, Slow_MA_Method, Slow_MA_Price, i+1); Slow_MA_Bar_1 = iMA(NULL, 0, Slow_MA_Period, Slow_MA_Shift, Slow_MA_Method, Slow_MA_Price, i+2);
2) Ensure that the previous value is below, and the current value is above, e.g.
if((Fast_MA_Bar_1 < Slow_MA_Bar_1) && (Fast_MA_Bar_0 > Slow_MA_Bar_0))
This sort of works, but not really telling me if there is a cross over.
AVD_Minus = iADX(NULL,0,14,PRICE_CLOSE,MODE_MINUSDI,0); AVD_Plus = iADX(NULL,0,14,PRICE_CLOSE,MODE_PLUSDI,0); AVD_Main = iADX(NULL,0,14,PRICE_CLOSE,MODE_MAIN,0); A = fmax (AVD_Plus, AVD_Minus); B = fmin (AVD_Plus, AVD_Minus); if(A==AVD_Plus)PlusHigh=A; if(A==AVD_Minus)MinusHigh=A; if(B==AVD_Plus)PlusLow=B; if(B==AVD_Minus)MinusLow=B; Indicator_Crossed_A = PlusHigh+PlusLow; Indicator_Crossed_B = MinusHigh+MinusLow; if(Indicator_Crossed_A>Indicator_Crossed_B) BuyOut=Indicator_Crossed_A; if(Indicator_Crossed_A<Indicator_Crossed_B) SellOut=Indicator_Crossed_A;
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 everyone,
I am a little bit stuck on how to check for a cross over, I started writing this code.
I need a bit of guidance on how to code it better than this.