Controlling multiple instances

Created at 15 Mar 2013, 17:43
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!
PR

proffzulus

Joined 15.03.2013

Controlling multiple instances
15 Mar 2013, 17:43


Hello everybody.

Can you please advise me how can I use multiple instances of my bot, driven by one core logic? The idea is to use multiple orders at the same time, and possibly, with multiple currencies (that's less important). Do I need to create instances and call them within the same namespace?  I need to control the execution of multiple instances from one place, does anyone have any Ideas? At least, I need them to share data.

I tried to add another class to the same file (and namespace) and use it with a callback on creation

//within core logic


myClass myobj = new myClass(this);
myobj.showSome();

//outside the robot

public class myClass : myRobot {

myRobot mainRobot;

public myClass(myRobot r)

{

mainRobot = r;

}
public void showSome() { Print("This is a data from parent {0}", mainRobot.sampleInt)} 
//public int sampleInt is initialized and available

}

 

 but faced a null reference exception.

I tried also to pass reference links but it didn't work for me.


@proffzulus
Replies

cAlgo_Fanatic
15 Mar 2013, 18:00

You cannot start a robot from another robot for the time being. So you wouldn't be able to have multiple instances.  But you can have multiple orders from within the same robot for the same currency.


@cAlgo_Fanatic

hichem
15 Mar 2013, 18:05

RE:
proffzulus said:

Hello everybody.

Can you please advise me how can I use multiple instances of my bot, driven by one core logic? The idea is to use multiple orders at the same time, and possibly, with multiple currencies (that's less important). Do I need to create instances and call them within the same namespace?  I need to control the execution of multiple instances from one place, does anyone have any Ideas? At least, I need them to share data.

I tried to add another class to the same file (and namespace) and use it with a callback on creation

//within core logic

myClass myobj = new myClass(this);
myobj.showSome(); //outside the robot public class myClass : myRobot { myRobot mainRobot; public myClass(myRobot r) { mainRobot = r; }
public void showSome() { Print("This is a data from parent {0}", mainRobot.sampleInt)}
//public int sampleInt is initialized and available }

 

 but faced a null reference exception.

I tried also to pass reference links but it didn't work for me.

Hello, 

 

What are you trying to accomplish is possible but I don't think you are using the proper way to do it. 

The way cAlgo functions doesn't not allow you to make Robots visible to each other. cAlgo uses the cSharpCodeProvider class to compile the Robot class into an assembly then load that assembly at runtimme then executes it. By doing that each Robot will be wrapped in a seperate domain which makes it unaccessible to other classes.

And this mechanism is necessery for proper initialisation and isolation of the robot.

To make robots share data you should make some sort of an interprocess communication between them. That way one robot can expose his properties so that other robots can retrieve them.

I have created a Library to do that. You can download it for free at www.scyware.com/download and for getting you started http://scyware.com/help-robotlink/


@hichem