|
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
|