Indicator Can't Access Previous Bar Close  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
csswowsers
Posts: 6
Joined: Dec 04 2013

Dec 04 2013

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];
}

gvandenbosch
Posts: 30
Joined: Oct 24 2013
Has thanked: 9 times
Been thanked: 3 times

Dec 08 2013

You can try this:

Code: Select all

Bars.FullSymbolData.Close[1]

csswowsers
Posts: 6
Joined: Dec 04 2013

Dec 08 2013

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);
}
}

User avatar
Andrew MultiCharts
Posts: 1587
Joined: Oct 11 2011
Has thanked: 931 times
Been thanked: 559 times

Dec 09 2013

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.

csswowsers
Posts: 6
Joined: Dec 04 2013

Dec 09 2013

I don't see the option to export. I only have the indicator added currently. How can I have your team take a look?

User avatar
Andrew MultiCharts
Posts: 1587
Joined: Oct 11 2011
Has thanked: 931 times
Been thanked: 559 times

Dec 09 2013

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

User avatar
Henry MultiСharts
Posts: 9165
Joined: Aug 25 2011
Has thanked: 1264 times
Been thanked: 2958 times

Dec 10 2013

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.