Good morning people,
I would like a help, unfortunately I am still a beginner in programming, I know how to do the basics but I always get a lot.
I am having difficulty changing a TRAILING STOP mode that I currently use, I have tried several times and I have not been able to solve it.
What happens is that this TRAILING module is only capable of managing a single position at a time.
I would like help to change the module so that it can manage the multi-position TRAILING STOP at the same time.
Thanks in advance for your help.
If this is mql5 code Ask/Bid are not available as is.
If this is mql4 code PositionXXX() functions are not available.
They are MQL5 codes.
This is just the module.
Some parameters I put straight on ontick
Ask = SymbolInfoDouble(Symbol(),SYMBOL_ASK); Bid = SymbolInfoDouble(Symbol(),SYMBOL_BID);
From beforehand I would like to thank the help.
Of the hundreds of forums I've read, I always see you helping colleagues.
It would be harder if we did not have help from the more experienced people
thank you.
I put the EA to make it clearer
Your original posted code is not the same as in your attached file.
int _tp=PositionsTotal(); for(int i=_tp-1; i>=0; i--) { ulong tick=PositionGetTicket(i); if(PositionGetString(POSITION_SYMBOL)==_Symbol) // Add here needed filters : symbol ? magic ? { double _p_tp = PositionGetDouble(POSITION_TP); double _p_sl = PositionGetDouble(POSITION_SL); double _p_op = PositionGetDouble(POSITION_PRICE_OPEN); long _p_type = PositionGetInteger(POSITION_TYPE); if(_p_type==POSITION_TYPE_BUY && ((Ask-_p_op)>TrailStop*Point())) { newsl=Ask-(TrailStep*Point()); if(newsl>_p_sl && newsl!=_p_sl) { trade.PositionModify(_Symbol,newsl,_p_tp); } } if(_p_type==POSITION_TYPE_SELL && (_p_op-Bid>TrailStop*Point())) { newsl=Bid+(TrailStep*Point()); if((_p_sl>newsl || _p_sl==0) && newsl!=_p_sl) { trade.PositionModify(_Symbol,newsl,_p_tp); } } } }NOT TESTED
Your original posted code is not the same as in your attached file.
NOT TESTEDI should have sent a version with some minor change that I have made trying to solve the problem, but it continues with the same function, managed only the first open position. I'll send the correct night
Thanks for the help, as soon as I get home I will test the code that you attached.
I'll check which one I sent and send the correct code at night.
Thank you my friend.
It did not work, EA can not manage the trailing stop individually from all positions at the same time.
I attached the EA with the change to look at.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Good morning people,
I would like a help, unfortunately I am still a beginner in programming, I know how to do the basics but I always get a lot.
I am having difficulty changing a TRAILING STOP mode that I currently use, I have tried several times and I have not been able to solve it.
What happens is that this TRAILING module is only capable of managing a single position at a time.
I would like help to change the module so that it can manage the multi-position TRAILING STOP at the same time.
Thanks in advance for your help.