The issue is that the STOP order at line 35 is placed the next candle, not immediately on entry, because the ONMARKET status is updated at the closing of the entry candle.
To help us continually offer you the best experience on ProRealCode, we use cookies. By clicking on "Continue" you are agreeing to our use of them. You can also check our "privacy policy" page for more information.Continue