I think that your code doesn't work the way that you expect because you are assuming that, if the order exists, the first order selected will have the WatchDogBuy" or WatchDogSell" comment.
If that is not the case, then WatchDogLotsSell will be added to, until the commented trade is selected
Maybe change
if ((OrderComment() == "WatchDogBuy") || (OrderComment() == "WatchDogSell")) break;
to
if ((OrderComment() == "WatchDogBuy") || (OrderComment() == "WatchDogSell")) { WatchDogLotsSell = 0; break; }
Also, although I have never seen this happen, there is a risk that the broker may change part of the comment, so can make it risky when you use OrderComment to identify a trade.
Why not use a different magic number instead?
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi,
Im writing a function for an EA that upon change of trend it will sum all the opened trades and open an order in the opposit direction with a new magic number. This order will only close when the trend changes again. For some reason it is opening multiple orders with the right amount of lots(the sum). What am i doing wrong?
Here is the function: