Automatic moving Stoploss in EA - page 2

 
Fernando Carreiro:
  1. For starters, your file does not compile because of undeclared identifiers.
  2. When closing orders, you must always count down, just as I have shown you in my previous post correcting your MoveSLTP function. So, get into the habit of ALWAYS counting down when iterating over the Order history.
  3. When the OrderClose fails, verify the reason (the error code) and act accordingly. Don't just try to close it 15 times without regard for the reason.
  4. Don't hard-code the slippage. Let it be an external variable definable by the user.
  5. Instead of using Ask or Bid to close the order, use the OrderClosePrice() instead which will automatically select the Bid or Ask depending on the Order Type (just as I have used in the example code posted before).
  6. Combine your Buy and Sell functions, into the same function, just as I did for you in the MoveSLTP function. This way you only have to maintain one function.
  7. Don't confuse your code by using the "if( !condition ) continue; else {...};" construct. Just use "if( condition ) {...}" instead as I have shown you in my previous example code.
  8. To make your code more maintainable, instead of creating 3 loops (for Winning, Loosing and All orders), rather just create one loop, and check the condition within the loop. This makes the code more compact and easier to maintain (and read) than repeating the whole closing process 3 times.

There are more points, but these should be enough to get you started. You may also notice that many of the points listed, have already be shown to you in my example code in the MoveSLTP function, so you should have taken notice of them and done the research.

On a special note, have a look at the MQL4 Updates so that you keep up with the modern style of MQL4 coding.

Also, I highly recommend that you build up your coding skills and basic coding experience by practicing with "C" coding. Here are a few links for sites that offer tutorials and learning for "C" that can help:

Thank you very much! There are a lot of things to do in my EA so I hope that I will success 
 

Fernando Carreiro

Thank you! 

 
Fstrifoerr8:

Fernando Carreiro

Thank you! 

My pleasure, but I am not really sure why you are thanking me?
 
Fernando Carreiro:
My pleasure, but I am not really sure why you are thanking me?
For help to this man.
 
Fstrifoerr8:
For help to this man.
Yeah and I would ask you to stop flooding the forum with useless posts. If you are bored go for a ride.