Rotation Trading With Min Holding Period & Gain/Loss Filter

I run several tax efficient strategies where i run explorations against watchlists to get my factors for each stock. i then manually keep track of the buys/sells in csv and read these in the backtest.

Is there a way in Rotational trading to do the following:
(The strategy trades once per year every december)

When ranking stocks of a watchlist....

  1. IF the %gain/loss on the position is < -5% THEN SELL (rotate out of it to get tax loss and purchase a different stock.

  2. IF %gain/Loss > 0 AND Rank drops out of Top N Rank AND BarsHeld < 275 THEN do not sell / rotate out (due to the S/T capital gain it would cause).

i have periodically messed around with this over the years.... figured i would ask for direction or ideas on how i might accopmlish this.... thanks