Before the new script starts to run, there are 13 closed orders already. All the 13 orders have absolutely different magic numbers from the one of the new script.
However, in the script I wrongly initialize histroyPOS=0. I found a bug after the new script opened an order and closed it soon in my live account. So it's 14 closed orders later on my live account.
You can see the script will cycle for 14 times. But the problem is that the script accumulates the profit of the 14th order for 14 times. That is accountProfit=14*(OrderProfit() of 14th order).
If there's no bug, you know it should be accountProfit=(OrderProfit() of 14th order) since the magic number of the 14th order is different from all previous 13 orders.
Even there's no bug in OrderMagicNumber(), it should be accountProfit=(OrderProfit() of all 14 closed orders). So it seems OrderSelect() also has problem as it only selected 14th order although 'i' was increasing.
Therefore, finally I'm confused if the bug is in OrderMagicNumber() or in OrderSlect()?
for(i=histroyPOS; i<OrdersHistoryTotal(); i++)
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true && OrderMagicNumber()==MAGIC)
Can you reproduce this behavior ? If you run just the snippet of code you posted, do you get the same issue ?
My guess is : the bug is in your code.
To add comments, please log in or register