I want the code to ensure all trades are closed. Will this while loop function? Do I run the risk of becoming stuck?
if you want to know is all the trades are close,you need to see if there are positions.
to do it,you can use :
if(PositionsTotal() == 0) { //there aren't positions . }
if you want to know is all the trades are close,you need to see if there are positions.
to do it,you can use :
Sorry, I didn't explain myself properly. I meant all trades that I'm targeting (Magic number).
Sorry, I didn't explain myself properly. I meant all trades that I'm targeting (Magic number).
bool istherepositions(int magic) { if(PositionsTotal() == 0) { return false; } for(int i=0;i<PositionsTotal();i++) { ulong ticket = PositionGetTicket(i); bool selected = PositionSelectByTicket(ticket); if(selected) { if(PositionGetInteger(POSITION_MAGIC) == magic) { return true; } } } return false; // if there're positions but the magic number doesn't match. }
Hi,check this method ,i think this resolve your problem.
it will only return true if there's position open and the position's magic number is what you targeting.
(the code wasn't compiled)
Hi,check this method ,i think this resolve your problem.
it will only return true if there's position open and the position's magic number is what you targeting.
(the code wasn't compiled)
Thank you brother
Hi,check this method ,i think this resolve your problem.
it will only return true if there's position open and the position's magic number is what you targeting.
(the code wasn't compiled)
That's mql5 code, that original code is mql4.
Sorry i didn't know cause the topic wasn't in the mt4 session
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I want the code to ensure all trades are closed. Will this while loop function? Do I run the risk of becoming stuck?