I've been trying to implement a DCA strategy into my LEAPs. The way the algo works is combining the ROC in and out strategy by buying leaps, and DCA into them when we are at the bear market. 

When backtesting, it seems to work pretty well, except for a couple of contracts;

  1. SPY 220121C00315000
  2. SPY 201218C00285000

 

So what happened is that those two contracts are supposed to be liquidated as they met the condition to liquidate near expiry. 

But instead of selling them off, it buys them - I cant seem to get a fix this. Hoping someone with expertise could help out. Please find the attached backtest.