The indicator does not work inside the bot
The indicator does not work inside the bot
10 Mar 2024, 01:30
Hello!
I am writing a bot that works in conjunction with my indicator.
Separate from the bot, the indicator works correctly. But when I try to use it inside the bot, the variables inside the indicator do not change in any way as the price moves and it does not generate the information necessary for the bot. There were no errors during initialization, I can freely access the variables inside the indicator. The indicator does not have a parameter, therefore, when used in the bot, I do not pass any parameters.
It seems to me that this is due to the fact that I am using MarketSeries to get data inside the indicator. For example:
DateTime nyTime = MarketSeries.OpenTime[index];
_dailyHigh = MarketSeries.High[index];
And when I run it inside the bot, I don't pass any parameters, as is done in the cBots examples, such as Sample RSI Bot, via DataSeries. And it seems to me that because of this, the indicator does not have data when working inside the bot.
Initialization of my indicator inside the bot:
private NYRangeIndicator _nyRangeIndicator;
protected override void OnStart()
{
_nyRangeIndicator = Indicators.GetIndicator<NYRangeIndicator>();
}
A similar example with SampleRSIcBot:
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class SampleRSIcBot : Robot
{
[Parameter("Quantity (Lots)", Group = "Volume", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]
public double Quantity { get; set; }
[Parameter("Source", Group = "RSI")]
public DataSeries Source { get; set; }
[Parameter("Periods", Group = "RSI", DefaultValue = 14)]
public int Periods { get; set; }
private RelativeStrengthIndex rsi;
protected override void OnStart()
{
rsi = Indicators.RelativeStrengthIndex(Source, Periods);
}
...
}
In this example, the DataSeries data is passed to the indicator. I'm not passing anything to it, because in theory, MarketSeries should be available in Automate immediately.
But as far as I know, it is impossible to create a parameter with the MarketSeries type, and I could not find working examples of indicators that work inside the bot and use MarketSeries.
But this is just my guess, so I want to ask for advice on how to make the indicator work inside cBot.
UPD:
I'll add an example to make it clearer what I'm talking about. Here in the Calculate method Indicator I get the current time:
public DateTime curTime;
public override void Calculate(int index)
{
DateTime nyTime = Bars.OpenTimes[index];
curTime = nyTime;
....
}
Then I access this variable already in the Bot and output its value to the Logs:
private NYRangeIndicator _nyRangeIndicator;
protected override void OnStart()
{
_nyRangeIndicator = Indicators.GetIndicator<NYRangeIndicator>();
}
protected override void OnBar()
{
Print("Cur:",_nyRangeIndicator.curTime);
}
And that's what I see in the Logs during the Backtesting:
10/10/2023 09:25:00.418 | Cur:01.01.0001 0:00:00
10/10/2023 09:20:00.426 | Cur:01.01.0001 0:00:00
10/10/2023 09:15:00.128 | Cur:01.01.0001 0:00:00
10/10/2023 09:10:00.311 | Cur:01.01.0001 0:00:00
....
(Separately from the Bot, the indicator works correctly)
I tried using Bars instead of MarketSeries. But it also didn't help solve my problem.
firemyst
13 Mar 2024, 00:10
I may be wrong, but when you run the indicator from inside the bot, it's using what you have specified as the bot's time zone:
@firemyst