inputbool RunOnCurrentCurrencyPair = true; //Here You Don't Much Need It
inputbool CloseOnlyManualTrades = true; //Here You Don't Much Need It
inputbool DeletePendingOrders = true; //Here You Don't Much Need It
inputint MaxSlippage = 5; //This Is Important
//+------------------------------------------------------------------+//| Expert initialization function //No Problem Code Here |//+------------------------------------------------------------------+intOnInit()
{
//--- ObjectCreate(0,"CloseAll_btn",OBJ_BUTTON,0,0,0);
ObjectSetInteger(0,"CloseAll_btn",OBJPROP_XDISTANCE,450);
ObjectSetInteger(0,"CloseAll_btn",OBJPROP_YDISTANCE,5);
ObjectSetInteger(0,"CloseAll_btn",OBJPROP_XSIZE,100);
ObjectSetInteger(0,"CloseAll_btn",OBJPROP_YSIZE,50);
ObjectSetString(0,"CloseAll_btn",OBJPROP_TEXT,"Close All");
ObjectSetInteger(0,"CloseAll_btn",OBJPROP_COLOR, White);
ObjectSetInteger(0,"CloseAll_btn",OBJPROP_BGCOLOR, Red);
ObjectSetInteger(0,"CloseAll_btn",OBJPROP_BORDER_COLOR,Red);
ObjectSetInteger(0,"CloseAll_btn",OBJPROP_BORDER_TYPE,BORDER_FLAT);
ObjectSetInteger(0,"CloseAll_btn",OBJPROP_BACK,false);
ObjectSetInteger(0,"CloseAll_btn",OBJPROP_HIDDEN,true);
ObjectSetInteger(0,"CloseAll_btn",OBJPROP_STATE,false);
ObjectSetInteger(0,"CloseAll_btn",OBJPROP_FONTSIZE,12);
//---return;
}
//+------------------------------------------------------------------+//| Expert deinitialization function //You Must Put It |//+------------------------------------------------------------------+voidOnDeinit(constint reason)
{
//---ObjectDelete(0,"CloseAll_btn"); //This is important
}
//+------------------------------------------------------------------+//| Expert tick function //Nothing Here |
//+------------------------------------------------------------------+voidOnTick()
{
//---
}
//+------------------------------------------------------------------+//| ChartEvent function //This a lot problem come it |//+------------------------------------------------------------------+voidOnChartEvent(constint id, //Nothing problem here
constlong &lparam, //Nothing problem here
constdouble &dparam, //Nothing problem here
conststring &sparam) //Nothing problem here
{
//---if(sparam== "CloseAll_btn") //This you must check it to make it available for click not just have button on chart and cannot use it
{
if(RunOnCurrentCurrencyPair == true && CloseOnlyManualTrades == true) CloseAll(DeletePendingOrders,MaxSlippage); //This the problem so much, you must add the code to connect with the void for code check it
ObjectSetInteger(0,"CloseAll_btn",OBJPROP_STATE,false); //This Not Important delete or just put it because at OnInit Already Have It
}
//---
}
//This Is The Junk Code You Need To Check All Of It To Make It Available To Close It At Any EA or Indicator or Anything you trade of itvoid CloseAll (bool boolPendingOrders, int intMaxSlippage) //Here Check
{
int ticket; // This OK
if (OrdersTotal() == 0) return; // This OK
for (int i = OrdersTotal() - 1; i >= 0; i--) //This OK
{
if (OrderSelect (i, SELECT_BY_POS, MODE_TRADES) == true) //Also OK
{
if (OrderType() == OP_BUY) //OK
{
ticket = OrderClose (OrderTicket(), OrderLots(), MarketInfo (OrderSymbol(), MODE_BID), 3, CLR_NONE);//Check This Where You Must Put It
if (ticket == -1) Print ("Error: ", GetLastError());//OK
if (ticket > 0) Print ("Position ", OrderTicket() ," closed");//OK
}
if (OrderType() == OP_SELL)//OK
{
ticket = OrderClose (OrderTicket(), OrderLots(), MarketInfo (OrderSymbol(), MODE_ASK), 3, CLR_NONE);//Check This Where You Must Put IT
if (ticket == -1) Print ("Error: ", GetLastError());
if (ticket > 0) Print ("Position ", OrderTicket() ," closed");
}
if (OrderType() == OP_BUYLIMIT)//Check This What Type Of Order You Use It
{
ticket = OrderDelete (OrderTicket(), CLR_NONE); //Same Check This
if (ticket == -1) Print ("Error: ", GetLastError());//OK
if (ticket > 0) Print ("Position ", OrderTicket() ," closed");//OK
}
if (OrderType() == OP_SELLLIMIT)//Check This What Type Of Order You Use It
{
ticket = OrderDelete (OrderTicket(), CLR_NONE); //Same Check This
if (ticket == -1) Print ("Error: ", GetLastError());//OK
if (ticket > 0) Print ("Position ", OrderTicket() ," closed");//OK
}
}
}
return; //If You Want put it on your ea or indicators this you must check it carefully
}
To who read in this forum I already found the answer but I can't give the full code because I want build my Ultimate EA but you can check the code I will give it //and you check it and learn so am I.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
To who read in this forum I already found the answer but I can't give the full code because I want build my Ultimate EA but you can check the code I will give it //and you check it and learn so am I.