Silly question, but did you press F3 in the terminal and check global variables before, during and after you run your EA?
Is it possible that another copy of the EA, running in another window, sets GV values?
Also, global variables are not destroyed after your EA exits. As it is stated in a documentation: "Global variables exist in the client terminal during 4 weeks since their last use, then they are automatically deleted."
If all above checks, than listen what Alain told you and debug your code.
Why the bitterness? I don't think you are understanding the question first of all. And no there are no other EAs running. Each gv is assigned a name based on the OrderTicket() so doesnt matter if other GVs exist as each will have a different name for different trades. Problem is the GV gets set immediately a trade opens even before the conditions are met. It does this from the first time I started testing both on strategy tester and on live test.
Does the same even with manual trades. Previous GVs dont matter because they are named and checked using the OrderTicket() function so only the value of the GV with the name that matches the open order's ticket number is fetched. Anyway, will do more tests tomorrow right now i need to clear my head besides its sunday. :-/
Been thinking about this problem and have also tested the code on my MT4 (build 1170). I can't reproduce the bug. However, thinking about it, you're looping over all open orders and then comparing the OrderOpenPrice to the Low of the previous bar (I.e. Low) - should you perhaps be checking against the previous bar based on the order open time? You can do this using IBarShift(NULL,0,OrderOpenTime()) to get the bar that that order was opened on and then simply deduct 1 to get the previous bar...
Or have I missed the point of your function?