Forex
Google
New signals service!

Go Back   Forex Trading > Downloads > Expert Advisors - Metatrader 4


Register in Forex TSD!
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time).
Click here to register and get more information

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-12-2007, 12:37 PM
Senior Member
 
Join Date: Apr 2006
Posts: 121
InTrance is on a distinguished road
Closing all orders EA?

Hi,

I've been working on a system and I'm in need of an EA that will close all orders (active and pending) as soon as a profit target is hit (lets say 30 pips, or an $ value). I'll be running a set of EAs for my testing so this EA should close all orders regardless of magic number.

Anyone seen such an EA?

Thanks a lot.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-12-2007, 03:38 PM
Junior Member
 
Join Date: Sep 2006
Location: Indonesia
Posts: 8
jkancil is on a distinguished road
extern int profit=30; //profit USD
int mgc=1234;

double pft;
int total=OrdersTotal();
for(int cnt=0;cnt<total;cnt++) {
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderMagicNumber()==mgc) pft=pft+OrderProfit();
}
if(pft>profit) {
for(cnt=0;cnt<total;cnt++) {
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderMagicNumber()==mgc) {
if(OrderType()==OP_BUY) OrderClose(OrderTicket(),OrderLots(),Bid,3,White); else
if(OrderType()==OP_SELL) OrderClose(OrderTicket(),OrderLots(),Ask,3,White); else
OrderDelete(OrderTicket());
}
}
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-12-2007, 04:59 PM
Senior Member
 
Join Date: Nov 2005
Posts: 169
mangman is on a distinguished road
This EA seems to work fine for me in closing all orders regardless of the magic number, active and pending, when the profit level is reached.
The default profit value is $30. You can set it to any $ value you wish externally.
Attached Files
File Type: mq4 CloseAll-PL.mq4 (4.2 KB, 296 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-12-2007, 08:28 PM
Senior Member
 
Join Date: Jun 2006
Posts: 743
yeoeleven is on a distinguished road
Closing EA

The EAs in this thread work well too

Close Open Trades EAs based on Equity

John
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 03-13-2007, 12:34 AM
Senior Member
 
Join Date: Apr 2006
Posts: 121
InTrance is on a distinguished road
Thanks a million guys!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 03-18-2007, 10:58 PM
Member
 
Join Date: Aug 2006
Posts: 30
gorinw9 is on a distinguished road
equity %

is it possible to add % of equity in addition to $ or pip values?..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 08-08-2007, 02:56 PM
Member
 
Join Date: Jul 2007
Location: Frisco, Tx
Posts: 69
cochran1 is on a distinguished road
EA to close a trade when 2 MAs cross

A very kind programmer(thanks Shinigami) created an EA for me that will close a trade when 2 MAs cross. The EA is listed below. The MAs can be custom set, see parameter definitions at the following link.

iMA - MQL4 Documentation

-----------------------------------------
#property copyright "Shinigami© 2007"
#property link "Shini1984@gmail.com"
#define ORDER_ID 2016
extern int MA1.period =0;
extern int MA1.shift=0;
extern int MA1.method=0;
extern int MA1.price=0;
extern int MA2.period=0;
extern int MA2.shift=0;
extern int MA2.method=0;
extern int MA2.price=0;


int start()
{
if(CheckMACross()==1)
CloseOrders();
return(0);
}


int CheckMACross()
{
if(iMA(Symbol(),0,MA1.period,MA1.shift,MA1.method, MA1.price,2)<iMA(Symbol(),0,MA2.period, MA2.shift,MA2.method,MA2.price,2))
{
if(iMA(Symbol(),0,MA1.period,MA1.shift,MA1.method, MA1.price,1)>=iMA(Symbol(),0,MA2.period,MA2.shift, MA2.method,MA2.price,1))
return(1);
}
else if(iMA(Symbol(),0,MA1.period ,MA1.shift,MA1.method,MA1.price,2)>iMA(Symbol(),0, MA2.period,MA2.shift,MA2.method,MA2.price,2))
{
if(iMA(Symbol(),0,MA1.period,MA1.shift,MA1.method, MA1.price,1)<=iMA(Symbol(),0,MA2.period,MA2.shift, MA2.method, MA2.price,1))
return(1);
}
else return(0);
}


int CloseOrders()
{
for(int i=0;i<OrdersTotal();i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
//if(OrderMagicNumber()!=MagicNumber)
//continue;
if(OrderSymbol()!=Symbol())
continue;
if(OrderType()==OP_BUY)
OrderClose(OrderTicket(),OrderLots(),Bid,3);
if(OrderType()==OP_SELL)
OrderClose(OrderTicket(),OrderLots(),Ask,3);
}
return(0);
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 08-14-2007, 05:35 AM
Junior Member
 
Join Date: Aug 2007
Posts: 17
fxgroup is on a distinguished road
Hi,
Quite interesting but how could this EA define that it need to CLOSE for OPEN BUY or to CLOSE OPEN SELL POSITION . What I means is this EA should CLOSE OPEN BUY or OPEN SELL POSITION ?

Thank you.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 08-14-2007, 05:40 AM
Junior Member
 
Join Date: Aug 2007
Posts: 17
fxgroup is on a distinguished road
Hi,
Quite interesting but how could this EA Code define which one it should CLOSE.
OPEN BUY POSITION or OPEN SELL POSITION.

Thank you.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 08-14-2007, 08:50 PM
Member
 
Join Date: Jul 2007
Location: Frisco, Tx
Posts: 69
cochran1 is on a distinguished road
Not Sure, I requested this EA but I do not code myself. I have been using this and it seems to work ok. This just closes a trade when the EAs cross. thx
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
modify orders and close pending orders bkgridley Questions 8 05-23-2007 09:49 PM
Closing Pending Orders bkgridley Expert Advisors - Metatrader 4 1 05-11-2007 05:47 AM
Closing positions before new day jorgeng Metatrader 4 5 04-11-2007 07:40 AM
EA Help Needed - Closing Existing Orders SuzanneFX Metatrader 4 1 12-26-2006 02:28 PM
EA - closing all positions at once. ra300z Metatrader 4 6 09-08-2006 01:45 AM


All times are GMT. The time now is 09:34 AM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.