Yes you can but make sure that the code of one Robot does not affect the other. For instance one Robot may be closing all positions that are open for the account.
You may use a List to keep track of the positions that each robot is creating and closing:
// Declaration
private readonly List _positions = new List();
// OnPositionOpened
protected override void OnPositionOpened(Position openedPosition)
{
_positions.Add(openedPosition);
}
// OnPositionClosed
protected override void OnPositionClosed(Position closedPosition)
{
if (_positions.Contains(closedPosition))
{
_positions.Remove(closedPosition);
}
}
// access within OnTick/OnBar
foreach (Position position in _positions )
{
// do something e.g.
if(position.NetProfit < ProfitLevel)
Trade.Close(position);
}
so there is no magic number or something similar to separate the robots? If you have 20 bots running, you are relying only on figuring out which one opened a position with the list code that you have listed which i assume will need to be in every bot?
We are currently working on introducing "labels" in cAlgo that will have the functionality of identifying robots. It will be available very soon, stay tuned!
admin
19 Sep 2012, 15:31
Hello SpotTrader,
Yes you can but make sure that the code of one Robot does not affect the other. For instance one Robot may be closing all positions that are open for the account.
You may use a List to keep track of the positions that each robot is creating and closing:
@admin