Page 1 of 1

Indicator Can't Access Previous Bar Close

Posted: Dec 04 2013
by csswowsers
I am trying to plot a custom indicator but am getting an exception when accessing previous bar close. When referencing Bars.Close[1] I get the exception.

protected override void CalcBar(){
if (Bars.CurrentBar == 1) {
tr.Value = Bars.High[0] - Bars.Low[0];
}
if (Bars.CurrentBar > 1)
{
if (Bars.High[0] < Bars.Close[1]) ra.Value = Bars.Close[1] - Bars.Low[0];
}

Re: Indicator Can't Access Previous Bar Close

Posted: Dec 08 2013
by gvandenbosch
You can try this:

Code: Select all

Bars.FullSymbolData.Close[1]

Re: Indicator Can't Access Previous Bar Close

Posted: Dec 08 2013
by csswowsers
That didn't work. This is my indicator code:

public class TR : IndicatorObject {
public TR(object _ctx):base(_ctx){

}
public static VariableSeries<Double> tr;
public static VariableObject<Double> ra;
private IPlotObject plot1;
protected override void Create() {
// create variable objects, function objects, plot objects etc.
tr = new VariableSeries<Double>(this);
ra = new VariableObject<Double>(this);
plot1 = AddPlot(new PlotAttributes("", EPlotShapes.Line, Color.Red));
}

protected override void StartCalc() {
// assign inputs
}
protected override void CalcBar(){
if (Bars.CurrentBar == 1) {
tr.Value = Bars.High[0] - Bars.Low[0];
}
if (Bars.CurrentBar > 1)
{
ra.Value = Bars.High[0] - Bars.Low[0];
if (Bars.High[0] < Bars.Close[1]) ra.Value = Bars.Close[1] - Bars.Low[0];
if (Bars.Low[0] > Bars.Close[1]) ra.Value = Bars.High[0] - Bars.Close[1];
tr.Value = tr[1] * (13 / 15) + ra.Value * (2 / 15);
}
plot1.Set(0,tr.Value);
}
}

Re: Indicator Can't Access Previous Bar Close

Posted: Dec 09 2013
by Andrew MultiCharts
Hello csswowsers,

We failed to reproduce the issue with MultiCharts .NET Version 8.8 Release (Build 8364). Please make sure you have this version (or its 64 bit analogue) installed and if the problems still bothers you, please send the complete exported study.

Re: Indicator Can't Access Previous Bar Close

Posted: Dec 09 2013
by csswowsers
I don't see the option to export. I only have the indicator added currently. How can I have your team take a look?

Re: Indicator Can't Access Previous Bar Close

Posted: Dec 09 2013
by Andrew MultiCharts
Please come to our live chat during working hours (6:30 am – 4:00 pm EST) to let our operators connect to your computer remotely in order to export the study and transfer it to our end to study the case: http://messenger.providesupport.com/mes ... pport.html

Re: Indicator Can't Access Previous Bar Close  [SOLVED]

Posted: Dec 10 2013
by Henry MultiСharts
This question has been resolved during the live chat remote connection session:
1) The exception was a MultiCharts exception that is handled by MultiCharts (MaxBarsBack auto adjustment). This exception does not mean that there is anything wrong with your code, that is expected behavior, you just need to ignore this exception.
2) The solution was to set the MaxBarsBack for the study to 1.