extern int lockprofit = 100;
extern int pipstolock = 1;
void Lockprofit() {
double v1 = 0.0,
v2 = 0.0;
double sl = 0.0,
ptl = 0.0;
for (int i = 0; i < OrdersTotal(); i++) {
if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
if (OrderSymbol() == Symbol() && OrderMagicNumber() == mgc) {
if (OrderType() == OP_BUY) {
v2 = floor((Bid - OrderOpenPrice())/lockprofit);
if ((v1 < v2) && (v2 != 0)) {
v1 = v2;
ptl = ((v1 - 1) * lockprofit) + pipstolock;
sl = OrderOpenPrice() + (ptl * Point);
if (OrderStopLoss() < sl) {
if (!OrderModify(OrderTicket(), OrderOpenPrice(), sl, OrderTakeProfit(), 0, Green))
Print("OrderModify Buy : ", GetLastError());
}
}
}
if (OrderType() == OP_SELL) {
v2 = floor((OrderOpenPrice() - Ask)/lockprofit);
if ((v1 < v2) && (v2 != 0)) {
v1 = v2;
ptl = ((v1 - 1) * lockprofit) - pipstolock;
sl = OrderOpenPrice() - (ptl * Point);
if (OrderStopLoss() > sl) {
if (!OrderModify(OrderTicket(), OrderOpenPrice(), sl, OrderTakeProfit(), 0, Red))
Print("OrderModify Sell : ", GetLastError());
}
}
}
}
}
}
if(LockProfitAfter>0 && ProfitLock>0 && Points>=LockProfitAfter)
{
if(Points<=LockProfitAfter+TrailingStop)
LockProfit(OrderTicket(),LockProfitAfter,ProfitLock);
else if(Points>=LockProfitAfter+TrailingStop)
SteppingTrailingStop(OrderTicket(),TrailingStop,TrailingStep);
}
else if(LockProfitAfter==0)
SteppingTrailingStop(OrderTicket(),TrailingStop,TrailingStep);
siap mascoba masnya liat kode di sini https://www.mql5.com/en/code/11649
ini sebagian kodenya
Code:if(LockProfitAfter>0 && ProfitLock>0 && Points>=LockProfitAfter) { if(Points<=LockProfitAfter+TrailingStop) LockProfit(OrderTicket(),LockProfitAfter,ProfitLock); else if(Points>=LockProfitAfter+TrailingStop) SteppingTrailingStop(OrderTicket(),TrailingStop,TrailingStep); } else if(LockProfitAfter==0) SteppingTrailingStop(OrderTicket(),TrailingStop,TrailingStep);
void TrailingStop(int trailingpip)
{
double point=MarketInfo(Symbol(),MODE_POINT);
int traillingtmp=trailingpip;
int suc;
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderProfit()>0)
{
if(OrderType()==OP_BUY)
{
if(OrderStopLoss()<OrderOpenPrice())traillingtmp=2;
if((OrderClosePrice()-OrderOpenPrice())/point>traillingtmp && (OrderClosePrice()-OrderStopLoss())/point>traillingtmp * 2)
{
suc=OrderModify(OrderTicket(),OrderOpenPrice(),OrderClosePrice()-(traillingtmp*point),0,0,clrNONE);
}
}
else if(OrderType()==OP_SELL)
{
if(OrderStopLoss()>OrderOpenPrice())traillingtmp=2;
if((OrderOpenPrice()-OrderClosePrice())/point>traillingtmp && (OrderStopLoss()-OrderClosePrice())/point>traillingtmp * 2)
{
suc=OrderModify(OrderTicket(),OrderOpenPrice(),OrderClosePrice()+(traillingtmp*point),0,0,clrNONE);
}
}
}
}
}
}