Forex
Google

Go Back   Forex Trading > Downloads > Expert Advisors - Metatrader 4
Forex Forum Register FAQ Members List Calendar Today's Posts


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 11-26-2006, 02:43 AM
Kurka Fund's Avatar
Kurka Fund Kurka Fund is offline
Senior Member
 
Join Date: Sep 2006
Location: San Diego
Posts: 139
Kurka Fund is on a distinguished road
Protect Profit

Can anyone here code this ....

I would like to protect profits after a certian number of pips is reached

So once "x" number of pips is reached it starts a trailing stop.

None of my attempts have been successfull.

Also is there anyway to fake a takeprofit and stoploss if your broker only alows it to be more than 10?

I was thinking about putting some rules to the OrderClose ()....

Thanks,
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 11-26-2006, 04:30 AM
Craig Craig is offline
Senior Member
 
Join Date: Feb 2006
Location: New Zealand
Posts: 249
Craig is on a distinguished road
/////////////////////////////////////////////////////////////////////////////////////////////
// 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()));
}
}
}
}
}
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 11-26-2006, 04:31 AM
Craig Craig is offline
Senior Member
 
Join Date: Feb 2006
Location: New Zealand
Posts: 249
Craig is on a distinguished road
The ErrorDescription function is in the stderror.mqh header.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 11-26-2006, 04:40 AM
xxDavidxSxx's Avatar
xxDavidxSxx xxDavidxSxx is offline
Senior Member
 
Join Date: Jul 2006
Posts: 745
xxDavidxSxx is on a distinguished road
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.
Attached Files
File Type: mq4 e-Trailing.mq4 (3.0 KB, 55 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 12-05-2006, 03:07 PM
oshaban oshaban is offline
Junior Member
 
Join Date: Nov 2005
Posts: 19
oshaban is on a distinguished road
Lightbulb

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);
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



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

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


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


All times are GMT. The time now is 12:14 AM.