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 not 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.