Close all positions

 

Sorry for the silly Q :P but I'm wondering... how do you close all positions? I can't seem to figure out how to code it into my EA :(

Thanks 

 
MoForce posted  :

Sorry for the silly Q :P but I'm wondering... how do you close all positions? I can't seem to figure out how to code it into my EA :(

Thanks 

Try this

#include <trade/trade.mqh>

void OnStart()
  {
   CTrade trade;
   int i=PositionsTotal()-1;
   while (i>=0)
     {
      if (trade.PositionClose(PositionGetSymbol(i))) i--;
     }
  }

 

 

Reason: