getting a specific position by label

Created at 19 May 2013, 21:16
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!
lec0456's avatar

lec0456

Joined 14.11.2012

getting a specific position by label
19 May 2013, 21:16


I noticed some code in the Sample Trailing Stop loss that seemed to get a position by ID can you do the same with the label?  If so how do you modify this code to get it to work?

 

I don't see any documentation on the method FirstOrDefault

 

private Position Position

        {

            get { return Account.Positions.FirstOrDefault(position => position.Id == PositionId); }

        }


@lec0456
Replies

cAlgo_Fanatic
20 May 2013, 10:34

You can replace ID by Label. Since for the time being you cannot set the label for manual trades this will work with existing positions created by a robot where you can specify the label.

[Parameter("Position Label")]
public string PositionLabel { get; set; }
//...
private Position Position
{
    get { return Account.Positions.FirstOrDefault(position => position.Label == PositionLabel); }
}
//...
private void CheckPosition()
{
    if (Position == null)
    {
        Print("Invalid position Label {0} or position closed ", PositionLabel);
        Stop();
    }
}
//...

Documentation for C# syntax and examples may be found on the msdn website.

FirstOrDefault


@cAlgo_Fanatic

diogene823
20 May 2013, 14:14

Sorry, it's possible change the label of an order?

For example if i have a trailing stop robot that follow all trade with a specify label

and i will that today one trade it's not follow from the robot but follow manually i change the label of this trade and

the robot don't follow it anymore.

When i will that the robot follow this trade again i change the label whit the old label...

it's possible?

Thanks all for the answer.


@diogene823

atrader
22 May 2013, 17:35

No, it is not possible to change the Label. You may stop the robot when you want it to stop trailing the order and then restart it when you need to.


@atrader

diogene823
22 May 2013, 22:56

Thanks Atrader,

but if the robot trailing more than one trade and you will follow only one trade manualy?

Thanks

Regards


@diogene823