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(...);
}
}
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
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);
}
}
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);
}
}
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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