Robot Grid

Created at 27 Nov 2017, 10:25
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!
JA

jalmir.coelho@gmail.com

Joined 19.07.2017

Robot Grid
27 Nov 2017, 10:25


The table above sets up a series of orders that have been opened

I need to close certain orders

1 - order buy number 1
2 - order buy number 23
3 - order sell number 2
4- order to sell number 24

How to search for specific orders and close them?

I also need to capture the number of pips in each order that was closed

Example: Order number 1 = -1 pip
                Order number 23 = 10 pips

@jalmir.coelho@gmail.com
Replies

PanagiotisCharalampous
27 Nov 2017, 11:48

Hi jalmir.coelho@gmail.com,

You can close loop and close positions based on certain conditions as below.

            foreach (var position in Positions)
            {
                //Put here any condition required to close the position
                if (position.Pips < -1)
                    ClosePosition(position);
            }

If you need access to historical trades, use the History collection.

Let me know if the above information helps.

Best Regards,

Panagiotis


@PanagiotisCharalampous

jalmir.coelho@gmail.com
27 Nov 2017, 22:37 ( Updated at: 21 Dec 2023, 09:20 )

RE:

Panagiotis Charalampous said:

Hi jalmir.coelho@gmail.com,

You can close loop and close positions based on certain conditions as below.

            foreach (var position in Positions)
            {
                //Put here any condition required to close the position
                if (position.Pips < -1)
                    ClosePosition(position);
            }

If you need access to historical trades, use the History collection.

Let me know if the above information helps.

Best Regards,

Panagiotis

How to close only the highlighted blue order using your id?

how to get the value of pips (-1.7) and apply to a variable?
Do you have an example?

 


@jalmir.coelho@gmail.com

PanagiotisCharalampous
28 Nov 2017, 09:26

Hi jalmir.coelho@gmail.com,

You can find the position id by accessing the Position.Id parameter. See below

                if (position.Id.ToString() == "21260940")
                    ClosePosition(position);

You can store the value of pips in a variable as shown below

var pips = position.Pips;

Let me know if these are the answers you were looking for.

Best Regards,

Panagiotis


@PanagiotisCharalampous

cicondo
11 Dec 2017, 08:45 ( Updated at: 21 Dec 2023, 09:20 )

RE: RE:

jalmir.coelho@gmail.com said:

Panagiotis Charalampous said:

Hi jalmir.coelho@gmail.com,

You can close loop and close positions based on certain conditions as below.

            foreach (var position in Positions)
            {
                //Put here any condition required to close the position
                if (position.Pips < -1)
                    ClosePosition(position);
            }

If you need access to historical trades, use the History collection.

Let me know if the above information helps.

Best Regards,

Panagiotis

How to close only the highlighted blue order using your id?

how to get the value of pips (-1.7) and apply to a variable?
Do you have an example?

 

I would recommend to create a specific label for each order you're placing....

The best way to get a specific position is to use a LINQ expression like:

var position = (from p in positions where p.Label == "yourLabel" && p.Pips > 0 select p).FirstOrDefault();

So you dont need to iterate through any collection, thats a direct query ;-)

Cheers Markus


@cicondo