Strange EA's problem or maybe Broker woes?

 
Hello folks,

I am having an issue with my EA. I have tried to research some answers, but alas, nothing really matches
my circumstance.

My EA creates an order with BOTH Take Profit and a Stop Loss. So, the only way i can see my order being closed
is only through those 2 paths. Is this a correct statement? 

My issue is that without my EA actually issueing a Close, the MetaTrader platform under this Broker (IC Markets)
will close my order. Strange! (fyi, this is still a Demo account i am running EA on)

Since, MT4 doesn't really provide a OnClose() function, i can't exactly trap it or maybe add some
debugging to let me know the reason.

Below are the messages i recieve.


Here is my Original order
2021.02.24 18:00:02.714 '20054188': order was opened : #1471721 buy 0.03 USOIL at 63.366 sl: 60.762 tp: 65.102
2021.02.24 18:00:02.417 '20054188': order buy market 0.03 USOIL sl: 60.762 tp: 65.102

at 5pm, MT4 automatically decided decided to close my existing trade. (I thought originally it must be a weekend type of thing, but 
this also happens sometimes would close my orders during week days.) 8 times it tried to close this repeatably.
2021.02.28 17:00:07.682 '20054188': close order #1471721 buy 0.03 USOIL at 63.366 sl: 60.762 tp: 65.102 at price 0.000
2021.02.28 17:00:07.682 '20054188': close order #1471721 buy 0.03 USOIL at 63.366 sl: 60.762 tp: 65.102 at price 0.000
2021.02.28 17:00:07.682 '20054188': close order #1471721 buy 0.03 USOIL at 63.366 sl: 60.762 tp: 65.102 at price 0.000
2021.02.28 17:00:07.682 '20054188': close order #1471721 buy 0.03 USOIL at 63.366 sl: 60.762 tp: 65.102 at price 0.000
2021.02.28 17:00:07.682 '20054188': close order #1471721 buy 0.03 USOIL at 63.366 sl: 60.762 tp: 65.102 at price 0.000
2021.02.28 17:00:07.682 '20054188': close order #1471721 buy 0.03 USOIL at 63.366 sl: 60.762 tp: 65.102 at price 0.000
2021.02.28 17:00:07.588 '20054188': close order #1471721 buy 0.03 USOIL at 63.366 sl: 60.762 tp: 65.102 at price 0.000
2021.02.28 17:00:07.588 '20054188': close order #1471721 buy 0.03 USOIL at 63.366 sl: 60.762 tp: 65.102 at price 0.000

Why close this trade? Why is price at 0.000?
The answers seem to indicate that there is no current price from this Broker at the moment.

Then these messsages occured:
2021.02.28 17:00:07.698 '20054188': order #1471721 buy 0.03 USOIL closing at 0.000 failed [Trade context is busy]
2021.02.28 17:00:07.682 '20054188': order #1471721 buy 0.03 USOIL closing at 0.000 failed [Trade context is busy]
2021.02.28 17:00:07.682 '20054188': order #1471721 buy 0.03 USOIL closing at 0.000 failed [Trade context is busy]

Here is another 8 messages, I suspected these are the remainants of the failed closing prior:
2021.02.28 17:00:08.620 '20054188': order #1471721 buy 0.03 USOIL closing at 0.000 failed [Market is closed]
2021.02.28 17:00:08.604 '20054188': order #1471721 buy 0.03 USOIL closing at 0.000 failed [Market is closed]
2021.02.28 17:00:08.588 '20054188': order #1471721 buy 0.03 USOIL closing at 0.000 failed [Market is closed]
2021.02.28 17:00:08.588 '20054188': order #1471721 buy 0.03 USOIL closing at 0.000 failed [Market is closed]
2021.02.28 17:00:08.573 '20054188': order #1471721 buy 0.03 USOIL closing at 0.000 failed [Market is closed]
2021.02.28 17:00:08.573 '20054188': order #1471721 buy 0.03 USOIL closing at 0.000 failed [Market is closed]
2021.02.28 17:00:08.573 '20054188': order #1471721 buy 0.03 USOIL closing at 0.000 failed [Market is closed]
2021.02.28 17:00:08.573 '20054188': order #1471721 buy 0.03 USOIL closing at 0.000 failed [Market is closed]

Then after a while I see:
2021.02.28 18:00:02.812 '20054188': order #1471721 buy 0.03 USOIL closing at 0.000 failed [Off quotes]
2021.02.28 18:00:02.812 '20054188': order #1471721 buy 0.03 USOIL closing at 0.000 failed [Off quotes]
2021.02.28 18:00:02.812 '20054188': order #1471721 buy 0.03 USOIL closing at 0.000 failed [Off quotes]

Does any one have any clues or suggestions as to what is going on? Is there a way i can troubleshoot this??

Since order was running, it can't be slippage related....


Thanks.

 

As a follow up on this problem, the automatic closing of my positions always happens over the weekend. I have seen it happen during

the weekday's also, but that is much more rare.

For example, on Sunday 5pm EST time, if a trade is open and still running from previous Friday, MT4 will close it on me.

 

Is your EA running on the oil chart or a different chart?

Do you have another EA running? That may be trying to close all trades.

 

Hello Keith,

Yes, the EA is running on a oil chart.

Yes, the same EA is running on different charts (diff magic#). 

As mentioned, my EA does not close these trades, it's done by MT4.

I depend on TP or SL to close the trade.

Thanks.

 
jazzthedog:

Hello Keith,

Yes, the EA is running on a oil chart.

Yes, the same EA is running on different charts (diff magic#). 

As mentioned, my EA does not close these trades, it's done by MT4.

I depend on TP or SL to close the trade.

Thanks.

I am quite sure (but not certain) that the error reports are created by an EA trying to close the trades. I don't see why you would get a trade context busy report when MT4 is trying to close the order.

Look in the Experts folder.

Look in the order comment for one of the closed trades, does it include [sl] or [tp]?

 

Yup, it appears that my code from an 'earlier' version was running in which in i did close orders was running... :(

What made a worse was i wasn't just killing for the current magic#, but ALL orders :(

I added more debugging and will test again over the weekend.

Thanks for you help!

Reason: