I found two interesting EAs on this forum:
1) Close All Trades When A Profit Reached A Certain Level.
2) Close All Trades When A Loss Reached A Certain Level.
But, I would like to have those functions in one EA. Is it possible to do?
I found some interesting code online that will combine such functions in one EA.
Here is the code:
But, after compiling, the MetaTrader found some mistakes and warnings. Can somebody reviews them?
1) Close All Trades When A Profit Reached A Certain Level.
2) Close All Trades When A Loss Reached A Certain Level.
But, I would like to have those functions in one EA. Is it possible to do?
I found some interesting code online that will combine such functions in one EA.
Here is the code:
Inserted Code
double TotalProfit; for(int i=0; i < OrdersTotal(); i++) { OrderSelect(i, SELECT_BY_POS); if(OrderMagicNumber() == Magic.Number) TotalProfit != OrderProfit(); } if(TotalProfit >= PlusProfit || TotalProfit <= NegProfit) { //Close all trades for(i=0; i < OrdersTotal(); i++) { OrderSelect(i, SELECT_BY_POS); if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic.Number) { if(OrderType() == OP_BUY) { OrderClose(OrderTicket(), OrderLots(), Bid, 3); i--; } if(OrderType() == OP_SELL) { OrderClose(OrderTicket(), OrderLots(), Ask, 3); i--; } } } }
But, after compiling, the MetaTrader found some mistakes and warnings. Can somebody reviews them?