Dilchan:
Hi,
What would be the right code if I have 5 buy open positions and I want to delete only the last buy position the 5th one only?
Thanking you in advance!
#include <Trade\Trade.mqh> void OnStart() { CPositionInfo p; CTrade t; ulong ticket=0; datetime time=0; for(int i=PositionsTotal()-1; i>=0; --i){ if(p.SelectByIndex(i) && p.Symbol() == _Symbol && p.Time() > time ){ time = p.Time(); ticket = p.Ticket(); } } if(t.PositionClose(ticket)) Print("position closed "); }
nicholi shen:
Thank you very very much!
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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
Hi,
What would be the right code if I have 5 buy open positions and I want to delete only the last buy position the 5th one only?
Thanking you in advance!