Exit Sell Orders

How it works:

  • It selects the number of orders and then subtracts 1 from that number and assigns that number to (i) i.e. 7 orders become 6. then the loop will start from 6 and run 7 times 6,5,4,3,2,1,0 and stop.
  • As it starts it selects order 6. If it is not able to then it will jump to the else statement and print the reason why in the journal.
  • Next it checks to see if it is a sell order. If it is not it moves on and i– changes it to 5.
  • If it is a sell it checks the Magicnumber.If it’s incorrect it does i– and goes to 5.
  • If Magic is good it starts the While loop which is set to true which means it will never stop unless something inside it makes it break out of it’s cycle.
  • It tries to close the order with the parameters obtained from the order it just selected and stores the result, true or false in the result variable.
  • If it did notexitsells() close it’s gets the last error from the broker and prints it to the journal. Otherwise if it did close properly it simply sets err to zero and breaks out of the while loop, skipping the switch.
  • If the order did NOT close then one of the other cases might match. If it finds a match it will do everything on every line after that until it hits a (break). So any will run until they hit the break on the case:146 line. It will wait 1000 milliseconds then refresh the rates and then bump (i) up and break out of switch and while loop.
  • For instance, If order 4 does not close it will get bumped up to 5 here and then when it jumps out of the switch and the while loop and gets to the end of this for loop iteration, the 5 will get changed back to 4 and the order 4 will run again. Hopefully closing this time with the rates refreshed.
  • When the loop completes 7 runs. 6,5,4,3,2,1,0 and comes back for a run at -1 it will stop and all orders will be closed.


2 thoughts on “exitsells()

  1. JimDandy 1958 Post author

    Hey you’re welcome Dan. I’ve had a lot of people taking the Course over at http://www.jimdandymql4courses.com tell me that they are really glad that they took the course to fill in their gaps of knowledge with what I left out in the youtube videos. One guy told me today that if he had seen on of my course videos a week ago it would have saved him about 3 days of hunting for his mistake.

    I have levels 1,2,and 3 done now and am working on level4 which is focused specifically on the writing of Ea’s and all of the options available to us.. You may want to go over and sign up for level 1 for 19.58 and see if you think it will add anything to what you know. If so you can upgrade to levels 2 and 3. If you subscribe to multiple Levels at once you can start on any level. Or work your way through 2 levels at once but the best way is to start at the beginning and let me build on that foundation. I hope you are able to use what you learn to make your life better. After all, that’s all that matters. It’s not about money, it’s about being happy in life. PipPip..Jimdandy.

  2. Dan

    Thank You Jim for the code, I have watched all of your videos on youtube and enjoyed them greatly,
    I learned a lot. I may put it to use some day. This was the only way I would learn as your are the only MQL4 lesson that I know of and they are very informative.

    Dan Doherty

Leave a Reply