OrderProfit + Loss & CloseAllTrades doesn't work
- Your posted code does nothing, as total is initialized to zero and not updated. Always post the real code.
- Why are you incrementing dProfit, when it's the sum of orders' profits.
- What is the meaning of $Balance Change + number of losses (dProfit + dLoss)
- You've exited the OrderSelect loop, you can't call OrderClose with those parameters.
- Why do you always close an order?
if(dProfit+dLoss>=Profit) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red ); result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
- Check your return codes
What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
WHRoeder:
Wow, lots of mistakes/problems. Thank you very much for your help. I will work on these issues.
- Your posted code does nothing, as total is initialized to zero and not updated. Always post the real code.
- Why are you incrementing dProfit, when it's the sum of orders' profits.
- What is the meaning of $Balance Change + number of losses (dProfit + dLoss)
- You've exited the OrderSelect loop, you can't call OrderClose with those parameters.
- Why do you always close an order?
- Check your return codes What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
Hi Everyone I've been stuck on something for over a week. No matter what I try, I cannot get this to work. I want my EA to simply add the profit and loss of two open trades together, and if the combined profit and loss exceeds a certain profit margin, it must close both trades. But it always closes both trades in a loss. It is as if it closes the first trade in a loss as soon as the other trade goes in profit, but then fails to close the profitable trade until it goes into a loss. It always prints dLoss=0. So it is obviously not calculating the losses properly. Is this because OrderProfit() does not take losses into account? What is the opposite function for OrderProfit()? The best code I have so far is this one. Will someone please look and see if you notice any problems. Thank you very much.