olivier,
You may get any time frame from Quantopian data.history() using .resample()
Hope this simple code will help you.
def initialize(context):
schedule_function(trade, date_rules.month_start(), time_rules.market_open(minutes = 65))
def trade(context, data):
#---------------------------------------------
stock, TimeFrame, ma = symbol('SPY'), '1M', 10
#---------------------------------------------
bars = ma*21
if get_open_orders(): return
curr_price = data.current(stock, 'price')
daily_prices = data.history(stock, 'price', bars, '1d')
monthly_prices = daily_prices.resample(TimeFrame).last()
print monthly_prices
mavg = monthly_prices.mean()
if data.can_trade(stock):
if curr_price >= mavg:
order_target_percent(stock, 1.0)
else:
order_target_percent(stock, 0)
record(price = curr_price, mavg = mavg)