no problem. You can close positions partially. just do it.
OK, but the next code does not work!
if ((OrderProfit()/(Lots*10)>=30)&&(OrderLots()==Lots))
{
if (OrderType()==OP_SELL)
OrderClose(OrderTicket(),OrderLots()/2,Ask,Slippage,Red);
else
OrderClose(OrderTicket(),OrderLots()/2,Bid,Slippage,Red);
}
if ((OrderProfit()/(Lots*10)>=30)&&(OrderLots()==Lots))
{
if (OrderType()==OP_SELL)
OrderClose(OrderTicket(),OrderLots()/2,Ask,Slippage,Red);
else
OrderClose(OrderTicket(),OrderLots()/2,Bid,Slippage,Red);
}
what is "does not work"?
you need to expose log records with errors. there may be severe reasons
you need to expose log records with errors. there may be severe reasons
I mean there is no error in the logs and no trade is closed(half of the lot).
If I use this one on usdjpy:
if ((OrderProfit()/(Lots*10)>=30)&&(OrderLots()==Lots))
{
Print(OrderSymbol());
if (OrderType()==OP_SELL)
OrderClose(OrderTicket(),OrderLots()/2,Ask,Slippage,Red);
else
OrderClose(OrderTicket(),OrderLots()/2,Bid,Slippage,Red);
}
The only thing that is printed in logs is "usdjpy".
If I use this one on usdjpy:
if ((OrderProfit()/(Lots*10)>=30)&&(OrderLots()==Lots))
{
Print(OrderSymbol());
if (OrderType()==OP_SELL)
OrderClose(OrderTicket(),OrderLots()/2,Ask,Slippage,Red);
else
OrderClose(OrderTicket(),OrderLots()/2,Bid,Slippage,Red);
}
The only thing that is printed in logs is "usdjpy".
did You check last error after closing? I see You don't check both operation's result and last occured error.
please study our script samples!
please study our script samples!
ERR_INVALID_TRADE_VOLUME 131 Invalid trade volume.
try to normalize your lot value
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Example: An expert script opened position with 1lot, if profit is 50pips I want to close 0,5lots
and leave the other 0,5lots running.