Hey everyone,
Just wanted to see if someone could answer some questions I have about the code and respective backtest.
First, the idea of my strategy is a "breakout". It needs a lot of fine tuning, but I was just trying to get the framework in there. Here's what I envisioned and tried to implement. Please tell me if there's something missing or done incorrectly.
I have UWTI in there now as the ETF being traded. Every minute, from 3 minutes into trading day until 6 hours into trading day, it checks if the price and volume have increased by a set value compared to the past few minutes. If so, it will use all of the portfolio funds to purchase UWTI shares. Then, it will also check each minute to see if an order is open. If one is and the price is either > 0.1% or < 0.5% of the purchase price, sell all shares. I didn't want to hold overnight, so the last thing was to sell with 10 minutes left in the day no matter what the current returns.
So I coded that as best I know how and tried to back test. This is where a lot of my questions come in or stem from. One, why isn't it selling at the end of the first day? That function must not be operating properly. Two, why does it buy a small percentage of new shares each time it sells the bulk of shares? Three, I can understand that it may sell at larger than 0.1% gain or 0.5% loss because it's on a discrete minute timeframe. But on some backtests (maybe not this one), it was selling like 3-4% gains or losses. It happened a few times and seems unlikely that a stock jumps that much in a minute.
EDIT: Realized in that code that I have sell if < 1.005 * purchase price. Changed to < 0.995 * purchase price and got the exact same transactions on the backtest.