| New signals service! | |
|
|||||||
| Register in Forex TSD! | |
|
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time). Click here to register and get more information |
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
How to partial close an open position.....
Dear All,
How do I close the trade to take partial profit in MT4? For example sell 0.4 lot, take profit for 0.1 lot at 20 pips, 0.1 lot at 40 pips, 0.1 lot at 60 pips and 0.1 lot at 80 pips. The terminal only shows TP for the whole order (i.e. 0.4 lot). Thanks in advance bdandi |
|
|||
|
Quote:
I've managed to close as you suggested for Instant Execution but I still haven't figure out for Pending Execution (i.e. I want the partial order to close once the TP is reached without waiting at the computer). |
|
||||
|
Quote:
|
|
||||
|
If you enter a trade with 0.4 lot and like to have seperate TP for each 0.1 lot, just make 4 limit order, 0.1 lot each, for each TP. Then when you get back to your PC, close any limit order that filled with CLOSE-BY command. I think this feature can also coded to a script. Hope this help
![]()
__________________
David Michael H "Trader helps traders with sincerity, honesty and integrity" |
|
|||
|
Hi,
My first attempt would be // lets difine our ea variables only what we need to get the lots functionality extern double Lots = 0.4; // the total order size you need. extern double OneLot = 0.1; // How many lots you want to take off. // lets define Tp extern double firstTP = 20; extern double secondTP = 40; extern double thirdTP = 60; extern double fourthTP = 80; int start() { // This variable is used for taking lots double ls = Lots; // 0.4 // Lets start closing say our sell position after some 1st Tp,2nd TP etc. total = OrdersTotal(); for(cnt = 0; cnt<OrdersTotal(); cnt++) { OrderSelect(cnt,Select_BY_POS, Mode_Trades); if(OrderSymbol() == Symbol() && OrderType() == OP_SELL ) { // Close the First Lot at 20 TP.. if(Bid>(OrderOpenPrice()+firstTp*Point)&& ls>= 0.4) //(1) OrderClose(OrderTicket(),OneLot,Bid,3,CLR_NONE); // You could now modify the SL to be placed at the price you opened //the order or as you wish how you want to trail. ls--; return(0); } } } (1). I am using ls as a control variable to decrease the lot each time we meet our tp.. Note that i am using every time 0.4,0.3etc( just to show how one can compare with the total lots . (2). This is how you would close the second lot see i am checking as <= (less or equals) else if(Bid>(OrderOpenPrice()+secondTP*Point)&& ls <= 0.3) { OrderClose(OrderTicket(),OneLot,Bid,3,CLR_NONE); ls--; return(0); } Ofcourse there are better ways to write this code but this is my first attempt. regards EACAN |
|
|||
|
Quote:
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Close Position(s) when Price hits MA | zhu28ming | Setup Questions | 2 | 01-18-2007 06:34 AM |
| Managing your position after its open... | Kurka Fund | Expert Advisors - Metatrader 4 | 2 | 11-30-2006 11:10 PM |
| Alarm or close current position when price hit a MA. | zhu28ming | Expert Advisors - Metatrader 4 | 1 | 09-26-2006 11:04 PM |
| close open position one shot manually | dreamer | Setup Questions | 1 | 07-07-2006 01:08 PM |
| Checking for open position | caldolegare | Metatrader 4 | 1 | 01-26-2006 07:00 PM |