Back to Community
Help with Custom Functions

So I'm trying to write a function that tells quantopian to trade, only if the selected stock is on an uptrend, and if open has just overtaken my 'Enter' line on the pipeline. In backtesting, it's not working as expected. Here are some snippets to show how I'm doing this :

Uptrend:

def uptrend_check(context, data):  
        todays_open = history(1,'1d','open_price')  
        yesterday_open = history(2, '1d', 'open_price').iloc[0]  
        if (todays_open > yesterday_open):  
            return True  

Line Overtaking

def pipe_definition(context):  
return Pipeline(  
        columns = {  
        'Enter' : entrancestrategy,  
        'Exit' : exitstrategy,  
        'Open' : open_price,  
        },  
        screen = universe,  
        )  
def trade(context, data):  
    if uptrend_check:  
        open_rules = 'Open > Enter'  
    else:  
        Open_rules = 'Open == 50000000000'

     close_rules = 'Open > Exit'  

Of course, the else in Trade is to make sure it doesn't trade at all if uptrend_check returns False.

Could someone tell me what I'm doing wrong? I'm super new to this so any help is appreciated. I expect it's embarrassingly wrong. Thanks in advance.

Note: The code does run, but the transactions don't behave as expected.