/*[[ Name := tseries forecast Author := Copyright © 2004, Nick Bilak Link := Notes := Separate Window := No First Color := Yellow First Draw Type := Line First Symbol := 160 Use Second Data := No Second Color := DimGray Second Draw Type := Line Second Symbol := 218 ]]*/ Inputs: ndot(21); var: ka(0),kb(0),sx(0),sy(0),sxy(0),sx2(0),cnt(0),loopBegin(0),shift(0),ival(0); var: prevbars(0),is_First(true); SetLoopCount(0); // Check for additional bars loading or total reloadng. If Bars1 Then is_First=True; prevbars=Bars; //-------------------------------------------------------- // Pre-Loop setup // loopbegin prevents counting of previously plotted bars excluding current Bars if is_First Then Begin LoopBegin=bars-ndot-2; is_First=False; End; //-------------------------------------------------------- loopBegin++; // Plot the current bar also // loop from first bar to current bar (with shift=0) For shift=loopBegin Downto 0 Begin sy=0; sx=0; sxy=0; sx2=0; For cnt=1 To ndot Begin sy+=close[shift+cnt-1]; sx+=cnt; sx2+=cnt*cnt; sxy+=close[shift+cnt-1]*cnt; End; kb=(ndot*sxy-sx*sy)/(ndot*sx2-sx*sx); ka=(sy-kb*sx)/ndot; ival=ka+kb; SetIndexValue(shift, ival); loopBegin--; // Prevent repeating previously plotted bars on next tick End;