ema loop

 
Hello, I'm working with a self reflective ema based on the following formula:
(while pos >=)
ema = ratio * (last price - ema)
pos++;
Where pos is the bar count using a comparison to the bars counted function. My problem is that
the ema continues to add to itself on the last bar which caused the line drawn to shoot
straight down or up on the last bar. Any ideas on how to fix this?
 
Here's the file
Files:
d.mq4  3 kb
 
Current bar (Bar[0]) is always changing, making updates to the last ema continuously.
Probably for your case it's better to stop computing at Bar[1], ie. at pos==1