Before you use PositionGetInteger you need to select this position. So first detect the signal for closing and when it’s confirmed – you need to go in a loop of all trades and close only the trades from opposite direction for example:
if(signal=”buy”){ for(int i=PositionsTotal()-1;i>=0;i--){ if(uint ticket = PosititionGetTicket(i)){ if(PositionGetInteger(POSITION_TYPE)== POSITION_TYPE_SELL){ //close sell on buy signal trade.PositionClose(ticket); } } }
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 new into programming and i trying to figure out how to close a position on the opposide signal but i my tries dont work i watched different videos but no reult.
i know the code is a bit messy but could someone help me please