Technical Indicator API

It would be nice to have REST API to technical indicators. SMA and bollinger bands are my favorites. My math is ok but I don’t trust myself completely writing these. I use another service which is going start charging. It would be nice if Alpaca offered this.
Thank you.

1 Like

As long as you have access to bars data, technicals like MAs and Bands are fairly easily to calculate and verify calculations on a site like tradingview…

Would you mind giving me some pseudocode on howe to achieve this?
Thank you.

What language are you working in? I would imagine there are existing libraries for this.

Java. I looked but couldn’t find anything yet.

I just found a library. When I was searching before I must have put in the wrong query. Thanks for pushing my blindness aside.

function 50MA (listOfBars) {
totalClosingPrice = 0;
listOfBars.foreach((x, index) => {
totalClosingPrice += x.closingPrice
if(index = 50){ break }
})
return (totalClosingPrice / 50)
}

here is a some psuedo-javascript example of taking in a list of bars(with your specified time frame) and returning a 50MA.

Look at anything TA-Lib based,


Agree that it would reduce the entry barriers if API could support indicators next to prices. Timeseries is a harder problems than it looks .

I used following python code the get ‘pandas’ output format.

df = api.alpha_vantage.techindicators(techindicator=‘RSI’, output_format=‘pandas’, symbol=‘AAPL’, interval=‘1min’, time_period=myperiod, series_type=‘close’)

But the output format is ‘json’. What is wrong? Please help!

What worked for me is to change the out put format to json
output_format=‘json’

example
tsla_sma = api.alpha_vantage.techindicators(techindicator=‘SMA’,symbol=‘TSLA’, interval=‘60min’, time_period=‘20’, series_type=‘close’,output_format=‘json’)
tsla_sma_data = tsla_sma.pop(‘Technical Analysis: SMA’)
tsla_sma_meta = tsla_sma.pop(‘Meta Data’)

Once you got your dictionarys split out then convert them to a dataframe

tsla_sma_data_df = pd.DataFrame.from_dict(tsla_sma_data,orient=‘index’,dtype=‘float64’)

While calculating technicals can be a pain, it’s much better to do it internally than sending a REST call.

The round trip time (RTT) for a rest call can easily be anywhere between 200ms-500ms depending on where the server is located. On the other hand, it’s much much faster to calculate it internally, overall giving your algo better execution times.

2 Likes

I was excited to try Alpaca until I learned that there is no technical indicator API. I am just getting into algo trading, and want the ability to experiment with many combinations of indicators with varying parameters. If with the candle data I could get a set of indicators of my choosing, I could do so much experimenting and even automate tuning of indicators and parameters used. Having to implement them myself or hunt for bits and pieces of libraries to put together is a deal killer for me. You do so much, Alpaca, it would seem that providing these indicators would not be that hard and would benefit so many.

@gbgrout Check out pandas-ta if you’re using Python. (I don’t use python but I read this library has many common technical indicators)

try this IEX Cloud API | IEX
+1 on adding this feature. I’m looking forward for ATR

The thing about indicators is that they can take on so many parameters and thus lead to so many variations. Take SMA for example, do you want 2-SMA, 3-SMA, … 9-SMA…11-SMA… 180 SMA, etc? And do you want the 1-minute 9 SMA, 5-minute 9 SMA? Oh what about 2-minute? And what about daily. Now, what about EMA?
If a market data provider also serves pre-computed indicators, their compute and storage costs blow up 100s, 1,000s, or even 10,000 folds.
And that’s why indicator calculations are deferred to the client. These clients would only need to calculate the indicators that it needs, on the fly (don’t have to store them).

On the other hand, some indicators do not depend on input parameters, such as day high, day low, day open, previous close, VWAP. These Alpaca does support.

We made a REST API for techincal indicators to deliver exactly this, check it out → https://taapi.io/
Super easy to integrate with Alpaca and hopefully anyone’s algo-bot. The API is made to save a lot of time and effort when building trading bots. Get in touch if you’d like to know more.