Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Trying to develop a simple ATR breakout strategy on a 15min timeframe.

Hi all,
I am trying to develop a simple ATR breakout strategy on a 15min timeframe.

I tried to use resample('15min') on a minute dataframes of high, low and close price, and then use that for calculating ATR.
But I am just seeing 'nan' .

Can anyone please help me with this?

2 responses

So I found the problem, and here is the fixed code for rebalance:

# Rebalance every 15mins.  
def rebalance(context, data):  
    # Load historical data for the stocks  
    historyperiod = 2 * context.timeperiod * context.ATRperiod  
    hist = data.history(context.stocks, ['high', 'low', 'close'], historyperiod, '1m')  
    for stock in context.stocks:  
        # Calculate the ATR for the stock  
        high = hist['high'][stock].resample('15min', how='max').dropna()  
        low = hist['low'][stock].resample('15min', how='min').dropna()  
        close = hist['close'][stock].resample('15min', how='last').dropna()  
        atr = talib.ATR(high.values, low.values, close.values, timeperiod=context.ATRperiod)[-1]  
        print high.index[-3:-1]  

But now I see another problem. Here when we print the high.index[-3:-1], I get
PRINT DatetimeIndex(['2011-01-03 21:00:00+00:00', '2011-01-04 14:30:00+00:00'], dtype='datetime64[ns]', freq=None, tz='UTC')

Here resample is creating a timestamp for '2011-01-04 14:30:00+00:00' which is the market open time, if I am not wrong.
Now we dont want a 15min candle for this time. Rather our first 15min candle should be at '2011-01-04 14:45:00+00:00', so now how do I get rid of this '2011-01-04 14:30:00+00:00' candle?

Any help is really appreciated :)

Hi Harsh,

Did you even find a solution to this problem. I am having same issues.

Thanks
Serge