I know this isn't an exact solution to what you described above, but hopefully it will help guide in the right direction.
When you initialize your algo, you can add the below Custom Factor:
class MonthlyReturns(CustomFactor):
# predeclare your inputs and window length
inputs = [USEquityPricing.close]
window_length=21
# return out the montly return value
def compute(self, today, assets, out, close):
out[:] = close[-1]/close[0]
You could set your pipeline to update once per month, that way once per month you are adding 21 day returns to your pipeline (i.e. one month of trading days).
Once you have added this factor to the pipeline with something like:
monthly_returns = MonthlyReturns()
pipe.add(monthly_returns, 'monthly_returns')
In your order function, you can maybe implement an if statement on the return column for your algo to go long on stocks that are > 0 in this regard and short stock that are < 0 monthly returns. In the attached, I just went long on the top 100 returning stocks each month.