Download MetaTrader 5
To add comments, please log in or register
Create interesting Forum topics concerning the automated trading!
JC 2015.03.17 23:51  
jjc upon testing the code it works for opening trades but it doesn't close them when the MAs cross over again. I'm sorry to take more of your time but do you think you could have a look at the code to see if the problem can be deduced.

I can't immediately see a problem in the code around order closure. I have also tried running the code above - after zeroing out the problematic Stoploss values in the OrderSend() - in the MT4 strategy tester, and it closes both buy and sell positions.

I haven't inspected the code thoroughly to see whether it's closing positions when intended, but if it isn't closing them at all then I'd look for logic errors introduced for any further modifications you have made. For example, the code as exactly posted above doesn't compile because there is a missing }. If you have edited it incautiously, then you might have done something such as making the entire trading logic part of the block controlled by if(OrdersTotal()<MAX_ORDERS), which would mean that nothing at all further happens once three simultaneous positions have been opened.

If that's not the explanation then the key question is whether the OrderClose() is failing, and your Print() statements are generating messages in the log, or whether nothing is getting logged and therefore the OrderClose() isn't getting called at all.

BartWinter 2015.03.19 16:54  
Thanks a lot for you help. I will have a look to see what I can do.
/ /12
To add comments, please log in or register