| New signals service! | |
|
|||||||
| 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 |
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
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. |
|
|||
|
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()); } } } |
|
|||
|
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. |
|
|||
|
Closing EA
|
|
|||
|
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); } |
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
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 |