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
bdandiClose the order after u change the lot value. U can overwrite the lot value in any numbe u want (up to the order lot value)
Close the order after u change the lot value. U can overwrite the lot value in any numbe u want (up to the order lot value)
Thanks elihayun,
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).
Thanks elihayun, 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).
I think u can't do that. Instead open 3 pending orders with the lot size and T/P that u like
Perhaps there could be a script written for it?
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
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
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
EACANOne thing more which i wrote is that we could modify the stoploss everytime we close the last order and place it as we wish
Thanks elihayun and Firedave for your advice.
bdandi
How to partial close an open position.....
Hi Guys,
How can I partially close an open position when the price reaches a certain point...
Thanks
Babar
Can anyone complete this EA for multi target strategies ?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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