- Partially close a trade
- Competition. I will write an expert for free.
- [WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you.
- If you show your attempts and describe your problem clearly, you will most probably receive an answer from the community.
- You can also look at the Codebase if something already similar exists, so that you may study it.
- Finally, you also have the option to hire a programmer in the Freelance section.
Here is a sample code from the CodeBase ...
closing partially script and Stop loss to Break Even point
Mehmet Bastem, 2021.06.24 16:55
closing partially script and Stop loss to Break Even point
Your question is not related to the section you posted so it has been moved to the appropriate section: MQL5 forum: Expert Advisors and Automated Trading
here is what i came up with but when it is ran in the strategy tester it freezes as soon as the first stop order is hit.
I would like to know how to close partial profits on an open position every ten pips, so for example if a position was opened at 1.10000 i would like it to close a 10% partial at 1.10100 and then another 10% at 1.0200 and another 10% at 1.10300 and so on. I would like it to do this for all positions.
void ClosePartials() { double currentPrice = SymbolInfoDouble(_Symbol, SYMBOL_BID); int totalPositions = PositionsTotal(); for(int i=PositionsTotal()-1;i>=0;i--) { ulong ticket = PositionGetTicket(i); if(PositionSelectByTicket(ticket)) { double openPrice = PositionGetDouble(POSITION_PRICE_OPEN); double posVolume = PositionGetDouble(POSITION_VOLUME); double pipsProfit = (((openPrice-currentPrice)/_Point))/10; pipsProfit = NormalizeDouble(pipsProfit,_Digits); for(i; i<totalPositions; i++) { double lotsToClose = posVolume*0.1; if(pipsProfit>0&&(int)pipsProfit%10==0) { trade.PositionClosePartial(ticket,lotsToClose); } } } } }
I have edited your Improperly formatted code. In future, please use the CODE button (Alt-S) when inserting code.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use