Closing all the open orders when new ones are place

 
Guys i want to know if it's possible for all the running orders to be closed when new orders of opposite direction are placed, please help i've looked all over the internet for such a code but no luck, thank you
 
Sechene.9604:
Guys i want to know if it's possible for all the running orders to be closed when new orders of opposite direction are placed, please help i've looked all over the internet for such a code but no luck, thank you

yes it's possible. Show (post) your code and you may get help....

 
Sechene.9604 :
Guys i want to know if it's possible for all the running orders to be closed when new orders of opposite direction are placed, please help i've looked all over the internet for such a code but no luck, thank you

The algorithm is as follows: calculate how many positions BUY and SELL are available. Depending on the trading signal, first close the opposite positions.

Example code from the adviser Four Timeframes (here we close all SELL positions)

            int      count_buys           = 0;
            double   volume_buys          = 0.0;
            double   volume_biggest_buys  = 0.0;
            int      count_sells          = 0;
            double   volume_sells         = 0.0;
            double   volume_biggest_sells = 0.0;
            CalculateAllPositions(count_buys,volume_buys,volume_biggest_buys,
                                  count_sells,volume_sells,volume_biggest_sells);
            if(InpCloseOpposite)
              {
               if(count_sells>0)
                 {
                  double level;
                  if(FreezeStopsLevels(level))
                     ClosePositions(POSITION_TYPE_SELL,level);
                  return;
                 }
              }
Four Timeframes
Four Timeframes
  • www.mql5.com
Советник проверяет направление бара #0 (это самый правый бар, который Вы видите на графике) сразу на четырёх таймфреймах  Timeframe #1, Timeframe #2, Timeframe #3 и Timeframe #4. Если все четыре бара направлены в одну сторону - это будет торговым сигналом для открытия позиции. Проверка сигнала производится (по-возможности) раз в 10 секунд. Вы...
Reason: