• Home
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • User/Email: Password:
  • 3:33pm
Menu
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 3:33pm
Sister Sites
  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Print Thread

Similar Threads

Is there an EA to close trades after a certain amount of time? 27 replies

EA or script close all trades at certain equity level 6 replies

Close all orders at a certain time ea 2 replies

Create a verticle line at certain hour for every certain hour 16 replies

Close all orders with magic number at certain profit 8 replies

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe
  • 2
Attachments: Close trades at a certain percent positive
Exit Attachments
Tags: Close trades at a certain percent positive
Cancel

Close trades at a certain percent positive

  • Post #1
  • Quote
  • First Post: Nov 28, 2006 4:41pm Nov 28, 2006 4:41pm
  •  jenglish
  • | Joined Sep 2006 | Status: Member | 25 Posts
Hello,
Is it possible to create an EA that will close all trades and pending orders when the profit is up a certain percent, like 3%?
I trade inverse currency pairs and have been closing the trades manually but if there is a way to close them automatically that would be so much better.

If there is a way but you don't have time would you please post the variable that could be used?

Let's say I have an account balance of $1000. I would like all trades and pending orders to close or be deleted when the profit reachs 3% profit or $300.
Thanks.
  • Post #2
  • Quote
  • Nov 28, 2006 5:41pm Nov 28, 2006 5:41pm
  •  andersenws
  • | Joined Apr 2006 | Status: Member | 440 Posts
Sure, there's some built in ways to do this.

Our AccountBalance() is equal to all realized gains/losses.
Our AccountEquity() is eqaul to that plus all unrealized gains/losses.

So, if our account starts at 10000 and we open a 1 standard lot trade (10/pip), our account balance will remain at 10000 until we close that trade, at which point our gain/loss for that trade will be added to our balance.

Our account equity on the other hand, will fluctuate and represent all of our unrealized gains/losses.

So your code would be:
Inserted Code
if (AccountEquity()/AccountBalance()>=1.03)

Then, the close all positions is a bit more of code. I have it, but I can't remember where it is. I will be sure to post it later.

andersenws
"Youth is the trustee of prosperity." - Benjamin Disraeli
 
 
  • Post #3
  • Quote
  • Nov 28, 2006 5:43pm Nov 28, 2006 5:43pm
  •  jenglish
  • | Joined Sep 2006 | Status: Member | 25 Posts
Thank you very much! I'll look forward to that other code
 
 
  • Post #4
  • Quote
  • Nov 28, 2006 5:58pm Nov 28, 2006 5:58pm
  •  andersenws
  • | Joined Apr 2006 | Status: Member | 440 Posts
I believe this is the rest of the code.

First you need to define some variables at the beginningof your start()
Inserted Code
int total, cnt;
total=OrdersTotal();
Then put this inside of the code I just gave you.
Inserted Code
   for(cnt = 0; cnt < total; cnt++)
 {
   OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
   if(OrderType() <= OP_SELL &&   // check for opened position 
  OrderSymbol() == Symbol())  // check for symbol
 {
   if(OrderType() == OP_BUY)   // long position is opened
 {
  
  OrderClose(OrderTicket(), OrderLots(), Bid, 3, Violet); // close position
  return(0); // exit
}
  // check for stop
  
 }
   else // go to short position
 {
   
   OrderClose(OrderTicket(), OrderLots(), Ask, 3, Violet); // close position
   return(0); // exit
 }
   
 }

Hope that helps,
andersenws
"Youth is the trustee of prosperity." - Benjamin Disraeli
 
 
  • Post #5
  • Quote
  • Nov 28, 2006 5:59pm Nov 28, 2006 5:59pm
  •  andersenws
  • | Joined Apr 2006 | Status: Member | 440 Posts
Also, in the first code, you could replace 1.03 with anything you want (1.05 1.10), or you could even optimize it if you wanted to.

andersenws
"Youth is the trustee of prosperity." - Benjamin Disraeli
 
 
  • Post #6
  • Quote
  • Nov 28, 2006 6:13pm Nov 28, 2006 6:13pm
  •  jenglish
  • | Joined Sep 2006 | Status: Member | 25 Posts
Inserted Code
int total, cnt;
total=OrdersTotal();
I get a warning 'total' - expression on global scope not allowed. I put it just as it is above. Do I need to do anything else?
 
 
  • Post #7
  • Quote
  • Nov 28, 2006 6:26pm Nov 28, 2006 6:26pm
  •  jenglish
  • | Joined Sep 2006 | Status: Member | 25 Posts
I moved total=OrdersTotal(); down under the start and it isn't giving me any warnings so I will start testing this out to see if I put it together right. Thank you for the quick replies
 
 
  • Post #8
  • Quote
  • Nov 28, 2006 6:34pm Nov 28, 2006 6:34pm
  •  andersenws
  • | Joined Apr 2006 | Status: Member | 440 Posts
Sure, glad I could be of help.

andersenws
"Youth is the trustee of prosperity." - Benjamin Disraeli
 
 
  • Post #9
  • Quote
  • Nov 29, 2006 10:20pm Nov 29, 2006 10:20pm
  •  mie
  • | Joined Nov 2006 | Status: Member | 26 Posts
Quoting jenglish
Disliked
Hello,
Is it possible to create an EA that will close all trades and pending orders when the profit is up a certain percent, like 3%?
I trade inverse currency pairs and have been closing the trades manually but if there is a way to close them automatically that would be so much better.

If there is a way but you don't have time would you please post the variable that could be used?

Let's say I have an account balance of $1000. I would like all trades and pending orders to close or be deleted when the profit reachs 3% profit or $300.
Thanks.
Ignored
Sorry guys, if you see that the 3% from $1000 is only $30 not the $300. My advise is, if you need the $300 thats mean 30%, so high risk. Just my 2 cent.
 
 
  • Post #10
  • Quote
  • Nov 29, 2006 10:24pm Nov 29, 2006 10:24pm
  •  andersenws
  • | Joined Apr 2006 | Status: Member | 440 Posts
I'm sure it was an honest mistake. He meant 3%.

andersenws
"Youth is the trustee of prosperity." - Benjamin Disraeli
 
 
  • Post #11
  • Quote
  • Nov 30, 2006 7:37am Nov 30, 2006 7:37am
  •  jenglish
  • | Joined Sep 2006 | Status: Member | 25 Posts
yes that was a mistake I meant 3% for $30.
I seem to be having trouble with it. It will close one pair when the account equity reaches 3%, but it will not close all trades. I have attached the EA to one chart and to all the charts, but it still only closed 1 pair. Any ideas?
 
 
  • Post #12
  • Quote
  • Nov 30, 2006 7:15pm Nov 30, 2006 7:15pm
  •  jenglish
  • | Joined Sep 2006 | Status: Member | 25 Posts
I got now. Thanks
 
 
  • Post #13
  • Quote
  • Last Post: Apr 3, 2009 7:45am Apr 3, 2009 7:45am
  •  zam_c61
  • | Joined Dec 2007 | Status: Member | 15 Posts
Quoting andersenws
Disliked
I believe this is the rest of the code.

First you need to define some variables at the beginningof your start()
Inserted Code
int total, cnt;
total=OrdersTotal();
Then put this inside of the code I just gave you.
[code]...
Ignored
hi sir.

can u adjust it to my ea? i don't know where to put it. this ea running 24h/5 and enter to market every 1 hour. tf using tf1h. pair use gu and ucad.

tq
Attached File(s)
File Type: mq4 Chamera3.mq4   10 KB | 310 downloads
File Type: ex4 Chamera3.ex4   14 KB | 278 downloads
 
 
  • Platform Tech
  • /
  • Close trades at a certain percent positive
  • 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