OnPositionClosed in other instance
OnPositionClosed in other instance
28 Nov 2013, 14:14
Is it possible for a robot to manage trades that are opened by other instances (or manually)?
How can a robot act on the closing of a trade not set by that instance? OnPositionClosed can only do this for trades opened by the instance itself.
I try to build a bot that manages all my opened positions.
Replies
Cerunnos
28 Nov 2013, 17:03
RE: RE:
Cerunnos said:
hichem said:
From the new API:
Positions.Closed+= OnPositionsClosed;
will handle all closed positions not only in the current robot
Hi Hichem.
Even if a position was closed manually in cTrader or by SL hit. How would you code that?
Thanks in advance
protected override void OnStart()
{
Positions.Closed += OnPositionsClosed;
}
private void OnPositionsClosed(PositionClosedEventArgs args)
{
if (args.position.Label != "m10_Robot" && args.position.Label != "m5_Robot") // only manual positions
{
Print("Manually Position #{0} was closed", args.Position.Id);
}
}
Is that code right?
@Cerunnos
hichem
28 Nov 2013, 17:44
RE: RE: RE:
Normally positions open manually have no Label. So to test if the position is a manually open position you test if position.Label != string.Empty or position.Label != null, not sure which one actually works. And off course that supposes that positions created by a robot should have labels
Cerunnos said:
Cerunnos said:
hichem said:
From the new API:
Positions.Closed+= OnPositionsClosed;
will handle all closed positions not only in the current robot
Hi Hichem.
Even if a position was closed manually in cTrader or by SL hit. How would you code that?
Thanks in advance
protected override void OnStart()
{
Positions.Closed += OnPositionsClosed;
}
private void OnPositionsClosed(PositionClosedEventArgs args)
{
if (args.position.Label != "m10_Robot" && args.position.Label != "m5_Robot") // only manual positions{
Print("Manually Position #{0} was closed", args.Position.Id);
}}
Is that code right?
@hichem
PaulGekko
22 Oct 2015, 11:59
RE: Good
I totally agree, the memory problem is the biggest issue of the platform. I have just reported it on the spotware site, please vote to rise its priority. Thank you
http://vote.spotware.com/forums/229166-ideas-and-suggestions-for-ctrader-and-calgo/suggestions/10316478-ctrader-and-calgo-use-an-excesive-amount-of-memory
jeex said:
Thanks Spotware. But to be honest: fixing the memory leak is more urgent.
@PaulGekko
Cerunnos
28 Nov 2013, 14:33
RE:
jeex said:
With using labels (Label = "m10_Robot" etc.) and a bridge which can pass variables between robots (Robolink from scyware.com)...
@Cerunnos