• Home
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • User/Email: Password:
  • 7:49am
Menu
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 7:49am
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

Closing all trades coding 3 replies

Code for closing all trades at new candle? 2 replies

Closing all trades? 15 replies

closing of trades 4 replies

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe
  • 5
Attachments: Closing all trades when....
Exit Attachments

Closing all trades when....

  • Post #1
  • Quote
  • First Post: Nov 21, 2007 12:30pm Nov 21, 2007 12:30pm
  •  jr2007
  • | Joined Sep 2007 | Status: Member | 269 Posts
my account goes into -10%.

I am currently testing a system, and found it to be very profitable. The exit strategy, is getting out when the combined opened trades equal 10% of my account balance. I have been able to do this by setting up an alarm on the metatrader, and checking my acct. It would be great if it can be done automatically. If anyone knows how to program this for the Metatrader4, please respond.
  • Post #2
  • Quote
  • Edited at 9:49pm Nov 21, 2007 3:01pm | Edited at 9:49pm
  •  smjones
  • Joined Mar 2006 | Status: THANK YOU MERLIN,TWEE and FF Team | 4,603 Posts
I modified a EA to do this. If you are running an EA already, just put this on a fresh chart in the same account. I use GBPJPY, because it gets the most pip action. The pair is really not important, because it just uses the tick change to activate like all EAs.
Attached Files
File Type: mq4 CloseTrades_After_Account_Win_Percent.mq4   4 KB | 366 downloads
File Type: mq4 CloseTrades_After_Account_Loss_Prcnt2much.mq4   4 KB | 334 downloads
 
 
  • Post #3
  • Quote
  • Nov 21, 2007 6:24pm Nov 21, 2007 6:24pm
  •  jr2007
  • | Joined Sep 2007 | Status: Member | 269 Posts
Quoting smjones
Disliked
I modified a EA to do this. If you are running an EA already, just put this on a fresh chart in the same account. I use GBPJPY, because it gets the most pip action. The pair is really not important, because it just uses the tick change to activate like all EAs.
Ignored
I posted what I have for the moment. I am currently still testing it. I have some changes in mind, but, it will help to have the EA.

CLICK HERE:

Message #49

http://www.forexfactory.com/showthre...t=51115&page=4
 
 
  • Post #4
  • Quote
  • Nov 21, 2007 8:47pm Nov 21, 2007 8:47pm
  •  athalon7
  • | Joined Oct 2006 | Status: I Hedge | 206 Posts
I had this programmed and use to sell it. I sold more than a few. The best way to use it is set "Use Equity Percentage" to false and program your settings. Read the directions.
Attached Files
File Type: doc Amazing Equity Protector EA Instructions.doc   20 KB | 633 downloads
File Type: mq4 Amazing Equity Protector EA!.mq4   6 KB | 381 downloads
"Its not where your at, but where your coming from"
 
 
  • Post #5
  • Quote
  • Nov 21, 2007 9:50pm Nov 21, 2007 9:50pm
  •  smjones
  • Joined Mar 2006 | Status: THANK YOU MERLIN,TWEE and FF Team | 4,603 Posts
I also posted a percent lost EA
 
 
  • Post #6
  • Quote
  • Nov 23, 2007 4:34pm Nov 23, 2007 4:34pm
  •  jr2007
  • | Joined Sep 2007 | Status: Member | 269 Posts
Hey everyone who has posted EA on this thread........thank you very much. I only have a few questions. When using the EA, does the EA only work on the present open orders? Or, will it work on pending orders that will come into play? Also, do I need to have my computer running after the EA has been entered? Any help will greatly be appreciated.
 
 
  • Post #7
  • Quote
  • Nov 23, 2007 8:20pm Nov 23, 2007 8:20pm
  •  smjones
  • Joined Mar 2006 | Status: THANK YOU MERLIN,TWEE and FF Team | 4,603 Posts
Quoting jr2007
Disliked
Hey everyone who has posted EA on this thread........thank you very much. I only have a few questions. When using the EA, does the EA only work on the present open orders? Or, will it work on pending orders that will come into play? Also, do I need to have my computer running after the EA has been entered? Any help will greatly be appreciated.
Ignored
The 2 I posted work on both the open and pending orders. As with all EAs, the computer must be running with MT4 running and connected to the broker for the EA to be active.
 
 
  • Post #8
  • Quote
  • Nov 23, 2007 8:51pm Nov 23, 2007 8:51pm
  •  jr2007
  • | Joined Sep 2007 | Status: Member | 269 Posts
Quoting smjones
Disliked
The 2 I posted work on both the open and pending orders. As with all EAs, the computer must be running with MT4 running and connected to the broker for the EA to be active.
Ignored
Thank you
 
 
  • Post #9
  • Quote
  • Nov 29, 2007 1:18pm Nov 29, 2007 1:18pm
  •  jr2007
  • | Joined Sep 2007 | Status: Member | 269 Posts
Quoting smjones
Disliked
I modified a EA to do this. If you are running an EA already, just put this on a fresh chart in the same account. I use GBPJPY, because it gets the most pip action. The pair is really not important, because it just uses the tick change to activate like all EAs.
Ignored

I have been testing this EA "CloseTrades_After_Account_Loss_Prcnt2much" , with no success. I am able to activate it on to the chart, and it even gives me the "My Acct. cutoff limit:-$xxx.xx. When it reaches the cutoff limit, no action is taken. What am I doing wrong. It is in the experts/scripts folder. I drag/drop it into the chart. I am using two pairs EURUSD/USDCHF. 15min chart. I have attch the options. Any help would greatly be appreciated. Thank you
Attached Image
File Type: bmp options.bmp   605 KB | 220 downloads
 
 
  • Post #10
  • Quote
  • Nov 29, 2007 1:23pm Nov 29, 2007 1:23pm
  •  smjones
  • Joined Mar 2006 | Status: THANK YOU MERLIN,TWEE and FF Team | 4,603 Posts
Quoting jr2007
Disliked
I have been testing this EA "CloseTrades_After_Account_Loss_Prcnt2much" , with no success. I am able to activate it on to the chart, and it even gives me the "My Acct. cutoff limit:-$xxx.xx. When it reaches the cutoff limit, no action is taken. What am I doing wrong. It is in the experts/scripts folder. I drag/drop it into the chart. I am using two pairs EURUSD/USDCHF. 15min chart. I have attch the options. Any help would greatly be appreciated. Thank you
Ignored
It is not a script. It is an EA. It goes in the Expert folder, not the Expert/script folder. If you already have an EA running, put this EA on a new chart by itself and it will manage closing all trades when the percent is hit. As I said above in the first post, I run it on GBPJPY, because GJ has more ticks and as with any EA, they are activated by each tcik.
 
 
  • Post #11
  • Quote
  • Nov 29, 2007 1:26pm Nov 29, 2007 1:26pm
  •  jr2007
  • | Joined Sep 2007 | Status: Member | 269 Posts
Quoting athalon7
Disliked
I had this programmed and use to sell it. I sold more than a few. The best way to use it is set "Use Equity Percentage" to false and program your settings. Read the directions.
Ignored
I have been able to get other EA s on the charts, but this one will not budge. I have followed instructions to the tee. What am I doing wrong?
 
 
  • Post #12
  • Quote
  • Nov 29, 2007 1:29pm Nov 29, 2007 1:29pm
  •  jr2007
  • | Joined Sep 2007 | Status: Member | 269 Posts
Quoting smjones
Disliked
It is not a script. It is an EA. It goes in the Expert folder, not the Expert/script folder. If you already have an EA running, put this EA on a new chart by itself and it will manage closing all trades when the percent is hit. As I said above in the first post, I run it on GBPJPY, because GJ has more ticks and as with any EA, they are activated by each tcik.
Ignored

Oh, maybe thats what it is, I'll change it to the Expert folder, thank you.
 
 
  • Post #13
  • Quote
  • Nov 29, 2007 1:45pm Nov 29, 2007 1:45pm
  •  jr2007
  • | Joined Sep 2007 | Status: Member | 269 Posts
