How can I close a part of a market order?

 

How can I close a part of a market order? Not the whole order, just a part of it, for example one half, one third etc.

I want to do the following:

1. Open a market position (buy or sell)

2. When my first profit target is reached, close half of the position. For the remaining order, set a new stoploss

3. when my second profit target is reached then close the remaining position.

Before I start coding, getting crazy and ripping my hair off my head I just want to ask. Does anyone have a good way to do this, some code or can you direct me forward to where it can be found?

 
wmrazek wrote >>

How can I close a part of a market order? Not the whole order, just a part of it, for example one half, one third etc.

I want to do the following:

1. Open a market position (buy or sell)

2. When my first profit target is reached, close half of the position. For the remaining order, set a new stoploss

3. when my second profit target is reached then close the remaining position.

Before I start coding, getting crazy and ripping my hair off my head I just want to ask. Does anyone have a good way to do this, some code or can you direct me forward to where it can be found?

extern double Lots=0.5;

extern double CloseLots=0.2;

.....

if (BuyCondition) OpenOrder(...Lots);

....

if (FirstProfitReached&&OrderLots()==Lots) //Compare if you still have the full order

{

OrderModify(...NewStopLoss..);//First modify the order

OrderClose(...CloseLots......); //then close a part

}

 
Thanks! I wasn't sure but now I see that "OrderClose" can be used for a part of the position. Does modify (newstoploss) have to be before orderClose, or can I do first orderClose and second modify?
 

please note that NOT all brokerages support partial closing. You need to check with your brokerage to make sure it does.

One way to go around this issue (and to make sure your EA will work on any brokerage) is by opening separate orders for each part that you need to close. For example instead of opening 1 full lot and trying to close 0.5 of it, you can simply open 2 orders x 0.5 lots each and then close the first one and modify the SL of the second...

thank you

Automated (automatedfx@gmail.com)

--

my recent grid trading:

http://fx-grid2.forexmosaic.com/ - 8621 pips in 7 weeks

http://fx-grid3.forexmosaic.com/ - 2068 pips in 3 weeks

 

Thanks Automated, I think that will also be easier for me to administrate the orders.

Reason: