# Get\_bars return null\[\]

**URL:** <https://forum.alpaca.markets/t/get-bars-return-null/11383>\
**Category:** Alpaca Market Data\
**Created:** [December 19, 2022, 6:08am UTC](https://forum.alpaca.markets/t/get-bars-return-null/11383 "2022-12-19T06:08:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![AlexL](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@AlexL](https://forum.alpaca.markets/u/AlexL)\
**Post date:** [December 19, 2022, 6:08am UTC](https://forum.alpaca.markets/t/get-bars-return-null/11383/1 "2022-12-19T06:08:10Z")

</div>

hey Guys!

```auto
import alpaca_trade_api as alpaca
import pandas as pd
import config

# Replace YOUR_API_KEY and YOUR_SECRET_KEY with your Alpaca API keys
api = alpaca.REST(config.ALPACA_KEY, config.ALPACA_SECRET_KEY, config.ALPACA_URL, "v2")

# Set the length and factor for the Super Trend indicator
length = 9
factor = 7

# Retrieve the latest market data for the S&P 500
bars = api.get_bars('SPY','1Day', limit=length)
sp500_data = pd.DataFrame(bars, columns=['t', 'o', 'h', 'l', 'c', 'v'])
sp500_data.columns = ['timestamp', 'open', 'high', 'low', 'close', 'volume']

# Calculate the average price over the specified length
average_price = sp500_data['close'].mean()

# Calculate the Super Trend value
sp500_data['super_trend'] = (sp500_data['high'] - sp500_data['low']) / factor + average_price

# Generate buy, sell, or hold signals based on the Super Trend value
try:
    if sp500_data['super_trend'][0] > sp500_data['close'][0]:
        super_trend_signal = "sell"
    elif sp500_data['super_trend'][0] < sp500_data['close'][0]:
        super_trend_signal = "buy"
    else:
        super_trend_signal = "hold"   
    print(f'The current Super_trend signal for the S&P 500 index is {super_trend_signal}')
except Exception as e:
    print(bars)
    print(f'Super_trend signal error: {e}')

```

**Could someone explain to me why he doesn’t return anything?**

```auto
> []
> Super_trend signal error: index 0 is out of bounds for axis 0 with size 0

```

---

<div class="post-metadata">

**Author:** ![oleg.rakhmatulin](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/oleg.rakhmatulin/32/559_2.png) [@oleg.rakhmatulin](https://forum.alpaca.markets/u/oleg.rakhmatulin)\
**Post date:** [December 24, 2022, 1:42pm UTC](https://forum.alpaca.markets/t/get-bars-return-null/11383/2 "2022-12-24T13:42:01Z")

</div>

The `limit` parameter limits the number of returned bars but this filter is applied only after the time range filter. If you don’t specify the `start` and `end` parameters it will mean “all bars for the current day” and in the case of a non-trading day you will not have any bars and REST API will return a null or empty array.
