int t = 0; //what time shift is "today"? double fast_MA_today = iMA(Symbol(),0,FastMAPeriod,0,MODE_EMA,PRICE_CLOSE,t); double slow_MA_today = iMA(Symbol(),0,SlowMAPeriod,0,MODE_EMA,PRICE_CLOSE,t); double price_needed_today = ((f-1)*(s+1)*fast_MA_today- (f+1)*(s-1)*slow_MA_today)/(2*(f-s));
The article is based on the stock market, which has a close. Forex doesn't. So Today=bar 1, and Tomorrow=bar 0 and that's what is being calculated, what the price must be tomorrow to have a cross over. T MUST be one.
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
I found a fun read here (article) on predicting EMA crossovers. If I understood it correctly, for EMAs, we can see a recurrence relation between yesterday's EMA and today's EMA, and by shifting this relation forward, we can solve to figure out the approximate price needed for tomorrow to close in order for the EMAs to cross (derivation here btw). I tried to implement this with an EA (so I could see results on the strategy tester). I expected it to give some false signals (obviously), but it also misses a good number of signals, which I don't think it should do if implemented correctly. Could someone take a look at the formula and my code and try to find the mistake? Also, in order to get it to work somewhat well, I had to use Close[0], which I don't want to do. Will that cause problems?
The code that matters:
Should be simple enough to understand. Tell me if I need to add more comments. FYI, t=1 y=2 provided the signal one bar late. t=2 y=3 provided the signal TWO bars late.