But when I set CalculateOnBarClose = false, I started having bad values returned from these properties. I tracked it down to references to CurrentBar and it seems that CurrentBar isn't always dependable the way I'm using it.
I did some testing and it seems that if I put CurrentBar in an integer property then it's always one behind when the variable/property is referenced another indicator. Also, when I put CurrentBar in a dataseries and then reference this dataseries via a property from another indicator then it's always zero.
I seem to remember something about CurrentBar not being dependable in certain contexts. Is this a know situation? Could this be a bug?
Here is my test code: (not sure if the Update()s are needed - same results with or without them)
IndicatorA:
public class IndicatorA: Indicator { private IntSeries testDS; private int testInt = 10; // initialize to something - later set to CurrentBar protected override void Initialize() { CalculateOnBarClose = false; testDS = new IntSeries(this); } protected override void OnBarUpdate() { testDS.Set(CurrentBar); // put CurrentBar value in the data series testInt = CurrentBar; // put CurrentBar value in an int } [Browsable(false)] [XmlIgnore()] public int TestDS { get { Update(); return (testDS[0]); } } [Browsable(false)] [XmlIgnore()] public int TestInt { get { Update(); return (testInt); } } }
public class IndicatorB: Indicator { protected override void Initialize() { CalculateOnBarClose = false; } protected override void OnBarUpdate() { Print("CurrentBar=" + CurrentBar + " TestDS=" + IndicatorA().TestDS + " TestInt=" + IndicatorA().TestInt); } }
CurrentBar=11059 TestDS=0 TestInt=11058
Comment