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?

Clone Algorithm
9
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 57a5bc2a3d9e1a0ff425119d
There was a runtime error.
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