dclark24:
Hello all, I have a very simple code that uses exponential moving averages at 2 lengths. When the shorter length crosses above the other then a long position is taken. Sometimes it works. That is ,when there is an obvious crossing I can see on the chart a long position is taken but at other obvious crossings a long position is not taken. Do you think this is related to the code or is it possibly a computer speed/processor issue? Any hints would be appreciated.
Hi,
So sometime below condition may happen:
if (EMA11==EMA21) if (EMA12<EMA22) or if (EMA11>EMA21) if (EMA12==EMA22)
So it could be :
if (EMA11>=EMA21) if (EMA12<EMA22) or if (EMA11>EMA21) if (EMA12<=EMA22)
You can print the values which you see the crossing is happened,and see the exact condition.
double aPrev = …, aCurr = …, bPrev = …, bCurr = …; bool wasUp = aPrev > bPrev, isUp = aCurr > bCurr, isCross = isUp != wasUp;

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 all, I have a very simple code that uses exponential moving averages at 2 lengths. When the shorter length crosses above the other then a long position is taken. Sometimes it works. That is ,when there is an obvious crossing I can see on the chart a long position is taken but at other obvious crossings a long position is not taken. Do you think this is related to the code or is it possibly a computer speed/processor issue? Any hints would be appreciated.