Simple Expert Advisor from Book question
I think you are correct, well spotted.
AmitSharma:
I think you're right.I believe the if statement should be Total > 1, each market order would increment total by 1, so, if total was greater than 1 then there would be several market orders, also, total is initialized at 0 before the for loop, and then incremented right before the if statement, so total < 1 would never execute anyways. But I am completely new to all this, so I could just be blinded by silly-stupidness.
The for-condition "for(int i=1; i>=OrdersTotal(); i++)" also looks wrong. It's only going to execute properly if there's only one order (though it will try and fail to execute if there are no orders). That's presumably why the bug you've identified wasn't picked up; the code was never actually tested with multiple orders.
jjc:
I think you're right.
The for-condition "for(int i=1; i>=OrdersTotal(); i++)" also looks wrong. It's only going to execute if there's only one order. That's presumably why the bug you've identified wasn't picked up; the code was never actually tested with multiple orders.
Oh yeah, that greater than sign should also be switched: for(int i = 1; i <= OrdersTotal(); i++). Hmm, you'd think this sort of thing would be error-free by now, the book has a lot of good information for a beginner like myself, I would assume a lot of other beginners have gone through it. At least the forum is good :D.I think you're right.
The for-condition "for(int i=1; i>=OrdersTotal(); i++)" also looks wrong. It's only going to execute if there's only one order. That's presumably why the bug you've identified wasn't picked up; the code was never actually tested with multiple orders.
At least by finding this error, questioning it and getting an answer you have learned even better. Well done. :-)

You are missing trading opportunities:
- Free trading apps
- Free Forex VPS for 24 hours
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi,
I am new to MQL and looking through the book and I was looking at the code in the example for a simple expert advisor (https://book.mql4.com/samples/expert) in the 4th block
}
I believe the if statement should be Total > 1, each market order would increment total by 1, so, if total was greater than 1 then there would be several market orders, also, total is initialized at 0 before the for loop, and then incremented right before the if statement, so total < 1 would never execute anyways. But I am completely new to all this, so I could just be blinded by silly-stupidness.
Thanks for your time,
Amit Sharma