Hello everybody, actually I am using this EA to close at a profit level and deleting all Pending Orders placed left on Terminal.
It works perfectly but I would like to add this functions:
1) Delete Pending Orders True/False options,to activate or de-activate
and a
2)"Value of Total Orders" filter to Close at profit:
Condition: if total orders open are >= “value”
-----------------------> close (and delete)
if total orders open are < “value”
-----------------------> don't do anything
for Total Orders I mean: if only OP_SELL or only OP_BUY or (OP_SELL +
OP_BUY) are >= of “Value” still proceed to close ( and delete if activated) otherwise if < of
“Value” don't do anything.
ex. : 1 lot OP_BUY + 0.8 lot
OP_SELL + 2.5 lot OP_BUY = 3 orders --------> enable to close (and delete)
This is the code actually I am using.
externdouble My_Money_Profit_Target=100; //The amount of money profit at which you want to close ALL open trades.externstring Profit_Target= "Enter above To Close all OPEN trades when amount of profit is Reached in Account and not per OPEN trade! ";
int Slippage=5;
int i;
//+------------------------------------------------------------------+//| expert initialization function |//+------------------------------------------------------------------+int init()
{
//----//----return(0);
}
//+------------------------------------------------------------------+//| expert deinitialization function |//+------------------------------------------------------------------+int deinit()
{
//----//----return(0);
}
//+------------------------------------------------------------------+//| expert start function |//+------------------------------------------------------------------+int start()
{
if (AccountProfit()>= My_Money_Profit_Target)
{
for(i=OrdersTotal()-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
int type = OrderType();
bool result = false;
switch(type)
{
//Close opened long positionscaseOP_BUY : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),Slippage,Blue);
break;
//Close opened short positionscaseOP_SELL : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),Slippage,Red);
break;
//Close pending orderscaseOP_BUYLIMIT :
caseOP_BUYSTOP :
caseOP_SELLLIMIT :
caseOP_SELLSTOP : result = OrderDelete( OrderTicket() );
}
if(result == false)
{
Sleep(0);
}
}
Print ("Account Profit Reached. All Open Trades Have Been Closed");
return(0);
}
Comment("Balance: ",AccountBalance(),", Account Equity: ",AccountEquity(),", Account Profit: ",AccountProfit(),
"\nMy Account Profit Target: ",My_Money_Profit_Target);
return(0);
}
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.
Hello everybody, actually I am using this EA to close at a profit level and deleting all Pending Orders placed left on Terminal.
It works perfectly but I would like to add this functions:
1) Delete Pending Orders True/False options,to activate or de-activate
and a
2)"Value of Total Orders" filter to Close at profit:
ex. : 1 lot OP_BUY + 0.8 lot OP_SELL + 2.5 lot OP_BUY = 3 orders --------> enable to close (and delete)
This is the code actually I am using.
Many many thanks for you precious time.
Greetings, Lorenzo