i need a close all trades (pending+ active) button

To add comments, please log in or register
Seyedmajid Masharian
1531
Seyedmajid Masharian  

hello

i need a close all trades (pending+ active) button indicator

that it can close all trades on all pairs when i install it on one of my charts.

can anyone help?

thanks

Marco vd Heijden
Moderator
7846
Marco vd Heijden  
Have you tried this ?
Seyedmajid Masharian
1531
Seyedmajid Masharian  
any other help?
Donald Gibson
456
Donald Gibson  
void Close_AllOrders()
  {
/*-----------------------------------------------------------------------------------------------*/
//Close Orders according to FIFO Rule
   for(i=0; i<OrdersTotal(); i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         if(OrderSymbol()==Symbol())
           {
            if(OrderType()==OP_BUY)
              {
               Close_Result=OrderClose(OrderTicket(),OrderLots(),Bid,0,clrNONE);
               if(Close_Result) i--;
              }
            if(OrderType()==OP_SELL)
              {
               Close_Result=OrderClose(OrderTicket(),OrderLots(),Ask,0,clrNONE);
               if(Close_Result) i--;
              }
            if(OrderType()==OP_SELLLIMIT ||
               OrderType()==OP_SELLSTOP ||
               OrderType()==OP_BUYLIMIT ||
               OrderType()==OP_BUYSTOP)
              {
               Close_Result=OrderDelete(OrderTicket(),clrNONE);
               if(Close_Result) i--;
              }
           }
     }
/*-----------------------------------------------------------------------------------------------*/
  }

Here is a function that I use to close all orders.

As far as using a button to run it from a chart, that's up to you to program

Mehmet Bastem
694
Mehmet Bastem  
Seyedmajid Masharian:

hello

i need a close all trades (pending+ active) button indicator

that it can close all trades on all pairs when i install it on one of my charts.

can anyone help?

thanks

//example expert close, buy sell

#property strict
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   ObjectCreate(0,"CloseButton",OBJ_BUTTON,0,0,0);
   ObjectSetInteger(0,"CloseButton",OBJPROP_XDISTANCE,25);
   ObjectSetInteger(0,"CloseButton",OBJPROP_YDISTANCE,25);
   ObjectSetInteger(0,"CloseButton",OBJPROP_XSIZE,100);
   ObjectSetInteger(0,"CloseButton",OBJPROP_YSIZE,50);

   ObjectSetString(0,"CloseButton",OBJPROP_TEXT,"CLOSE");

   ObjectSetInteger(0,"CloseButton",OBJPROP_COLOR,White);
   ObjectSetInteger(0,"CloseButton",OBJPROP_BGCOLOR,Red);
   ObjectSetInteger(0,"CloseButton",OBJPROP_BORDER_COLOR,Red);
   ObjectSetInteger(0,"CloseButton",OBJPROP_BORDER_TYPE,BORDER_FLAT);
   ObjectSetInteger(0,"CloseButton",OBJPROP_HIDDEN,true);
   ObjectSetInteger(0,"CloseButton",OBJPROP_STATE,false);
   ObjectSetInteger(0,"CloseButton",OBJPROP_FONTSIZE,10);

//---
/////////
   ObjectCreate(0,"CloseButton1",OBJ_BUTTON,0,0,0);
   ObjectSetInteger(0,"CloseButton1",OBJPROP_XDISTANCE,150);
   ObjectSetInteger(0,"CloseButton1",OBJPROP_YDISTANCE,25);
   ObjectSetInteger(0,"CloseButton1",OBJPROP_XSIZE,100);
   ObjectSetInteger(0,"CloseButton1",OBJPROP_YSIZE,50);

   ObjectSetString(0,"CloseButton1",OBJPROP_TEXT,"BUY");

   ObjectSetInteger(0,"CloseButton1",OBJPROP_COLOR,White);
   ObjectSetInteger(0,"CloseButton1",OBJPROP_BGCOLOR,Blue);
   ObjectSetInteger(0,"CloseButton1",OBJPROP_BORDER_COLOR,Blue);
   ObjectSetInteger(0,"CloseButton1",OBJPROP_BORDER_TYPE,BORDER_FLAT);
   ObjectSetInteger(0,"CloseButton1",OBJPROP_HIDDEN,true);
   ObjectSetInteger(0,"CloseButton1",OBJPROP_STATE,false);
   ObjectSetInteger(0,"CloseButton1",OBJPROP_FONTSIZE,10);
