Looking for confirmation: static variables accessible across all bot instances?
Looking for confirmation: static variables accessible across all bot instances?
04 Oct 2019, 10:31
Hello Team Spotware:
Just wanted to confirm support that static variables declared as public in cbots are visible/accessible under every instance for a particular cBot?
So I have a bot with a DataSeries declared as:
private DataSeries _closeLongSeries;
Instead of having this variable sucking up memory for every instance, I'd like to declare it as:
public static DataSeries _closeLongSeries;
so there's only 1 instance of it across the 21 bot instances instead of 1 for each bot instance since it will be the same.
Is this supported in cAlgo with bots?
This question was also posed in this thread ( #8 ), but never answered:
https://ctrader.com/forum/cbot-support/11907
Thank you.

PanagiotisCharalampous
04 Oct 2019, 10:43
Hi FireMyst,
Yes this should be the case. You can check it with the example below
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo.Robots { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class NewcBot : Robot { [Parameter(DefaultValue = 0.0)] public double Parameter { get; set; } public static int Counter; protected override void OnStart() { // Put your initialization logic here } protected override void OnTick() { Counter++; Print(Counter); } protected override void OnStop() { // Put your deinitialization logic here } } }Best Regards,
Panagiotis
@PanagiotisCharalampous