I've created a function which puts the OHLC values into an array, and returns that double[] array to the calling indicator. I've created the indicator which calls the function and gets the array from it.
However, I can't get the indicator code to produce a "series" with a history. I want to be able to check things like: what was the first element of the array 10 bars ago? what was the 3rd element of the array 50 bars ago, etc.
In the code below, if i try to plot myArray[0][2], it works. If I try myArray.Value[2] I think it also works. But I can't refer to previous bars. For example myArray[1][2] or myArray[10][2] produces an error.
What am i doing wrong?
Code: Select all
using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;
namespace PowerLanguage.Indicator{
[SameAsSymbolAttribute(true)]
public class _ohlcPlotter : IndicatorObject {
public _ohlcPlotter(object _ctx):base(_ctx){}
private IPlotObject plot1;
private _ohlcArrayFunction myArray;
protected override void Create() {
// create variable objects, function objects, plot objects etc.
plot1 = AddPlot(new PlotAttributes("", EPlotShapes.Line, Color.Red));
myArray = new _ohlcArrayFunction(this);
}
protected override void StartCalc() {
// assign inputs
}
protected override void CalcBar(){
// indicator logic
plot1.Set(myArray[0][2]); // << this works
}
}
}
Code: Select all
using System;
using System.Drawing;
using System.Linq;
namespace PowerLanguage
{
namespace Function
{
public sealed class _ohlcArrayFunction : FunctionSeries<double []>
{
public _ohlcArrayFunction(CStudyControl _master) : base(_master) { }
public _ohlcArrayFunction(CStudyControl _master, int _ds) : base(_master, _ds) { }
protected override void Create()
{
// create variable objects and function objects
}
protected override void StartCalc()
{
// assign inputs
}
protected override double[] CalcBar()
{
// function logic
double [] ohlcArray;
ohlcArray = new double [4];
ohlcArray[0] = Bars.Open[0];
ohlcArray[1] = Bars.High[0];
ohlcArray[2] = Bars.Low[0];
ohlcArray[3] = Bars.Close[0];
return ohlcArray;
}
}
}
}