//
   ObjectCreate(0,"CloseButton2",OBJ_BUTTON,0,0,0);
   ObjectSetInteger(0,"CloseButton2",OBJPROP_XDISTANCE,275);
   ObjectSetInteger(0,"CloseButton2",OBJPROP_YDISTANCE,25);
   ObjectSetInteger(0,"CloseButton2",OBJPROP_XSIZE,100);
   ObjectSetInteger(0,"CloseButton2",OBJPROP_YSIZE,50);

   ObjectSetString(0,"CloseButton2",OBJPROP_TEXT,"SELL");

   ObjectSetInteger(0,"CloseButton2",OBJPROP_COLOR,White);
   ObjectSetInteger(0,"CloseButton2",OBJPROP_BGCOLOR,Blue);
   ObjectSetInteger(0,"CloseButton2",OBJPROP_BORDER_COLOR,Blue);
   ObjectSetInteger(0,"CloseButton2",OBJPROP_BORDER_TYPE,BORDER_FLAT);
   ObjectSetInteger(0,"CloseButton2",OBJPROP_HIDDEN,true);
   ObjectSetInteger(0,"CloseButton2",OBJPROP_STATE,false);
   ObjectSetInteger(0,"CloseButton2",OBJPROP_FONTSIZE,10);


   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---
//OrderSend(Symbol(),OP_BUY,1,Ask,3,0,0,"ada",123,0,CLR_NONE);
if(sparam=="CloseButton1") // Close button has been pressed
     {
     OrderSend(Symbol(),OP_BUY,1,Ask,3,0,0,"BUY",123,0,CLR_NONE);
     
      ObjectSetInteger(0,"CloseButton1",OBJPROP_STATE,false);
     }
    if(sparam=="CloseButton2") // Close button has been pressed
     {
     OrderSend(Symbol(),OP_SELL,1,Bid,3,0,0,"SELL",123,0,CLR_NONE);
     
      ObjectSetInteger(0,"CloseButton2",OBJPROP_STATE,false);
     }



   if(sparam=="CloseButton") // Close button has been pressed
     {
      for(int i=OrdersTotal()-1; i>=0; i--)
        {
         OrderSelect(i,SELECT_BY_POS);
         if(OrderType()==OP_BUY || OrderType()==OP_SELL)
            OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),5);
         else
            OrderDelete(OrderTicket());
        }
      ObjectSetInteger(0,"CloseButton",OBJPROP_STATE,false);
     }
  }
//+------------------------------------------------------------------+
Seyedmajid Masharian
1531
Seyedmajid Masharian  
Donald Gibson:

Here is a function that I use to close all orders.

As far as using a button to run it from a chart, that's up to you to program

is this an indicator or script?

can you send me mq4 file?

thanks

Seyedmajid Masharian
1531
Seyedmajid Masharian  
Mehmet Bastem:

is this an indicator or script?

can you send me mq4 file and how to use it?

thanks
Marco vd Heijden
Moderator
7846
Marco vd Heijden  

The demand for more has arrived.

You could also try here

Seyedmajid Masharian
1531
Seyedmajid Masharian  
Marco vd Heijden:

The demand for more has arrived.

You could also try here

but they reply my request .

such systems previously created by some programmers so i don't see any need to ask for that on freelance

Mehmet Bastem
694
Mehmet Bastem  
Seyedmajid Masharian:

but they reply my request .

such systems previously created by some programmers so i don't see any need to ask for that on freelance

experts

Files:
Seyedmajid Masharian
1531
Seyedmajid Masharian  
Mehmet Bastem:

experts

Thanks a lot i will try
123
To add comments, please log in or register