|
|||||||
| 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 |
|
|||
|
/////////////////////////////////////////////////////////////////////////////////////////////
// Trailing stop losses void TrailOrders(int trailing_stop, int magic_number) { //Iterate orders int num_orders = OrdersTotal(); for(int trade = 0; trade < num_orders; trade++) { //Select an order if (!OrderSelect(trade,SELECT_BY_POS,MODE_TRADES)) { continue; } if (OrderMagicNumber() != magic_number) { continue; } if (OrderType()==OP_BUY) { if (Bid-OrderOpenPrice() > Point*trailing_stop) { if (OrderStopLoss() < Bid-Point*trailing_stop) { if (!OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*trailing_stop,OrderTakeProfit(),0,Green)) { Print("TrailOrders, OrderModify failed. Err#:", ErrorDescription(GetLastError())); } } } } if (OrderType()==OP_SELL) { if (OrderOpenPrice()-Ask > Point*trailing_stop) { if (OrderStopLoss() > Ask+Point*trailing_stop) { if (!OrderModify(OrderTicket(),OrderOpenPrice(),Ask+P oint*trailing_stop,OrderTakeProfit(),0,Red)) { Print("TrailOrders, OrderModify failed. Err#:", ErrorDescription(GetLastError())); } } } } } } |
|
||||
|
just use e-trailing
the default of 8 is when trail is moved to break even(no matter what the initial s/l is set) the default of 2 is how many pips it trails after being moved to break even change those 2 settings to your liking. I use this EA on every trade I make. Usually I trail to b/e at 25/30 pips and trail every 5 pips there after. you can set initial s/l at 100 and target of 200. or what ever you want, the broker never knows what point your ea will trail at. |
|
|||
|
Hi ...
I use this code in the most of my EA's to protect profit is the account profit reach a specific $ but not pips. The code is not recomended to add to EA's which are attached to plateform with other EA's because it has no MAGIC No. You can add MAGIC No. easily if you like. extern int MaxProfitPerPair = 7; //in Dollars ... ... ... if(AccountProfit()>= MaxProfitPerPair * OrdersTotal()) CloseAllPositions(); ... ... ... void CloseAllPositions(){ int total = OrdersTotal(); for(int i=total-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), 5, Red ); break; //Close opened short positions case OP_SELL : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red ); } if(result == false) { Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() ); Sleep(3000); } } return(0); } |
![]() |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to protect itself from the broker? | BrunoFX | Non Related Discussions | 18 | 05-01-2008 06:23 PM |
| Profit to Protect Function | woogitt_lover | Tools and utilities | 1 | 03-01-2007 12:59 PM |
| how to protect an EA | mike_cole | Tools and utilities | 2 | 11-10-2006 07:45 PM |
| I need to protect my EA | zidan66 | Metatrader 4 | 7 | 09-11-2006 10:11 PM |
| profit Vs Profit factor | cardio | Metatrader 4 | 4 | 02-10-2006 06:24 PM |