LOL! I figured it out, and I feel so stupid. I made it MUCH harder than I should have.
Anyhow, here's the fixed code for anyone who wants it:
double TimeSeriesForecast(int TSFPeriod, int Offset) { double sy=0; double sx=0; double sxy=0; double sx2=0; for (int cnt=1; cnt <= TSFPeriod; cnt++) { sy+=Close[(cnt-1)+Offset]; sx+=cnt; sx2+=cnt*cnt; sxy+=Close[(cnt-1)+Offset]*cnt; } double kb=(TSFPeriod*sxy-sx*sy)/(TSFPeriod*sx2-sx*sx); double ka=(sy-kb*sx)/TSFPeriod; double ival=ka+kb; return(ival); }

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
Hi guys. I'm new.
I pulled some code out of an indicator I found floating around somewhere in order to include it in my EA, but I'm having trouble with it. It doesn't return the same value that the indicator does.
I think it has something to do with the way I'm normalizing the doubles and floating point precision, but I can't figure it out.
I've tried it with NormalizeDouble() and without. I've tried only normalizing some of them, and without. I'm stumped. Please help, or maybe just post a function for TSF that actually WORKS. :)
Help would be preferred though, that way I can learn what the heck I'm doing wrong.
Anyhow here's the code I'm using, and the original indicator it's stolen from is attached: