Back to Community
How to create a stock market scanner using pipeline in your jupyter notebook ( with built-in hammer price action)

Hello guys, today I want to share with this community a stock market scanner I have been developing (is not done yet) in order to be a useful tool at the moment to select stocks that accomplish particular criteria:

This scanner is component by one price action structure not avaibables in the Talib librarie and two strategies signal, this is just for buy orders.

The price price actions is:

  • The hammer pattern: This pattern is a boolean factor which one is created by SMAs with a lenght of one period to replicate the OLHC componente of the canddle, this was needed in order to create the boolean conditions, this pattern is constructed with the most recent candle structure [-1] , is different to Talib price action hammer, dragon fly and doji, because is more flexible and contain all of prior and more scenarios:
   mid_price= (high+low)/2  
    box= (close-open1).abs()  
    limit_box = (high-low)*0.25 #this variable give to the structure the maximum size can have the box in compare with the high - low difference  
    condition_5 = close > mid_price  
    condition_6 = open1 > mid_price  
    condition_7 = caja <= abport  
    hammer = condition_5 & condition_6 & condition_7 


The two strategies signals are:

  • Reversal trend up to down: This strategy signal follow the next sequence = stock close price above 20 day SMA, below 50 days SMA and 200 days SMA:
    condition_1 = price > sma20  
    condition_2 = price < sma50  
    condition_3 = price < sma200  
    condition_4 = 5 < price <120  
    sma_condition = condition_1 & condition_4 & condition_3 & condition_2  
  • RSI and MACD: This strategy signal follow and use the Talib built-in indicators of RSI and MACD working with the next sequence = RSI < 40 and MACDsignal < -1.5 (this settings are not be optimized yet):
    condition_1 = rsi < 40  
    condition_2 = macd < -1.5  
    technical_condition = condition_1 & condition_2

With alphalens you can evaluate it if works or not, but you must set the quantiles and bins in the next way:

   asset_list = factor.index.levels[1].unique()  
   pricing = get_pricing(asset_list,start_date="2019-4-5", end_date="2020-5-5", fields= "close_price" )  
   merged_data = get_clean_factor_and_forward_returns(factor, pricing, quantiles= None, bins= [-1, .5, 2])  

This settings on alphalens was provided thanks to Dan Whitnable Here and is useful to analyze boolean factors.

The above instruction is just for do the scanning process for boolean factor, but you can used it and combine it with regular factors, this instruction is not for automated trading, it works just as a filter and then you apply your discretional style.

Loading notebook preview...