# Technical Indicators from Past Data

**URL:** <https://forum.alpaca.markets/t/technical-indicators-from-past-data/15051>\
**Category:** Alpaca Market Data\
**Created:** [September 26, 2024, 12:39pm UTC](https://forum.alpaca.markets/t/technical-indicators-from-past-data/15051 "2024-09-26T12:39:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Spears](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/daniel_spears/32/6549_2.png) [@Daniel\_Spears](https://forum.alpaca.markets/u/Daniel_Spears)\
**Post date:** [September 26, 2024, 12:39pm UTC](https://forum.alpaca.markets/t/technical-indicators-from-past-data/15051/1 "2024-09-26T12:39:14Z")

</div>

I am a paid member using paper trading.

I planned on using the method to retrieve past stock data to calculate the EMAs of various stocks.

So, I ran this function:

def validate\_ema9(bar,symbol):  
client = StockHistoricalDataClient(api\_options.ALPACA\_API\_KEY,api\_options.ALPACA\_SECRET\_KEY)

```
bars_request = StockBarsRequest(
    symbol_or_symbols=symbol,
    timeframe=TimeFrame.Minute,
    start=pd.Timestamp.now() - pd.Timedelta(days=20),
    end=pd.Timestamp.now()
)

bars = client.get_stock_bars(bars_request).df

bars['EMA9'] = bars['close'].ewm(span=9, adjust=False).mean()

last_ema9 = bars['EMA9'].iloc[-1]

last_bar_timestamp = bars.index[-1]

print(f"Most recent bar timestamp: {last_bar_timestamp}")

return bar['close'] > last_ema9

```

The problem is the data is 8 hours old… Is there a better way to get past data?
