@forexsake
Your logic is not checking whether there is already an open position or not, and will, therefore, trade on every bar that has opened at a different price form the previous bar.
Since you also don't specify any timeframe, it will trade several times a day. if you want daily gaps, you have to tell it to the algorithm. 🙂