Forex



Go Back   Forex Trading > Discussion Areas > Metatrader 4
Forex Forum Register More recent Calendar Advertising Others Help






Register
Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.

From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.

Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
  • Elite Section
    Get access to private discussions, specialized support, indicators and trading systems reported every week.
  • Advanced Elite Section
    For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
See more

 
 
Thread Tools
 
Old 10-29-2007, 01:14 AM
Member
 
Join Date: Dec 2005
Location: Shanghai
Posts: 41
doragio is on a distinguished road
Take Profit EA Currency Specific

Hi guys,

Was working on modifying this current EA without much luck and was hoping someone can help with this. Basically all the take profit ea's seem to work on a global scale where all your positions hit a certain profit level. How do you adjust it so that it only calculates the profits of a specific pair, like the USDJPY. And then closes the JPY trades once the profit level is at a certain point but leaves the other pairs alone.

Here's the close profita EA code, just not sure which strings to alter to make it currency specific. This would be great in a hedging type of trading where you want to close off the profit of certain pairs and not th whole basket.

Much thanks,

#property copyright "Copyright ?2006, Robert Hill."

extern int ProfitTarget = 10; // Profit target in dollars

int start()
{
double TotalProfit = 0.0;

int total, i;
bool result = false;

// Calculate total profit on all trades

total = OrdersTotal();
for(i=total-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
TotalProfit += OrderProfit();
}

if (TotalProfit >= ProfitTarget)
{

// First close losing trades

total = OrdersTotal();

for(i=total-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);

result = false;

switch(OrderType())
{
//Close opened long positions
case OP_BUY : if ( OrderProfit() < 0) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
break;

//Close opened short positions
case OP_SELL : if ( OrderProfit() < 0) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );

}

if(result == false)
{
Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );
Sleep(3000);
}
}

// Now close remaining trades

total = OrdersTotal();

for(i=total-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);

result = false;

switch(OrderType())
{
//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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
 
Old 10-29-2007, 06:46 AM
wolfe's Avatar
Senior Member
 
Join Date: Jan 2006
Posts: 820
wolfe is on a distinguished road
Keep track of each specific currency pair by magic number. When orderprofit() of a specific magic number is hit, close all orders with that magic number. (assign each currency pair you are trading a specific magic number)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
 
Old 10-29-2007, 07:55 AM
Member
 
Join Date: Dec 2005
Location: Shanghai
Posts: 41
doragio is on a distinguished road
wolfe,

Thanks for your reply. If I'm manually opening these positions, how do I assign each pair a specific magic number, the only caption I see is where you can assign a comment . thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
 
Old 10-29-2007, 07:59 AM
dxtrade's Avatar
Senior Member
 
Join Date: Jul 2007
Location: Maldives
Posts: 194
dxtrade is on a distinguished road
Here is a script ( experts/scripts ) which lets you manually open trades with a magic number assigned.

Hope that helps.
Attached Files
File Type: mq4 OpenMagic.mq4 (2.2 KB, 78 views)
__________________
Happy Trading...

"Failure is only a temporary change in direction to set you straight for your next success."
"Winning is a habit. Unfortunately, so is losing."
"It’s so simple to be wise. Just think of something stupid to say and then don’t say it."

"Say what you mean, but don't say it mean!"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
 

Bookmarks

Tags
take profit EA, profit ea, ea currency
Thread Tools

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
Help: How to write simple EA to buy and sell at a specific time? jack2 Expert Advisors - Metatrader 4 119 11-01-2009 01:02 AM
Specific EA spiritbreezer Expert Advisors - Metatrader 4 1 10-04-2007 09:59 AM
get high price in specific times pooshkin Questions 7 10-12-2006 06:03 PM
how to let the EA close all opening order of a specific symbol? phoenix Expert Advisors - Metatrader 4 4 05-30-2006 06:08 AM
Script that waits for a specific price? nog General Discussion 2 04-12-2006 01:37 AM


All times are GMT. The time now is 10:08 PM.



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