Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
boolean values, patterns

Im using simple booleans to determine a pattern and price action. Trouble is Im getting True result on the values that should be false.

I even went to the python 3.5 IDLE to double check if I did something wrong

Pattern that Im looking for is a big red candle thats engulfing the next days green candle

Here's the code from Python 3.5 IDLE where the bool value being returned is Flase . Prices are AAPL for 15th and 16th November

>>> close_1d = 110.01  
>>> close_2d = 107.11  
>>> open_1d = 106.70  
>>> open_2d = 106.57  
>>> open_2d > close_2d and open_1d < close_1d and open_2d > close_1d and open_2d > open_1d and close_2d <= open_1d and close_2d < close_1d  
False  

Here is the algo code, where I used exactly the same bool inputs for screening as in Python IDLE

# The pipeline API requires imports.  
from quantopian.pipeline import Pipeline  
from quantopian.pipeline import CustomFactor  
from quantopian.algorithm import attach_pipeline, pipeline_output  
from quantopian.pipeline.data.builtin import USEquityPricing  
from quantopian.pipeline.factors import SimpleMovingAverage

class CurClose(CustomFactor):  
    inputs = [USEquityPricing.close]  
    window_length = 1  
    def compute(self, today, assets, out, close):  
        out[:] = close[-1]  
class CurOpen(CustomFactor):  
    inputs = [USEquityPricing.open]  
    window_length = 1  
    def compute(self, today, assets, out, open):  
        out[:] = open[-1]  
class YesClose(CustomFactor):  
    inputs = [USEquityPricing.close]  
    window_length = 2  
    def compute(self, today, assets, out, close):  
        out[:] = close[-2]  
class YesOpen(CustomFactor):  
    inputs = [USEquityPricing.open]  
    window_length = 2  
    def compute(self, today, assets, out, open):  
        out[:] = open[-2]

def initialize(context):  
    #Created and attached pipeline  
    pipe = Pipeline()  
    pipe = attach_pipeline(pipe, name = 'my_pipeline')  
    #Construct Factors  
    close_1d = CurClose()  
    close_2d = YesClose()  
    open_1d = CurOpen()  
    open_2d = YesOpen()  
    #Construct Filters  
    #This screen should find simple pattern based on open and close values from las two trading days  
    #Pattern that Im looking for is a big red candle thats engulfing the next days green candle  
    screen = open_2d > close_2d and open_1d < close_1d and open_2d > close_1d and open_2d > open_1d and close_2d <= open_1d and close_2d < close_1d  
    #Register outputs  
    pipe.add(screen, 'screen')  
    pipe.add(open_2d, 'open_2d')  
    pipe.add(close_2d, 'close_2d')  
    pipe.add(open_1d, 'open_1d')  
    pipe.add(close_1d, 'close_1d')  
    #Filter results  
    pipe.set_screen(screen)  
def before_trading_start(context, data):  
    results = pipeline_output('my_pipeline')  
    print(results)  

Results from the pipeline_output , note AAPL prices are the ones being double checked with Python IDLE

2016-11-17 14:45  PRINT                           close_1d  close_2d  open_1d     open_2d screen  
Equity(24 [AAPL])          110.010   107.110  106.700  106.570000   True  
Equity(39 [DDC])             8.565     8.500    8.530    8.430000   True  
Equity(62 [ABT])            39.950    39.800   39.800   39.290000   True  
Equity(64 [ABX])            15.600    15.580   15.550   14.780000   True  
Equity(67 [ADSK])           77.570    75.140   74.920   73.860000   True  
Equity(70 [VBF])            18.370    18.109   18.180   17.970000   True  
Equity(84 [ACET])           19.180    19.170   19.000   19.230000   True  
Equity(106 [ACU])           21.700    21.610   21.820   21.730000   True  
Equity(110 [ACXM])          26.890    26.760   26.550   27.030000   True  
Equity(114 [ADBE])         104.080   103.660  103.610  103.140000   True  
Equity(149 [ADX])           13.100    13.080   13.050   13.020000   True  
Equity(154 [AEM])           44.270    44.220   44.200   41.990000   True  
Equity(162 [AEPI])         113.000   112.700  112.700  112.450000   True  
Eq...