Ema

 

How would one modify the tutorial to make an ema with a constant .1 instead of the average between high and low? For some strange reason the ema goes straight down 3-4 bars before the last bar. Any idea why?

Update: Ok I think it's because the if the current bar - last bar returns a negative value the while loop continues to average it it to the ema. So I guess the fix is to simply not calculate the last bar until it closes.

D

Files:
 
dustovshio:
How would one modify the tutorial to make an ema with a constant .1 instead of the average between high and low? For some strange reason the ema goes straight down 3-4 bars before the last bar. Any idea why?

Update: Ok I think it's because the if the current bar - last bar returns a negative value the while loop continues to average it it to the ema. So I guess the fix is to simply not calculate the last bar until it closes.

D

I think that the double ema must be declared outsite of the start() function : when you attach your indic on a chart, it's ok because the previous value of ema is keeped in the loop, but when it's running live, start() is called at each new tick to update only the last bar value, and thus you have to remember the previous value of ema between two start() calls.