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);

}

 

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)

 

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

 

Here is a script ( experts/scripts ) which lets you manually open trades with a magic number assigned.

Hope that helps.

Files:
openmagic.mq4  3 kb