The strategy code is written so that it can enter a trade ONLY iff it is not in a trade. The code to evaluate the condition(s) to exit a position is executed before the code to evaluate a possible enter of a position. The strategy may exit a position in one direction AND enter a position in the opposite direction on the same bar.
The case in point (attached picture) shows an output window trace-- trace order plus my own annotations and a section of the execution log for the transaction. In the highlighted section of the output window the code evaluates and exits a previously established long position. This is recorded, as expected, in the execution log - the first entry at 10:47:53. Subsequently, the strategy enters a short position - as recorded by the THIRD 10:47:53 entry. What is UNEXPECTED in the second entry in the execution log - the "Close Position 2" entry.
Apparently there is a problem with the way I have coded this... but I have exhausted all ideas. Please Help!

Comment