//+------------------------------------------------------------------+ //| Quick Exit.mq4 | //| Copyright © 2007, GallantFX | //| http://www.gallantfx.com | //+------------------------------------------------------------------+ #property copyright "Copyright © 2007, GallantFX" #property link "http://www.gallantfx.com" //+------------------------------------------------------------------+ //| script program start function | //+------------------------------------------------------------------+ int start() { double percent = 0.01; //1 = %100 //---- int j=0; while (true){ j++; if (AccountProfit() > (AccountBalance()*percent)) { Print ("GFX - Quick Exit is closing all orders due to a profit bigger then ",AccountProfit(), " (%",percent*100," of ",AccountBalance(),")"); PlaySound("tada.wav"); // Closing All Orders int total = OrdersTotal(); for(int i=total-1;i>=0;i--) { OrderSelect(i, SELECT_BY_POS); int type = OrderType(); bool result = false; switch(type) { //Close opened long positions case OP_BUY : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red ); break; //Close opened short positions case OP_SELL : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red ); } if(result == false) { Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() ); Sleep(3000); } } } else { Print(j, " Positions are still open cause ",AccountProfit()," was smaller then ",(AccountBalance()*percent)); } Sleep(1000); } //---- return(0); } //+------------------------------------------------------------------+