// ---------------------------------------------------------------------------------- +
//                          Mn Close above Profit level                               +
// ---------------------------------------------------------------------------------- +
#property copyright "Mn"
#property show_confirm
#property show_inputs

extern int  mSlippage =  3;
extern string mCAP = "**** USE ENTIRELY AT OWN RISK *****";
extern string mCAPx = "**** Profit level above which the order closes *****";
extern double mProfit   = 100.00;
extern string mCAPxx    = "** TAKE CARE SETTING THESE OPTIONS *****";
extern string mCAPxxx   = "** Set to 1 for all pairs : Set to 0 for CurrentChart Only *****";
extern int   mAllSymbol = 0;
extern string mCAPxxxx  = "** Set to 1 to close Longs in profit : 0 to ignore Longs *****";
extern int    mLong     = 1;
extern string mCAPxxxxx = "** Set to 1 to close Shorts in profit : 0 to ignore Shorts *****";
extern int    mShort    = 0;

// ---------------------------------------------------------------------------------- +
int start()
{
  int mTotal = OrdersTotal();
  for(int i = mTotal-1; i>=0; i--)
  {
    OrderSelect(i, SELECT_BY_POS);
    int mType   = OrderType();
    bool mResult = false;
    if(OrderSymbol() == Symbol() || mAllSymbol == 1)
      {
        if(OrderTakeProfit() >= mProfit)
          {
           switch(mType)
            {
             case OP_BUY  :
              {
               mResult = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
               break;
              } 
             case OP_SELL : 
               {
                mResult = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
                break;
               }
            default      : 
               break;
            }
    
           if(mResult == false)
            {
              Alert("Order " , OrderTicket() , " Failed to close. Error:" , GetLastError() );
              Sleep(2000);
            } 
          }  // if(OrderTakeProfit
       }   // if(OrderSymbol
  }        // for i
  return(0);
 }
// ---------------------------------------------------------------------------------- +

