is_symbol_qualified question

Brett_SpenceBrett_Spence Posts: 11
edited March 2017 in Under The Hood

In my is_symbol_qualified I am looking for specific opening and closing values of the past two days. I want the symbols whose low yesterday is lower than the day before, but closed higher than the day before.
This is the code:
return ((md.stat.atr) >= (0.25)) and ((md.stat.avol) >= (750000)) and ((md.stat.prev_close) >= (2)) and ( ((md.bar.daily(start=-1).low[0]) < (md.bar.daily(start=-2).low[0])) and ((md.bar.daily(start=-1).close[0]) > (md.bar.daily(start=-2).close[0])) )
Sometimes (most times) it returns an index error: IndexError: index 0 is out of bounds for axis 0 with size 0.
I can't figure out why it wouldn't be picking up those previous couple of days values. I suspect it might be the way I am asking for the data (I don't have a great grasp of the data structures in the system) Any ideas would be greatly appreciated?
I was thinking of just putting the whole statement in a try catch, but I don't think that will return any symbol universe anyway - it'll just suppress the issue.

Comments

  • mgmg Posts: 13
    edited March 2017

    You should definitely read up on the quickref guide]

    To answer your question, you are probably requesting bar data for symbols that don't have bar data. You should first check the length of the list to make sure there is data before you access it.

    bars = md.bar.daily(start=-5)
    if len(bars.timestamp) > 0:
        yesterday_low = bars.low[-1]
        two_day_close = bars.close[-2]

    Also, you should probably try to request slightly more data than you need in the function call, then use list comprehensions to access the specific bar data you want.

    For example, to access the open of two days ago:
    (md.bar.daily(start=-5).open[-2])
    In this example, we are requesting 5 bars, then accessing the second from last list item for the day before yesterday. (Assuming all symbols that qualify actually had a formed bar on that day)

Sign In or Register to comment.