- Use an array of structs, and resize it for every new position. You'll have to use a for loop to look-up a certain ticket.
- Or, use a hash map.
The struct approach looks like this:
struct SPosition { int type; ulong ticket; double orderSL,orderTP; double virtualTP; }; SPosition Positions[]; int ticket_num=0; void GetPositions() { for(int i=PositionsTotal()-1; i>=0; i--) { ulong ticket=PositionGetTicket(i); if(ticket>0) { int pos; for(pos=ArraySize(Positions)-1; pos>=0; pos--) { if(Positions[pos].ticket==ticket) break; } if(pos<0) { pos=ArraySize(Positions); ArrayResize(Positions,pos+1); ZeroMemory(Positions[pos]); Positions[pos].ticket=ticket; } Positions[pos].type=(int)PositionGetInteger(POSITION_TYPE); Positions[pos].orderTP=PositionGetDouble(POSITION_TP); Positions[pos].orderSL=PositionGetDouble(POSITION_SL); if(Positions[pos].orderTP>0) { Positions[pos].virtualTP=Positions[pos].orderTP; trade.PositionModify(ticket,Positions[pos].orderSL,0); } } } ticket_num=ArraySize(Positions); }
lippmaje:
- Use an array of structs, and resize it for every new position. You'll have to use a for loop to look-up a certain ticket.
- Or, use a hash map.
The struct approach looks like this:
work perfect !!!
thank you bro :]

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
im using MQL5 and i want delete the tp of the position and to know what was the tp before [virtual_tp], and then to use is at the future
1. i tried to set a array for the ticket but the number of the ticket is too large , the max is 7 digits and the ticket digits in 8+
its work for me ok because the ticket num was just 7 digits, but when i give it to my friend he had ticket num of 9 digits and get error "array is out of range " (i cant make a array more then that )
2. i try the next way but when i have more then 1 trade and i close one of trade at the next time that the loop run the place that virtual_tp store is not update beacuze the posion place was changed in the loop
please any idea out to fix that ?