Getting same results from cBot as Indicator
Getting same results from cBot as Indicator
01 May 2015, 22:24
This indicator works the way I want it to:
using System; using cAlgo.API; using cAlgo.API.Internals; using cAlgo.API.Indicators; namespace cAlgo { [Indicator(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class SampleBearsPower : Indicator { [Output("Result", Color = Colors.Orange, PlotType = PlotType.Histogram)] public IndicatorDataSeries Result { get; set; } private MovingAverage movingAverage; protected override void Initialize() { movingAverage = Indicators.MovingAverage(MarketSeries.Close, 13, MovingAverageType.Exponential); } public override void Calculate(int index) { string echo = (MarketSeries.Low[index] - movingAverage.Result[index]).ToString() + "\n" + (MarketSeries.Low[index - 1] - movingAverage.Result[index - 1]).ToString() + "\n" + (MarketSeries.Low[index - 2] - movingAverage.Result[index - 2]).ToString() + "\n" + (MarketSeries.Low[index - 3] - movingAverage.Result[index - 3]).ToString() + "\n" + (MarketSeries.Low[index - 4] - movingAverage.Result[index - 4]).ToString() + "\n" + (MarketSeries.Low[index - 5] - movingAverage.Result[index - 5]).ToString() + "\n" + (MarketSeries.Low[index - 6] - movingAverage.Result[index - 6]).ToString() + "\n" + (MarketSeries.Low[index - 7] - movingAverage.Result[index - 7]).ToString() + "\n" + (MarketSeries.Low[index - 8] - movingAverage.Result[index - 8]).ToString() + "\n" + (MarketSeries.Low[index - 9] - movingAverage.Result[index - 9]).ToString(); ChartObjects.DrawText("StairsStatus", echo, StaticPosition.TopLeft, Colors.Red); Result[index] = MarketSeries.Low[index] - movingAverage.Result[index]; } } }
I would like a cBot to work the same way, and the cBot calculations should be based on an Hour2 timeframe. How can I get the cBot to return exactly the same results as the indicator? The results of my cBot are different and they do not change with every tick like they do for the indicator.
using System; using cAlgo.API; using cAlgo.API.Internals; using cAlgo.API.Indicators; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class SampleBot : Robot { private MovingAverage movingAverage; private MarketSeries MData; protected override void OnStart() { MData = MarketData.GetSeries(Symbol.Code, TimeFrame.Hour2); movingAverage = Indicators.MovingAverage(MData.Close, 13, MovingAverageType.Exponential); } protected override void OnTick() { string echo = (MData.Low[0] - movingAverage.Result[0]).ToString() + "\n" + (MData.Low[1] - movingAverage.Result[1]).ToString() + "\n" + (MData.Low[2] - movingAverage.Result[2]).ToString() + "\n" + (MData.Low[3] - movingAverage.Result[3]).ToString() + "\n" + (MData.Low[4] - movingAverage.Result[4]).ToString() + "\n" + (MData.Low[5] - movingAverage.Result[5]).ToString() + "\n" + (MData.Low[6] - movingAverage.Result[6]).ToString() + "\n" + (MData.Low[7] - movingAverage.Result[7]).ToString() + "\n" + (MData.Low[8] - movingAverage.Result[8]).ToString() + "\n" + (MData.Low[9] - movingAverage.Result[9]).ToString(); ChartObjects.DrawText("Status", echo, StaticPosition.TopLeft, Colors.Red); } } }
Thanks for helping!
Replies
botmaster
25 May 2015, 19:01
I'm also experiencing the same issue. The problem is that for the current Tick or Bar the values are all the same. (i.e Open = Close = High = Low. )
You would think that cBot would be using the same values as the indicator, but for some reason it doesn't.
At first I didn't notice this issue because indicators like the SampleSMA are only using one data Source for the current tick or bar.
As an experienced programmer, but a newbie to cBot I just can't figure out why Calculate(int index) works from a different dataset than OnBar(). The values returned via indicators to cBot are not the same. It would be nice if there was more documentation to explain these differences.
@botmaster
Spotware
12 Jun 2015, 17:39
Dear Traders,
We do not provide coding assistance services. We more than glad to assist you with specific questions about cAlgo.API. You also can contact one of our Partners or post a job in Development Jobs section for further coding assistance.
Regarding Calculate(int index) and OnBar():
The Calculate(int index) method is called for each historic bar starting from the beginning of the series up to the current bar and then on each incoming tick.The index parameter, represents each bar, ranging from 0 up to the current (last) bar.
The OnBar() method is called on each incoming bar providing the user the values of incoming bar.
@Spotware
ctid299233
03 Mar 2017, 18:43
Any update on this issue?
The indicators used in cBots show different entry and exit trade points than the same indicator in cTrader. Why?
Can an indicator be shown in cAlgo, so that I can manually check if the backtesting signals are correct?
@ctid299233
BeardPower
05 Mar 2017, 19:28
RE: There is definitely an issue with cAlgo referencing indicators
Spotware said:
Dear Traders,
We do not provide coding assistance services. We more than glad to assist you with specific questions about cAlgo.API. You also can contact one of our Partners or post a job in Development Jobs section for further coding assistance.
Regarding Calculate(int index) and OnBar():
The Calculate(int index) method is called for each historic bar starting from the beginning of the series up to the current bar and then on each incoming tick.The index parameter, represents each bar, ranging from 0 up to the current (last) bar.
The OnBar() method is called on each incoming bar providing the user the values of incoming bar.
It's not coding related. There is definitely an issue with this. I experience the same problem. This behavior is completely messing up the indicator values. Putting the indicator on the chart works as expected.
I made an indicator, with the following Calculation method:
public override void Calculate(int index) { Print("indicator calculating for index " + index + " count: " + MarketSeries.Close.Count); }
In cAlgo I made the following OnBar method:
protected override void OnBar() { Print("cAlgo calls for index " + MarketSeries.Close.Count); halfTrend.Calculate(MarketSeries.Close.Count) }
This creates the following output:
26/07/2015 21:05:00.000 | cAlgo calls for index 77 26/07/2015 21:05:00.000 | indicator calculating for index 77 count: 77 26/07/2015 21:05:00.000 | indicator calculating for index 0 count: 1 26/07/2015 21:05:00.000 | indicator calculating for index 1 count: 2 [...] 26/07/2015 21:05:00.000 | indicator calculating for index 76 count: 77
Where is that third line coming from? cAlgo calls the indicator for calculating index 77, the indicator calculates it and automatically gets called with another index of 0 up to the index cAlgo was calling for?
After the indicator is calling itself up to index 77, it works as expected:
27/07/2015 21:05:00.000 | cAlgo calls for index 78 27/07/2015 21:05:00.000 | indicator calculating for index 78 count: 78 27/07/2015 21:05:00.000 | indicator calculating for index 76 count: 77 28/07/2015 21:00:00.000 | cAlgo calls for index 79 28/07/2015 21:00:00.000 | indicator calculating for index 79 count: 79 28/07/2015 21:00:00.000 | indicator calculating for index 77 count: 78
No more calling itself, so what is the issue here?
@BeardPower
BeardPower
05 Mar 2017, 19:33
RE: RE: There is definitely an issue with cAlgo referencing indicators
The OnBar function should be this code, of course (a semicolon was missing):
protected override void OnBar() { Print("cAlgo calls for index " + MarketSeries.Close.Count); halfTrend.Calculate(MarketSeries.Close.Count); }
This forum definitely needs some edit functionality.
Thanks!
@BeardPower
BeardPower
05 Mar 2017, 20:25
Forther investigation
I forgot to mention, that this behavior is occurring with backtesting.
There was no opportunity to test on live data, as the market is closed over the weekend.
After the indicator is calling itself up to index 77, it works as expected:
Sorry, that was the incorrect. I wanted to say, that it still is now working as expected.
The indicator is lacking behind, and some internal function seems to be calling it, but it should not.
I investigated further, and here is another example output. The indicator always get called two additional times, which are NOT called by cAlgo:
03/03/2017 21:48:00.000 | cAlgo calls for index 602404 03/03/2017 21:48:00.000 | indicator calculating for index 602404 count: 602404 03/03/2017 21:48:00.000 | indicator calculating for index 602402 count: 602403 03/03/2017 21:48:00.000 | indicator calculating for index 602403 count: 602404 03/03/2017 21:49:00.000 | cAlgo calls for index 602405 03/03/2017 21:49:00.000 | indicator calculating for index 602405 count: 602405 03/03/2017 21:49:00.000 | indicator calculating for index 602403 count: 602404 03/03/2017 21:49:00.000 | indicator calculating for index 602404 count: 602405 03/03/2017 21:50:00.000 | cAlgo calls for index 602406 03/03/2017 21:50:00.000 | indicator calculating for index 602406 count: 602406 03/03/2017 21:50:00.000 | indicator calculating for index 602404 count: 602405 03/03/2017 21:50:00.000 | indicator calculating for index 602405 count: 602406 03/03/2017 21:51:00.000 | cAlgo calls for index 602407 03/03/2017 21:51:00.000 | indicator calculating for index 602407 count: 602407 03/03/2017 21:51:00.000 | indicator calculating for index 602405 count: 602406 03/03/2017 21:51:00.000 | indicator calculating for index 602406 count: 602407
@BeardPower
BeardPower
05 Mar 2017, 21:24
The root of evil
Finally I found out why this issue happens.
This is the Calculate function:
public override void Calculate(int index) { Print(index); lowsMA[index] = lowsMA.Last(1); }
lowsMA is just an output parameter:
[Output("MA lows", Color = Colors.IndianRed, PlotType = PlotType.DiscontinuousLine)] public IndicatorDataSeries lowsMA { get; set; }
The log form the indicator:
05/03/2017 19:08:55.461 | index: 0 [...] 05/03/2017 19:08:56.975 | index: 3150
The lof from cAlgo, calling the indicator:
02/03/2017 04:10:00.000 | cAlgo calls for index 599916 02/03/2017 04:10:00.000 | index: 599916 02/03/2017 04:10:00.000 | index: 599914 02/03/2017 04:10:00.000 | index: 599915 [...] 03/03/2017 21:59:00.000 | cAlgo calls for index 602415 03/03/2017 21:59:00.000 | index: 602415 03/03/2017 21:59:00.000 | index: 602413 03/03/2017 21:59:00.000 | index: 602414 03/03/2017 21:59:00.000 | Backtesting finished
So, why is the indicator calling itself two additional times, when called from cAlgo?
@BeardPower
BeardPower
05 Mar 2017, 23:13
( Updated at: 21 Dec 2023, 09:20 )
Bug in cAlgo: adding non-existing bars
I made some screenshots, where you can clearly see, that cBot is adding a blue bullish bar (as seen at the data box). The next bar has also a wrong date because of that.
Screenshot from cBot:
Screenshot from Indicator (there is no blue bullish bar):
Screenshot from cBot (there is a blue bullish candle and the red bearish bar has the same date as the bar before: 28/02/2017 22:00):
Same screenshot from Indicator (no blue bullish candle and the date of the next read bearish bar is correct)
:
@BeardPower
BeardPower
06 Mar 2017, 02:15
Works with live data
Finally I was able to test it under market conditions and the cBot works like expected.
It's definitely an issue with backtesting.
Hope this helps.
@BeardPower
onemind
03 May 2015, 15:46
Wish I could help but i have the exact same problem.
My cbot and indicator both use the exact same logic to define a channel but the indicator shows up where there are no trades from cbot and cbot trades when there is no indicator. Most of the time they are in sync.
@onemind