Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Trading Candle Patterns

There aren't many shared algos that trade candle patterns so I have shared this. Some candle patterns are very effective but never occur and some are very common but not especially effective. I have tried to combine a a few patterns that are reasonably effective and occur enough to generate a reasonable number of entries. Stops based on Average True Range are used to exit losing positions.

P.

2 responses

Peter,
Does 'cash = context.portfolio.cash' represent profit?

Thanks!

Hello Adam,

'context.portfolio.cash' represents cash at hand plus cash credited from short positions.

Profit would be something like positions value + cash - starting cash.

Have a play with this code:

def initialize(context):  
    context.first = True

def handle_data(context, data):  
    if context.first:  
        order(sid(24), 1)  
        context.first = False  
    if context.portfolio.positions[sid(24)].amount != 0:  
        print context.portfolio.starting_cash  
        print context.portfolio.cash  
        print context.portfolio.positions_value  
        print context.portfolio.pnl  
        print context.portfolio.positions[sid(24)].cost_basis  
        print context.portfolio.starting_cash - \  
            (context.portfolio.positions[sid(24)].cost_basis * context.portfolio.positions[sid(24)].amount)  
        print context.portfolio.positions_value - \  
            (context.portfolio.positions[sid(24)].cost_basis * context.portfolio.positions[sid(24)].amount)  
        print context.portfolio.positions_value + context.portfolio.cash - context.portfolio.starting_cash  

and try to work out some relationships.

P.