Mistake in example

Created at 03 May 2021, 10:41
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!
HS

hslagter

Joined 28.04.2020

Mistake in example
03 May 2021, 10:41


I am a beginner and tried the example. 

protected override void OnStart()
{
    Positions.Closed += PositionsClosed;
}
private void PositionsOnClosed(PositionClosedEventArgs args)
{
    var position = args.Position;
    Print("Position closed with {0} profit", position.GrossProfit);
}

It didn't work because

PositionsClosed is a wrong reference to PositionsOnClosed.

 


@hslagter
Replies

amusleh
04 May 2021, 11:06

Hi,

Your event handler and method name doesn't match, here is the working code:

protected override void OnStart()
{
    Positions.Closed += PositionsOnClosed;
}
private void PositionsOnClosed(PositionClosedEventArgs args)
{
    var position = args.Position;
    Print("Position closed with {0} profit", position.GrossProfit);
}

Please check API references for more examples.

You have to learn at least C# basics before starting to write C# code.


@amusleh