wait4signal / sharing-is-caring

MetaTrader 5 trade copier
GNU General Public License v3.0
23 stars 12 forks source link

EA esporadically crashes with "array out of range" error #7

Open gabrielmocan opened 12 months ago

gabrielmocan commented 12 months ago

Hello @bgabela , first, thanks for such amazing project. I'm running 1 master and 1 slave to test out the stability of this copier, and I've putted both on healthchecks.io

Eventually I keep receiving notifications from the slave saying that it is down, when checking the logs I can see the following message:

array out of range in 'Sharing-Is-Caring.mq5' (482,17)

This happens in any scenario, with trades, without trades... Doesn't seems to have a trigger that's reproducible.

Still, it happens frequently here.

image
gabrielmocan commented 12 months ago

P.S: master does not crash, only slave.

bgabela commented 11 months ago

Hello @bgabela , first, thanks for such amazing project. I'm running 1 master and 1 slave to test out the stability of this copier, and I've putted both on healthchecks.io

Eventually I keep receiving notifications from the slave saying that it is down, when checking the logs I can see the following message:

array out of range in 'Sharing-Is-Caring.mq5' (482,17)

This happens in any scenario, with trades, without trades... Doesn't seems to have a trigger that's reproducible.

Still, it happens frequently here.

image

Unfortunately I am unable to reproduce this behaviour, have not had it happen for me. Looking at the line where it crashes, I suspect it's not receiving expected values from producer. Please share the *-positions.csv file next time it happens so I can check it. Keep monitoring and add more detail here once you have more insight.

cshawky commented 11 months ago

Hi My two bobs to assist: This might happen if the file being read has an extra row or the recordCount is wrong. Line 461: while(!FileIsEnding(positionsFileHandle)) This line does not check to ensure i < prRecordCount and thus when the extra line is read, the following line has array out of range: Line 482: prRecords[i] = prData; Line 461 is better written as: while(!FileIsEnding(positionsFileHandle) && i < prRecordCount) The above change should remove the out of range error but not fix the underlying issue. Now why the extra line in the file I cannot answer as yet and that in itself should be an error. I am yet to run this EA for the first time. I am currently checking compilation and reviewing the code for correct syntax. As bgabela mentioned, a copy of the receiving file will assist. Also count the number of positions in the provider session at the same time...and lastly monitor the contents of the trade comment for each of the trades being copied. It is possible this may be impacting the csv file format creating an extra line.

Thanks

bgabela commented 11 months ago

Thank you @cshawky for the thorough analysis. You are right, the extra check should help avoid the crash when file has more lines than expected records. I will add it for next update.