Update the position ID in comment

Created at 05 Sep 2022, 08: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!
VE

velu130486

Joined 08.11.2019 Blocked

Update the position ID in comment
05 Sep 2022, 08:41


Dear All,

Please help me to how to copy Position ID in comment section when ever I execute the market order or limit order. Currently the comment column is blank and I want to add the position ID.

Thanks and Regards

R. Vadivelan

 


Replies

PanagiotisCharalampous
05 Sep 2022, 11:38

Hi Vadivelan,

It is not possible to edit position comments at the moment.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

velu130486
05 Sep 2022, 13:42

RE:

Hi Panagiotis,

I understand the comments can't be edited, thats why it is possible to add the position ID in comments while executing the order itself via Cbot like label.

Or Please help me to find the positions which Position ID and Comment is matching, because I have a Cbot which creates opposite order (with Position ID in comments) after certain condition. Now I want to close the positions except the 2 positions which position ID and comments are matching.

Note : I am not a developer, last time I got support from this forum for creating the opposite orders. Now I want to filter out the positions in Cbot.

Thanks and Regards,

R. Vadivelan

PanagiotisCharalampous said:

Hi Vadivelan,

It is not possible to edit position comments at the moment.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

 


PanagiotisCharalampous
05 Sep 2022, 14:24

Hi Vadivelan,

It is not possible because you cannot know the position id before it is executed.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

velu130486
05 Sep 2022, 16:55 ( Updated at: 21 Dec 2023, 09:22 )

RE:

Hi Panagiotis,

Since it is not possible to edit the comments, could you please help me to filter the position which position ID is not available in Comments.

As you can see from the above picture I have position ID and comments column so I want to filter the position for which Position ID is not in comments, yellow highlighted position to do some action.

 foreach (var pos in positionsCopy)
            {
				// if position comment is empty then skip it
				if (string.IsNullOrWhiteSpace(pos.Comment)) continue;
				
				var commentSplit = pos.Comment.Split('PID');
				if (commentSplit.Length < 2) continue;
				var originalPositionIdString = commentSplit[1];
				
				long originalPositionId;
				
				if (!long.TryParse(originalPositionIdString, out originalPositionId)) continue;
				
				var originalPosition = Positions.FirstOrDefault(position => position.Id == originalPositionId);
				
				if (originalPosition == null) continue;
				
				// Now you have the original position on originalPosition variable
            }

Earlier I got support from this forum for the above code however it is not working fine. So could you please help me to filter the positions comment is blank and also position ID is not existing in other positions?

Thanks and Regards

R. Vadivelan

PanagiotisCharalampous said:

Hi Vadivelan,

It is not possible because you cannot know the position id before it is executed.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

 


PanagiotisCharalampous
06 Sep 2022, 08:45

Hi Vadivelan,

I am still not sure about your requirements but you can try this

 foreach (var pos in Positions.Where(p => Positions.Count(ps => ps.Comment == p.Id.ToString()) == 0))

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

velu130486
07 Sep 2022, 07:26

RE:

Hi Panagiotis,

Thanks for your reply and sorry for not making it clear. I explain the thing to be done as below

Assume that have 2 position opened

PID10001

PID10002

I am creating the hedging order based on certain pips loss, so hedging order is created as below

PID10003  ---------------> Hedging order so in comment I have "PID100001" original position ID

Now I want to compare all 3 positions and eliminate original and hedging order to close the remaining position based on condition

In the above case I need to close PID10002.

Please help me how to do this in a proper way

Thanks and Regards

R. Vadivelan

PanagiotisCharalampous said:

Hi Vadivelan,

I am still not sure about your requirements but you can try this

 foreach (var pos in Positions.Where(p => Positions.Count(ps => ps.Comment == p.Id.ToString()) == 0))

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

 


PanagiotisCharalampous
07 Sep 2022, 08:34

Hi Vadivelan,

Did you try my suggestion?

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

velu130486
07 Sep 2022, 08:58

RE:

Hi Panagiotis,

Yes I tried your suggestion, as below but it print all the open position ID. However my request is to get the position ID for which hedging position is not yet available

 private void unique()
  {
  foreach (var pos in Positions.Where(p => Positions.Count(ps => ps.Comment == p.Id.ToString()) == 0))
  Print(pos.Id);
  }

I request your support on this,. Please let me know If I had done something wrong

Thanks and Regards

R. Vadivelan

PanagiotisCharalampous said:

Hi Vadivelan,

Did you try my suggestion?

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

 


PanagiotisCharalampous
07 Sep 2022, 09:17

Hi Vadivelan,

The code below works fine for me

          foreach (var pos in Positions.Where(p => Positions.Count(ps => ps.Comment == "PID" + p.Id.ToString()) == 0 && p.Comment == null))
            Print(pos.Id);

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

velu130486
07 Sep 2022, 10:55

RE:

Hi Panagiotis,

Thanks for your support. Yes I got all the Position ID as per my requirement.

Thanks and Regards

R. Vadivelan

PanagiotisCharalampous said:

Hi Vadivelan,

The code below works fine for me

          foreach (var pos in Positions.Where(p => Positions.Count(ps => ps.Comment == "PID" + p.Id.ToString()) == 0 && p.Comment == null))
            Print(pos.Id);

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

 


aeonfor
25 Oct 2022, 12:52 ( Updated at: 26 Oct 2022, 14:24 )

 I want to close the positions except the 2 positions which position ID and comments are matching.  forpc.onl  youtube vanced for pc


@aeonfor