Close all trades at once - downloaded scripts not working

 

(MT5) when i drag the script from the left on the chart, then click OK it should close all open trades but NOTHING happens no matter what settings (if both checkmarks allowed or only one, inputs can't be wrong either).

also doesnt make any difference if i have on autotrading or not.

i tried all of the 3 downloaded scripts but never a f reaction.

i don't have any EA running, only indicators, is this the issue?

or what am i making wrong? or can you tell me an easy way to close ALL open positions at once? 

 
bosslife:

(MT5) when i drag the script from the left on the chart, then click OK it should close all open trades but NOTHING happens no matter what settings (if both checkmarks allowed or only one, inputs can't be wrong either).

also doesnt make any difference if i have on autotrading or not.

i tried all of the 3 downloaded scripts but never a f reaction.

i don't have any EA running, only indicators, is this the issue?

or what am i making wrong? or can you tell me an easy way to close ALL open positions at once? 

You can use this: And you can add it if(something)CloseAllPositions()

//Include a Class of the Standard Library
#include <Trade\Trade.mqh>

CTrade trade;

//For Example
//+--------------------------------------------------------------------------------------------------+
//| Close All Position if Loss is Greater than MAXALLOWEDLOSS                                        |
//+--------------------------------------------------------------------------------------------------+
if((((AccountInfoDouble(ACCOUNT_BALANCE)-AccountInfoDouble(ACCOUNT_EQUITY))/AccountInfoDouble(ACCOUNT_BALANCE))*100)
   >=MAXAllowedLoss && AccountInfoDouble(ACCOUNT_EQUITY)<AccountInfoDouble(ACCOUNT_BALANCE))
{
   Print("Close All Position if Loss is Greater than MAXALLOWEDLOSS");
   CloseAllPositions();
}

//+--------------------------------------------------------------------------------------------------+
//| Close All Positions                                                                              |
//+--------------------------------------------------------------------------------------------------+
void CloseAllPositions()
{
 for(int i=PositionsTotal()-1; i>=0; i--)
 {
   string symbol=PositionGetSymbol(POSITION_SYMBOL);
   ulong ticket=PositionGetTicket(i);
   if(PositionGetSymbol(POSITION_SYMBOL)==Symbol())
   {
      trade.PositionClose(ticket);
   }
 }
}