You are missing trading opportunities:
- Free trading apps
- 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
Part of the problem is the way you wrote that code with big long if conditions full off &&, ||, and function call after function call makes it difficult to debug, you would be lucky to find anyone with the time to unravel that mess. You should look at the coding examples in the docs to see how code should be formatted in much shorter lines and commented.
" Makes it difficult to debug "?? :( Never heard of these though , is this real ....
Compiler also have hard time to debug my code :( ?
If that's the reason means I had to rethink all my coding idea for this part ?? Then it will turn up a totally different thing ...... :( :(
Yes it is hard to debug for example look at this code for trailing stop. It is easy to see what each line does therefore easy to spot mistakes.
I posted that code just as an example of easy to read code, it was not meant to be an example of a completed stand alone function.
It is the buy orders section of the trailing stop code from the MetaQuotes MACD sample EA included with MT4.
1) Not true, you can count up or down, the loop is more efficient, OrdersTotal() is called once and assigned to a local var.
Thank you SDC . Thanks for the tips too WHRoeder . It's useful .
I tried swaping OrderClosePrice() to the MarketInfo one on the previous code and the edited ( removing the && condition and put them as a if statement as after , the one in the 2nd for loop ) , but the result is still sometimes working sometimes not working .
The for loop for counting to total orders in the pool I uses count down loop but with x-- . I don't understand why you suggest --x though .
I googled "short circuit operators" but don't really understand what it means at mql4 , do you mind to explain a bit ^_^ ?? Why is it bad to chain 'if' ?
By the way , the above code that SDC suggested , that's not the code I'm using >.< .
It is not bad to chain ifs. The developers of the MQL4 language wrote the code I posted above. It is some code I cut from their macd sample EA as an example.
WHR was referring to a recent change to the way && || conditions are evaluated which now makes them equally as efficient as chained if conditions. Previously they were less efficient. You can use either method. Chained ifs are useful when there are divergences in the code so you can use 'else'.
Long lines of if( && || ) conditions can create parentheses confusion which makes finding errors more difficult, that is why I don't like doing it. Also there is an accepted standard for coding that says it should not be more than 80 characters wide. A lot of coders dont bother to adhere to that standard though, and the MQL4 developers keep creating enumerated identifiers with big long names to be used in their function calls to functions with equally big long names, which doesn't help with code formatting a whole lot.