- ago
Hi Guys.


How can I create a cumulative indicator / timeseries using at current bar calculation the value of previous bars?

for exemple, X = X(n-1) + X(n-2)

I don't know how to access prevoius values in the same timeseries / indicator inside Initialize section - dont know even if that is the correct location.

Thanks in advance.
0
619
Solved
2 Replies

Reply

Bookmark

Sort
Glitch8
 ( 10.65% )
- ago
#1
You could do it in Initialize. Or create the TimeSeries in Initialize and set the values in Execute. Here's an example of it done in Initialize:

CODE:
//create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) {          RSI rsi14 = RSI.Series(bars.Close, 14);          PlotIndicator(rsi14);          TimeSeries cumulative = new TimeSeries(bars.DateTimes);          for (int n = 2; n < bars.Count; n++)             cumulative[n] = rsi14[n - 1] + rsi14[n - 2];          PlotTimeSeries(cumulative, "RSICumulative", "RSI", WLColor.Green); }
2
Best Answer
- ago
#2
Thanks Glitch!!
0

Reply

Bookmark

Sort