problem with: OnPositionsClosed

Created at 25 Jul 2020, 22:32
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!
LU

luca.tocchi

Joined 25.03.2020

problem with: OnPositionsClosed
25 Jul 2020, 22:32


I'm using the OnPositionsClosed function

 

private void OnPositionsClosed(PositionClosedEventArgs args)
        {
            var position = args.Position;
            var position1 = Positions.Find("MyLabel");
            var position2 = Positions.Find("MyLabel");
 

           ecc...

        }

 

the bot does not recognize the position1 and position2 variables.

var position = args.Position: does this function cause all closed positions whatever their label label to be marked with "position"?

I do not understand why.

 


@luca.tocchi
Replies

PanagiotisCharalampous
27 Jul 2020, 08:21

Hi Luca,

What do you mean when you say?

the bot does not recognize the position1 and position2 variables.

You need to use a more precise language.

 Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

luca.tocchi
27 Jul 2020, 11:15

RE:

PanagiotisCharalampous said:

Hi Luca,

What do you mean when you say?

the bot does not recognize the position1 and position2 variables.

You need to use a more precise language.

 Best Regards,

Panagiotis 

Join us on Telegram

 

what I want to say: 

private void OnPositionsClosed(PositionClosedEventArgs args)
        {
            var position = args.Position;

        }

the function considers all positions that close regardless of the label

I need to tell him: if position 1 (var position1 = Positions.Find ("MyLabel1") is closed do this .. 

so also for other positions with different labels, 

but I can't ... because it considers all positions closed regardless of the label

 


@luca.tocchi

PanagiotisCharalampous
27 Jul 2020, 11:23

Hi Luca,

Try this

if(args.Position.Label == "MyLabel1")
{
  // Do something...
}

You need to use a more precise language.

 Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

luca.tocchi
27 Jul 2020, 11:26

RE:

PanagiotisCharalampous said:

Hi Luca,

Try this

if(args.Position.Label == "MyLabel1")
{
  // Do something...
}

You need to use a more precise language.

 Best Regards,

Panagiotis 

Join us on Telegram

awesome! thanks


@luca.tocchi