Indicator data inconsistent
Indicator data inconsistent
17 Aug 2014, 16:55
Hello, I have the following bot (and indicator):
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class BugBot : Robot { private TestIndicator indicator; protected override void OnStart() { indicator = Indicators.GetIndicator<TestIndicator>(); } protected override void OnBar() { var thisClose = MarketSeries.Close.LastValue; var thisOpenTime = MarketSeries.OpenTime.LastValue; Print(string.Format("Robot thisClose:{0}, thisOpenTime:{1}", thisClose, thisOpenTime)); // This gives the correct number //indicator.Calculate(MarketSeries.Close.Count - 1); // This gives the incorrect number var lastValue = indicator.Result.LastValue; } } public class TestIndicator : Indicator { [Output("Main")] public IndicatorDataSeries Result { get; set; } public override void Calculate(int index) { var thisClose = MarketSeries.Close.LastValue; var thisOpenTime = MarketSeries.OpenTime.LastValue; Print(string.Format("Indicator thisClose:{0}, thisOpenTime:{1}", thisClose, thisOpenTime)); } } }
I have run this on GBPJPY 1 hour, and am seeing strange behavior coming from the indicator. The follow is output into the log, with the most recent message at the top of this list, I have labelled the lines a to f:
a 17/08/2013 01:00:00.000 | Indicator thisClose:152.552, thisOpenTime:16/08/2013 5:00:00 PM
b 17/08/2013 01:00:00.000 | Indicator thisClose:152.553, thisOpenTime:16/08/2013 4:00:00 PM
c 17/08/2013 01:00:00.000 | Robot thisClose:152.552, thisOpenTime:16/08/2013 5:00:00 PM
d 17/08/2013 00:00:00.000 | Indicator thisClose:152.534, thisOpenTime:16/08/2013 4:00:00 PM
e 17/08/2013 00:00:00.000 | Indicator thisClose:152.517, thisOpenTime:16/08/2013 3:00:00 PM
f 17/08/2013 00:00:00.000 | Robot thisClose:152.534, thisOpenTime:16/08/2013 4:00:00 PM
At line b, the indicator says the close at 4pm is 152.553, but this is different to lines d and f, which both say the close at 4pm is 152.534. Why is this different?
Thanks,
Chris
Spotware
18 Aug 2014, 12:50
We investigated your report. You access Close price in OnBar method.
OnBar method is invoked when new bar is opened. At that moment MarketSeries collection already contains tick from new bar. It means that last bar is not formed and in general cases open = high = low = close. Probably you need to access to last formed bar. You can use Last(1):
@Spotware