SMJONES - Thank you very much. It worked. I had it in the wrong folder.
 
 
  • Post #14
  • Quote
  • Last Post: Oct 18, 2012 1:16pm Oct 18, 2012 1:16pm
  •  getting
  • | Joined Jun 2009 | Status: Member | 265 Posts
Inserted Code
//+------------------------------------------------------------------+
//|                      CloseTrades_After_Account_Loss_TooMuch.mq4  |
//|                                     Copyright © 2007, Tradinator |
//|                                          [email protected] |
//+------------------------------------------------------------------+

#property copyright "Copyright © 2007, Tradinator"
#property link      "[email protected]"
                                           
                                           
extern double     Percent_Win= 1;                                              //+---------------------------------------------------------------------+
//extern double Open_Loss_To_CloseTrades=-1000;  //|The amount of money at which you want to take a loss & close ALL     |
                                               //|open trades. eg if the floating loss in your account reaches or goes |
                                               //|beyond -$1000 then ALL the open positions in your account will be    |
                                               //|closed.                                                              |      
                                               //+---------------------------------------------------------------------+
extern double     Percent_Loss = 1;                                              //+---------------------------------------------------------------------+
//extern double Open_Loss_To_CloseTrades=-1000;  //|The amount of money at which you want to take a loss & close ALL     |
                                               //|open trades. eg if the floating loss in your account reaches or goes |
                                               //|beyond -$1000 then ALL the open positions in your account will be    |
                                               //|closed.                                                              |      
                                               //+---------------------------------------------------------------------+                                               
int Slippage=5;                                 
int i;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+

int start()
{
double My_Percent_Profit1 = Percent_Win / 100;
double My_Money_Profit_Target1 = AccountBalance() * My_Percent_Profit1;

if (AccountProfit()>= My_Money_Profit_Target1)
   {
    for(i=OrdersTotal()-1;i>=0;i--)
       {
       OrderSelect(i, SELECT_BY_POS);
       int type1   = OrderType();
               
       bool result1 = false;
              
       switch(type1)
          {
          //Close opened long positions
          case OP_BUY  : result1 = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),Slippage,Pink);
                         break;
               
          //Close opened short positions
          case OP_SELL : result1 = 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  : result1 = OrderDelete( OrderTicket() );                 
          }
          
       if(result1 == false)
          {
            Sleep(3000);
          }  
       }
      Print ("Account Cutoff Limit Reached. All Open Trades Have Been Closed");
      return(0);
   }  
   
   Comment("Balance: ",AccountBalance(),", Account Equity: ",AccountEquity(),", Account Profit: ",AccountProfit(),
           "nMy Account Profit Limit: ",My_Money_Profit_Target1);


double My_Percent_Profit2 = -1 * Percent_Loss / 100;
double My_Money_Profit_Target2 = AccountBalance() * My_Percent_Profit2;

if (AccountProfit()<= My_Money_Profit_Target2)
   {
    for(i=OrdersTotal()-1;i>=0;i--)
       {
       OrderSelect(i, SELECT_BY_POS);
       int type2   = OrderType();
               
       bool result2 = false;
              
       switch(type2)
          {
          //Close opened long positions
          case OP_BUY  : result2 = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),Slippage,Pink);
                         break;
               
          //Close opened short positions
          case OP_SELL : result2 = 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  : result2 = OrderDelete( OrderTicket() );                 
          }
          
       if(result2 == false)
          {
            Sleep(3000);
          }  
       }
      Print ("nnAccount Cutoff Limit Reached. All Open Trades Have Been Closed");
      return(0);
   }  
   
   Comment("nnnBalance: ",AccountBalance(),", Account Equity: ",AccountEquity(),", Account Profit: ",AccountProfit(),
           "nMy Account Cutoff Limit: ",My_Money_Profit_Target2);  
  return(0);
}
 
 
  • Platform Tech
  • /
  • Closing all trades when....
  • 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 / ©2022