Have seen similar strategies peddled across a few trading sites.
So I figured it was worth attempting to quickly code....
Results were a tad dissapointing
Have seen similar strategies peddled across a few trading sites.
So I figured it was worth attempting to quickly code....
Results were a tad dissapointing
I am not seeing how you identify the 52-week high. These commands just return the first high (0 is the first period):
high = (high_history[stock])[0]
low = (low_history[stock])[0]
I think you need something like this:
high = max(high_history[stock])
low = min(low_history[stock])
Tristan
Considering the history() function also get the data of current tick
you need to exclude the current value.
high_history = history(252,'1d','high')
low_history = history(252,'1d','low')
high = max(high_history[stock][:251])
low = min(low_history[stock][:251])
Yagnesh: Great catch! I believe this can also be done with:
high = max(high_history[stock][:-2])
low = min(low_history[stock][:-2])
This should create a "slice" that starts at the beginning (index=0) but does NOT include the most recent entry (index=-1).
On my third take, I think that this would be the right code:
high = max(high_history[stock][:-1])
low = min(low_history[stock][:-1])
The reason is because Python ranges and slices are "half open". This means they include the first value listed, but not the last value. So the "-1" is the end of the slice, but it is not included in the slice. :)
Haha yes it was not 52 week highs at all
Ill blame working at 3am!
Just did a run through and will need to manually exclude leveraged etfs