Need help for my expert advisior close position on opposite order
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); } } }
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