Hello Quantopian Community,
I'm in the process of coding up my first strategy on the platform. I'm a seasoned Tradestation coder and just went through a Python course so I can learn to code here. Please excuse my newb Python code.
- I went through some examples and I'm trying to figure out how to compute a moving average of the gaps over the last 20 days. What I came up with is:
Gap = history(1, '1d', 'price')[stock] - history(0, '1d', 'open')[stock]
However the 'open' isn't supported and I'm not sure how I would use that to compute a moving average.
- I'm trying to compute the HOD/LOD in minute mode. To do this, I have two functions:
def HODLOD_Init (context, data):
HOD = data[context.stock].high
LOD = data[context.stock].low
def HODLOD (context, data):
if data[context.stock].high > HOD:
HOD = data[context.stock].high
elif data[context.stock].low > LOD:
LOD = data[context.stock].low
The scheduler runs the HODLOD_Init at 1 minute into the session. Then in:
def handle_data(context, data):
HODLOD()
I call the function every bar in the handle_data. Is this the correct way to do this?