Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Get a symbol's "low" price for today using data.history

Hello there,

I'm struggling to compare today's low price with a propietary indicator line I'm generating (visually similar to a Bollinger Band lower band).

This is what I'm currently doing, which is not working.

I run a check of the status so I can trade at the market close:

schedule_function(check_bands,date_rules.every_day(),time_rules.market_close())  

I get the current price and the low price for today as follows:

 cur_price = data.current(context.stock,'price')  
 low_price = data.history(context.stock,'low',1,'1d')   #I'm not confident this is doing what i want  

I calculate my indicator value and assign to the variable called: lower_band

I then compare today's low to the lower_band in order to generate trade signals:

if low_price[0] <= lower_band:  
#then go long  

Problem is, I am not able to replicate the signals from my original (and trusted) excel prototype!

I suspect I am not getting today's low price in "low_price[0]"

Any hints /tips appreciated!

2 responses

Try this:

if low_price[-1] <= lower_band:  

low_price_for_today = low_price[-1]

Tks Vladimir - When I ran both side by side (low_price[-1] & low_price[0]) and printed to screen, both produced the same values. I'm now trying to recreate in a notebook to understand more. If i learn anything useful I will post here. Tks again.