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];
}
Indicator Can't Access Previous Bar Close [SOLVED]
-
- Posts: 30
- Joined: 24 Oct 2013
- Has thanked: 9 times
- Been thanked: 3 times
Re: Indicator Can't Access Previous Bar Close
You can try this:
Code: Select all
Bars.FullSymbolData.Close[1]
-
- Posts: 6
- Joined: 04 Dec 2013
Re: Indicator Can't Access Previous Bar Close
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);
}
}
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);
}
}
- Andrew MultiCharts
- Posts: 1587
- Joined: 11 Oct 2011
- Has thanked: 931 times
- Been thanked: 559 times
Re: Indicator Can't Access Previous Bar Close
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.
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.
-
- Posts: 6
- Joined: 04 Dec 2013
Re: Indicator Can't Access Previous Bar Close
I don't see the option to export. I only have the indicator added currently. How can I have your team take a look?
- Andrew MultiCharts
- Posts: 1587
- Joined: 11 Oct 2011
- Has thanked: 931 times
- Been thanked: 559 times
Re: Indicator Can't Access Previous Bar Close
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
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: Indicator Can't Access Previous Bar Close [SOLVED]
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.
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.