ctrader bug? Wrong values cBot vs indicator: polynomial regression
ctrader bug? Wrong values cBot vs indicator: polynomial regression
23 Jun 2023, 17:24
Hi,
I was testing the sample code from ctrader for polynomial regression. But it seems that I get different results/values if I use the function PolynomialRegressionChannels from ctrader within a cbot compared to the indicator.
here is the cbot example from ctrader, that I modified, so that it only prints me the values sql and sqh.
using cAlgo.API;
using cAlgo.API.Indicators;
namespace cAlgo.Robots
{
// This sample cBot shows how to use the Polynomial Regression Channels indicator
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class PolynomialRegressionChannelsSample : Robot
{
private double _volumeInUnits;
private PolynomialRegressionChannels _polynomialRegressionChannels;
[Parameter("Volume (Lots)", DefaultValue = 0.01)]
public double VolumeInLots { get; set; }
[Parameter("Label", DefaultValue = "Sample")]
public string Label { get; set; }
[Parameter("Source")]
public DataSeries Source { get; set; }
public Position[] BotPositions
{
get
{
return Positions.FindAll(Label);
}
}
protected override void OnStart()
{
_volumeInUnits = Symbol.QuantityToVolumeInUnits(VolumeInLots);
_polynomialRegressionChannels = Indicators.PolynomialRegressionChannels(2, 170, 2, 3);
}
protected override void OnBar()
{
Print(" _polynomialRegressionChannels.Sql.Last(1) = {0}, <= _polynomialRegressionChannels.Sqh.Last(1) = {1}", _polynomialRegressionChannels.Sql.Last(1),_polynomialRegressionChannels.Sqh.Last(1));
}
}
}
But this values don't match with the values from the Indicator like you can see in the screen shot:
Am I doing something wrong or is this a bug?
Replies
PanagiotisChar
26 Jun 2023, 08:26
Hi there,
PRC is a redrawing indicator. On every bar, past values change.
Need help? Join us on Telegram
@PanagiotisChar
SmartRetailTradingRobot
27 Jun 2023, 08:24
Hi Firemyst and Panagiotis,
thank you for your answers! This makes perfect sense.
Best regards
Nik
@SmartRetailTradingRobot
firemyst
24 Jun 2023, 05:32
Someone can correct me if I'm wrong, but the PRC is retrofitted to price action. Only the current value of the PRC is not repainted. This is similar to a linear regression channel which is also retrofitted to price action. This means that the entire graph is repainted, with the exception of the current value of the channel, which can be used for an automated strategy.
This has already been discussed somewhat here:
https://ctrader.com/forum/ctrader-support/37573#:~:text=Hi%2C,it's%20retrofitted%20to%20price%20action.
@firemyst