Static Varibles Across Instances How?

Created at 21 Sep 2017, 01:36
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
GA

GammaQuant

Joined 14.06.2017

Static Varibles Across Instances How?
21 Sep 2017, 01:36


Hi i want to share variables between cbots. ive seen elsewhare on this forum that you can use static varibles to share data between instances but i cant get this to work.

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 Static1 : Robot
    {
        [Parameter(DefaultValue = "TestingTesting")]
        public string Input { get; set; }
        public static string Test;

        protected override void OnStart()
        {
            // Put your initialization logic here
        }

        protected override void OnTick()
        {
            Test = Input;
            Print(Test);
            // Put your core logic here
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}



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 Static2 : Robot
    {
        [Parameter(DefaultValue = "")]
        public string Input { get; set; }
        public static string Test;

        protected override void OnStart()
        {
            // Put your initialization logic here
        }

        protected override void OnTick()
        {

            Print(Test);
            // Put your core logic here
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

The bottom robot static2 stays null....

How do i get this to work


@GammaQuant
Replies

PanagiotisCharalampous
21 Sep 2017, 10:00

Hi GammaQuant,

It is not possible to share static variables between cBots. Where have you seen this? Do you mind sharing a link? Maybe it was about something else.

Best Regards,

Panagiotis


@PanagiotisCharalampous

GammaQuant
21 Sep 2017, 11:34

RE:

Panagiotis Charalampous said:

Hi GammaQuant,

It is not possible to share static variables between cBots. Where have you seen this? Do you mind sharing a link? Maybe it was about something else.

Best Regards,

Panagiotis

Hi Panagiotis here are Three:

/forum/calgo-support/11288

/forum/cbot-support/11619?page=1

/forum/cbot-support/10908?page=2


@GammaQuant

PanagiotisCharalampous
21 Sep 2017, 12:09

Hi GammaQuant,

Thanks for the links. There is a mention in one of them that you could use static collections to share variables between cBots but this is not possible. I assume that the person that suggested this never actually tried it. The reason that this cannot happen is that you cannot compile more than two cBots in the same dll. As a result, each cBot exists in a different dll and they cannot share variables between them. If you need to share information between cBots maybe you can consider reading and writing to a file accessible by both. Let me know if this suggestion helps.

Best Regards,

Panagiotis


@PanagiotisCharalampous

GammaQuant
21 Sep 2017, 16:07

RE:

Panagiotis Charalampous said:

Hi GammaQuant,

Thanks for the links. There is a mention in one of them that you could use static collections to share variables between cBots but this is not possible. I assume that the person that suggested this never actually tried it. The reason that this cannot happen is that you cannot compile more than two cBots in the same dll. As a result, each cBot exists in a different dll and they cannot share variables between them. If you need to share information between cBots maybe you can consider reading and writing to a file accessible by both. Let me know if this suggestion helps.

Best Regards,

Panagiotis

Hi Panagiotis Ok so this is not possible then for sure.....

I am building a high performance trading system that will be running over 10 to 30 instances with a master instance controlling the other intances. As this is quite a complex system i dont want the performance to suffer so after lots of research on the available options i could take i have thought about doing this with WCF Named Pipe Binding with Protobuf serialization or doing it with Memory Mapped Files. i have never dont this before having only started programming c# 4 months ago so any advice would be appreciated.

Thank you.


@GammaQuant

PanagiotisCharalampous
21 Sep 2017, 16:34

Hi GammaQuant,

Named Pipes and Memory Mapped Files are indeed advanced C# subjects. Named Pipes are used for inteprocess communication i.e. one application sending messages to another while Memory Mapped Files are used to share memory between different processes. So it all depends on the application you are building. If for example you need one application to inform another about something then use Named Pipes. If you need an application to write something in memory and another application to read this information whenever needed then use Memory-Mapped files. I don't know if I can help you more than this at this stage. If you have more specific questions, feel free to ask.

Best Regards,

Panagiotis


@PanagiotisCharalampous

GammaQuant
21 Sep 2017, 17:11

I think i will use Named Pipes as there are much more examples and tutorials around to help me set up WCF than i have found for MMF. i also think it will be better for what i am doing as i want each instance to send mesaages to the master when anything significant happens on ticks coming in Asynchronously and also the master to send messages to the slaves. WCF looks like it will handle message queuing and other underlying stuff so i think thats the best direction for me to take. if i get into any problems with this in calgo i will ask your advice again. Thank you very much Panagiotis


@GammaQuant

Anka Software
10 Apr 2019, 18:35

RE:

Panagiotis Charalampous said:

Hi GammaQuant,

Thanks for the links. There is a mention in one of them that you could use static collections to share variables between cBots but this is not possible. I assume that the person that suggested this never actually tried it. The reason that this cannot happen is that you cannot compile more than two cBots in the same dll. As a result, each cBot exists in a different dll and they cannot share variables between them. If you need to share information between cBots maybe you can consider reading and writing to a file accessible by both. Let me know if this suggestion helps.

Best Regards,

Panagiotis

Hi,

   One clarification - could multiple instances of same cBot, share a static variable?

 

Regards

Vivek


@Anka Software

firemyst
04 Oct 2019, 10:52

RE: RE:

Anka Software said:

Panagiotis Charalampous said:

Hi GammaQuant,

Thanks for the links. There is a mention in one of them that you could use static collections to share variables between cBots but this is not possible. I assume that the person that suggested this never actually tried it. The reason that this cannot happen is that you cannot compile more than two cBots in the same dll. As a result, each cBot exists in a different dll and they cannot share variables between them. If you need to share information between cBots maybe you can consider reading and writing to a file accessible by both. Let me know if this suggestion helps.

Best Regards,

Panagiotis

Hi,

   One clarification - could multiple instances of same cBot, share a static variable?

 

Regards

Vivek

Yes.

See this updated thread:

https://ctrader.com/forum/calgo-support/22028?page=1#3

 


@firemyst

Emmanuel.evrard2
25 Oct 2020, 23:30

RE:

Hi PanagiotisCharalampous,

I tried to use Pipe to connect Calgo to an application

It works initially with

 [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]

but it don't work anymore, It seem not to be able to connect

                NamedPipeClientStream pipeStream = new NamedPipeClientStream(".", PipeName, PipeDirection.Out, PipeOptions.Asynchronous);

                pipeStream.Connect(TimeOut);                              DON'T WORK ANYMORE

 

Do you have an example of Pipe or sharememory in Ctrader ?

 

Thank you

 

 

PanagiotisCharalampous said:

Hi GammaQuant,

Named Pipes and Memory Mapped Files are indeed advanced C# subjects. Named Pipes are used for inteprocess communication i.e. one application sending messages to another while Memory Mapped Files are used to share memory between different processes. So it all depends on the application you are building. If for example you need one application to inform another about something then use Named Pipes. If you need an application to write something in memory and another application to read this information whenever needed then use Memory-Mapped files. I don't know if I can help you more than this at this stage. If you have more specific questions, feel free to ask.

Best Regards,

Panagiotis

 


@Emmanuel.evrard2

PanagiotisCharalampous
26 Oct 2020, 08:42

Hi Emmanuel,

Unfortunately we do not have such an example at the moment.

Best Regards,

Panagiotis 

Join us on Telegram 

 


@PanagiotisCharalampous

Emmanuel.evrard2
26 Oct 2020, 10:57

RE:

Thank you for your answer

 

PanagiotisCharalampous said:

Hi Emmanuel,

Unfortunately we do not have such an example at the moment.

Best Regards,

Panagiotis 

Join us on Telegram 

 

 


@Emmanuel.evrard2