Close Specific Trade Positions

 
Hi,
How would you close all open positions on a specific pair when the sum loss had reached a certain level?

Without closing all other open positions on other pairs

Example

ProfitLoss = 500 //max loss of all positions of a specific pair

Sum all EURUSD positions
If sum of all EURUSD positions >= ProfitLoss
Close all EURUSD positions

Thanks in Advance
 
After reading this i am curious as to how to do this also. Although I am curious as how to close all trades of the same pair when profits exceed the loss's and/or to a specified degree. Maybe like closing all trades of the same pair when profits exceed loss's 2/1. This could work with the "Pendulum" EA which places limit orders in both directions. Although i havent put much thought into it, it seems with the Pendulum EA this type of EA in addition to it is a WIN/WIN situatuion. I will keep track of this thread.. Good luck.
 
fxhedger wrote >>
Hi,
How would you close all open positions on a specific pair when the sum loss had reached a certain level?

Without closing all other open positions on other pairs

Example

ProfitLoss = 500 //max loss of all positions of a specific pair

Sum all EURUSD positions
If sum of all EURUSD positions >= ProfitLoss
Close all EURUSD positions

Thanks in Advance

int total=OrdersTotal();

for (int i=0; i<total;i++)

{

OrderSelect(...)

if OtderSymbol()="EURUSD" profit+=OrdeProfit();

}

if (profit>500) CloseOrders("EURUSD");

void CloseOrders(string symbol)

{

int total=OrdersTotal();

for (int i=0; i<total;i++)

{

OrderSelect(...)

if OrderSymbol()=symbol CloseOrder(...);

}

}

 
ronaldosim:

int total=OrdersTotal();

for (int i=0; i<total;i++)

{

OrderSelect(...)

if OtderSymbol()="EURUSD" profit+=OrdeProfit();

}

if (profit>500) CloseOrders("EURUSD");

void CloseOrders(string symbol)

{

int total=OrdersTotal();

for (int i=0; i<total;i++)

{

OrderSelect(...)

if OrderSymbol()=symbol CloseOrder(...);

}

}

thanks ronaldosim, i tried it, but gives me so much errors in metaeditor, may i introduce, i'm not a coder, therefore i understand your code but i don't know the mql4 coding rules and commands. Please would you be so kind and write the complete structure down?


Thanks

 
fxhedger wrote >>

thanks ronaldosim, i tried it, but gives me so much errors in metaeditor, may i introduce, i'm not a coder, therefore i understand your code but i don't know the mql4 coding rules and commands. Please would you be so kind and write the complete structure down?

Thanks

start()

{

double profit=0;

int total=OrdersTotal();

for (int i=0; i<total;i++)

{

OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

if OtderSymbol()="EURUSD" profit+=OrderProfit();

}

if (profit>500) CloseOrders("EURUSD");

}

void CloseOrders(string symbol)

{

int total=OrdersTotal();

for (int i=0; i<total;i++)

{

OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

if OrderSymbol()=symbol OrderClose(OrderTicket(),OrderPrice(),Ask,3);

}

}

 
ronaldosim:

start()

{

double profit=0;

int total=OrdersTotal();

for (int i=0; i<total;i++)

{

OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

if OtderSymbol()="EURUSD" profit+=OrderProfit();

}

if (profit>500) CloseOrders("EURUSD");

}

void CloseOrders(string symbol)

{

int total=OrdersTotal();

for (int i=0; i<total;i++)

{

OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

if OrderSymbol()=symbol OrderClose(OrderTicket(),OrderPrice(),Ask,3);

}

}

that is also my question, I basically have the same code as above and it doenst work in a live test with multiple currencies...
Reason: