OnPositionClosed in other instance

Created at 28 Nov 2013, 14:14
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!
jeex's avatar

jeex

Joined 18.10.2013

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.


@jeex
Replies

Cerunnos
28 Nov 2013, 14:33

RE:

jeex said:

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.

With using labels (Label = "m10_Robot" etc.) and a bridge which can pass variables between robots (Robolink from scyware.com)...


@Cerunnos

hichem
28 Nov 2013, 14:35

From the new API:

 

Positions.Closed+= OnPositionsClosed;

 

will handle all closed positions not only in the current robot


@hichem

jeex
28 Nov 2013, 14:42

History

Thanks for the reply. Another posibility is using the history. But i don't see how to aproach the history positions.


@jeex

Cerunnos
28 Nov 2013, 16:17

RE:

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


@Cerunnos

Spotware
28 Nov 2013, 16:25

Access to historical trades is not yet available but it is planned.


@Spotware

jeex
28 Nov 2013, 16:31

Good

Thanks Spotware. But to be honest: fixing the memory leak is more urgent.


@jeex

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

Cerunnos
28 Nov 2013, 18:33

@ hichem

Thanks a lot!


@Cerunnos

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