• Home
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 12:03pm
Menu
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 12:03pm
Sister Sites
  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Print Thread

Similar Threads

EA closing all trades and orders when profit reached? 5 replies

Disable EA's when profit target reached? 9 replies

Looking for EA that shows total profit if TP is reached 2 replies

Prevent trades once a certain profit level is reached 2 replies

EA how to close when combined profit is reached 2 replies

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe
Tags: CloseTrades After Account Profit Reached
Cancel

CloseTrades After Account Profit Reached

  • Post #1
  • Quote
  • First Post: Aug 6, 2010 12:59pm Aug 6, 2010 12:59pm
  •  Toothman
  • | Joined Aug 2006 | Status: Member | 1,242 Posts
Was wondering if someone would give me a little help tweaking this EA. As is, it closes all open trades and pending orders when open trades equal a set $ amount. What I'd like it to do is close all trades and orders when open trades plus any losing trades that have closed since the last TP, equal a certain $ amount. I would be using this EA with a second EA on another chart that would be taking small stop losses.

Example: You set EA to close everything at $10 profit
Trade A- closes with a $5 loss earlier in the day
Trade B- closes with a $5 loss a little later in the day
Trades C and D reach $20 profit, minus Trades A and B = $10 and EA closes at this point.
EA at this point after TP would then again start counting closed trades (losses) plus positive floating trades and TP at specific $ amount again.
Here's the code. Could you do me a favor and put the changes in bold print. thanks much/+------------------------------------------------------------------+
//| CloseTrades_After_Account_Profit_Reached.mq4 |
//| Copyright 2007, Tradinator |
//| [email protected] |
//+------------------------------------------------------------------+

#property copyright "Copyright 2007, Tradinator"
#property link "[email protected]"



extern double My_Money_Profit_Target=300; //The amount of money profit at which you want to close ALL open trades.

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 positions
case OP_BUY : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),Slippage,Pink);
break;

//Close opened short positions
case OP_SELL : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),Slippage,Pink);
break;
//Close pending orders
case OP_BUYLIMIT :
case OP_BUYSTOP :
case OP_SELLLIMIT :
case OP_SELLSTOP : result = OrderDelete( OrderTicket() );
}

if(result == false)
{
Sleep(3000);
}
}
Print ("Account Profit Reached. All Open & Pending 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);
  • Post #2
  • Quote
  • Aug 7, 2010 5:22am Aug 7, 2010 5:22am
  •  oromek
  • | Joined May 2009 | Status: Member | 116 Posts
hi

post AccountProfit() function, because i think this part of code must be altered to work according to your rules.

regards
oromek
 
 
  • Post #3
  • Quote
  • Last Post: Jun 7, 2019 9:50am Jun 7, 2019 9:50am
  •  D-TickTrader
  • | Joined Dec 2009 | Status: Member | 28 Posts
Hello Friends
Does any where has an EA for MT5 to Close all trades at profit reached.
 
 
  • Platform Tech
  • /
  • CloseTrades After Account Profit Reached
  • Reply to Thread
0 traders viewing now
Top of Page
  • Facebook
  • Twitter
About FF
  • Mission
  • Products
  • User Guide
  • Media Kit
  • Blog
  • Contact
FF Products
  • Forums
  • Trades
  • Calendar
  • News
  • Market
  • Brokers
  • Trade Explorer
FF Website
  • Homepage
  • Search
  • Members
  • Report a Bug
Follow FF
  • Facebook
  • Twitter

FF Sister Sites:

  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Forex Factory® is a brand of Fair Economy, Inc.

Terms of Service / ©2023