DataSeries value from previous bar
Author: ovtpete
Creation Date: 12/16/2008 12:31 PM
profile picture

ovtpete

#1
I can't figure out, while initializing a data series, how to get the value from the previous bar. It's easy enough to do in the main loop but then I can't chart the data series. For example, the code for an EMA would look something like:

CODE:
Please log in to see this code.


How can I do this?
profile picture

Eugene

#2
Typically, DataSeries myEMA = Close*0 is one of the possible ways to initialize a series before the main loop. Looks like actually you're not initializing but building some data series, and need the value from the previous bar.

To reference the value from the previous "bar", use one of the shift operators e.g. DataSeries>>1. (See DataSeries Object in the QuickRef.) However, this should not work with myEMA because it is empty.

In this example, calling the "x" in the loop will get the value from the previous bar:

CODE:
Please log in to see this code.


If this is not what you want, please explain.
profile picture

ovtpete

#3
Not the most elegant thing in the world, but that will do it. Thanks.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).