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)