Mistake in example

0
Votes

hslagter since: 28 Apr 2020;

  03 May 2021, 10:41
Mistake in example
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.

amusleh's avatar

amusleh since: 01 Mar 2021;

  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.

Community Developer | Spotware