| / | Forum |
|
brian851218
2008.04.03 05:39
Dear experts, I find a problem on my simple EA, which is when i want to close all positions in my account, the positions were not able to be closed at first price change. For example, if I have 10 positions, once I turn on my EA, the price changed from 1.9864 to 1.9865(1st run cycle),, only 5positions were closed. Then when price changed from 1.9865 to 1.9866(2nd run cycle), there were 3 positions closed. Finally, when the price changed from 1.9866 to 1.9865(3rd run cycle), the last two position were closed. Therefore, my 10 positions have not been closed at the same time. After detailed debug, I knew that, in the first run, the for loop only was executed 4 loops although OrdersTotal()=10 here. And in the second cycle, there were only 3 loops were executed, although OrdersTotal()=5. in the last cycle, full loops were executed, which was 2 loops. However, according to the MQL4 tutorial, the start function should be executed line by line and only when MetaTrader find the return keyword it will be ready to call start() function again with the most new quotation. That mean, the EA should close my all positions within one cycle, although, the close price may change because of the latest bid and ask price. the following is my code, please spend a little time to read. and find out the reason of the stupid error of my EA. Many thanks in advance! int start() OrderSelect(i,SELECT_BY_POS,MODE_TRADES); |
|
Universal Expert Advisor Template The article will help newbies in trading to create flexibly adjustable Expert Advisors. |
|
brian851218
2008.04.03 06:20
Also I found the error code is 4051. Any helps? Thanks! |
|
Liliput
2008.04.03 12:28
Check your syntaxis again.... |
|
brian851218
2008.04.03 14:44
And also the error 129. But the price setting should be correct. Could you help me to find out?
|