Latest Version Update OnPositionOpened OnPositionClosed

Created at 20 Dec 2013, 06:25
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!
JA

jayemtrading

Joined 20.12.2013

Latest Version Update OnPositionOpened OnPositionClosed
20 Dec 2013, 06:25


Hi,

I got the latest update of cAlgo installed and created a new robot. I am using ExecuteMarketOrder and  PlaceStopOrder. For some reason neither are triggering OnPositionOpened or OnPositionClosed. I'm sure this was working fine before the update.

 

protected override void OnPositionOpened(Position openedPosition)

protected override void OnPositionClosed(Position closedPosition)

 

Any help please?

John


@jayemtrading
Replies

Spotware
20 Dec 2013, 10:08

OnPositionOpened / OnPositionClosed will not be raised with the new API methods. Instead you can subscribe events such as in the following example.

The new API allows the use of synchronous as well as asynchronous operation.
ExecuteMarketOrder is using synchronous operation and will not continue to the next statement but will wait until the trade request response from the server is returned. Therefore, you can access position information from the result. You can also subscribe an event to be raised when the position opens.

Please read the Guide and the thread on the New Trading API for more information.

example

protected override void OnStart()
{
    Positions.Opened += PositionsOnOpened;

    var result = ExecuteMarketOrder(TradeType.Buy, Symbol, 10000, "label");            
    if(result.IsSuccessful)
        Print(result.Position.EntryPrice);    
}
private void PositionsOnOpened(PositionOpenedEventArgs args)
{
    var pos = args.Position;
    // etc...
    Print("Position opened at {0}", pos.EntryPrice);
}

 


@Spotware

jeex
27 Dec 2013, 23:42

... does not exist
Positions.Closed += PositionsOnClosed;

Gives the error: PositionsOnClosed does not exist...


@jeex

jeex
28 Dec 2013, 00:42

RE: ... does not exist

jeex said:

Positions.Closed += PositionsOnClosed;

Gives the error: PositionsOnClosed does not exist...

Found it. Above line of code is copied from Spotware examples. This of course should be

Positions.Closed += OnPositionsClosed;

 


@jeex

Spotware
30 Dec 2013, 14:35

RE: ... does not exist

Any subscribed method has to be defined. 

See the examples here:

/api/reference/positionclosedeventargs
/api/reference/positionopenedeventargs

jeex said:

Positions.Closed += PositionsOnClosed;

Gives the error: PositionsOnClosed does not exist...

 


@Spotware

jeex
31 Dec 2013, 13:43

On Positions Modified

I cannot find if there is a OnPositionsModified. Would come in handy for my Semi-robots.


@jeex

Spotware
02 Jan 2014, 09:31

RE: On Positions Modified

Not yet but we will include an event for positions being updated.

jeex said:

I cannot find if there is a OnPositionsModified. Would come in handy for my Semi-robots.

 


@Spotware