Hello guys, I want to know how can create a custom factor on LEAN, the next example is extracted from my Quantopian code:

 

from quantopian.pipeline import CustomFilter
import numpy as np
from quantopian.pipeline.data import USEquityPricing


class fibopoint(CustomFilter):

inputs = [USEquityPricing.low, USEquityPricing.high, USEquityPricing.close]

window_length = 21


def compute(self, today, assets, out, low, high, close):

dayshigh20 = np.max(high, axis=0)

dayslow20 = np.min(low, axis=0)

mid_price = (high[-1]+low[-1])/2

fiboprice2 = dayshigh20 - (.50*(dayshigh20-dayslow20))

cond = (np.argmax(dayshigh20, axis=0) - np.argmin(dayslow20, axis=0))>0

fibocondition_2 =mid_price >= fiboprice2

result1 = fibocondition_2 & cond & (high[-1]<= (dayshigh20 - (.10*(dayshigh20-dayslow20))))

out[:] = result1

Thanks a lot!