FMP
Oct 10, 2024 2:57 PM - Sanzhi Kobzhan
Image credit: technical analysis with EMA
The Exponential Moving Average (EMA) is a widely used indicator in Technical Analysis, designed to help smooth out price data and identify trends by placing greater weight on recent prices. This makes it particularly valuable in fast-moving markets, as it quickly responds to price changes while minimizing noise. EMA can help define the strength of the trend and help traders buy stocks at the right time. In this article, we'll dive into what EMA is, how it's calculated, how to use it to define the strength of the trend and how to use the Financial Modeling Prep (FMP) API to access EMA data for any stock in real time.
The Exponential Moving Average (EMA) is a type of moving average that gives more weight to recent prices than older prices. This feature makes the EMA more sensitive to current price changes, which can help traders spot trends earlier and make timely trading decisions. EMA represents the line on the graph that goes close to the stock market price.
Use example:
This quick reaction to new prices is what sets EMA apart from other averages, like the Simple Moving Average (SMA), which treats all prices equally over the chosen period.
EMA is useful for both short-term and long-term traders:
EMA can also act as a “support” or “resistance” level:
This behavior helps traders decide when to buy or sell. For example, if the price bounces off the EMA, it might be a good buying opportunity. If it drops after reaching the EMA, it might be a sign to sell or hold off on buying.
Let's go through the calculation of the EMA step by step. While software and online calculators can quickly provide the EMA, understanding the formula helps you see why it's useful.
Step 1: Start with the Simple Moving Average (SMA)
To get started, calculate the SMA for the chosen period. For example, if you're using a 10-day EMA, add up the closing prices for the past 10 days and divide by 10. This gives you the average closing price over that period.
Step 2: Calculate the EMA Multiplier
Next, calculate the multiplier, which gives more weight to recent prices. This is based on the period you're using for the EMA. The formula for the multiplier is:
Multiplier = 2 / (Period + 1)
For a 10-day EMA, the multiplier would be:
2 / (10 + 1) = 0.1818
This multiplier will weight each day's closing price in the EMA calculation.
Step 3: Calculate the EMA Using the Multiplier
After getting the SMA and the multiplier, you can calculate the EMA. Here's the formula:
EMA = ( Close Price − Previous EMA ) × Multiplier + Previous EMA
This formula updates the EMA by combining the previous EMA with today's closing price. The multiplier makes sure that more recent prices have a stronger effect on the EMA than older ones.
Let's say you have the following 10 closing prices for a stock:
Day 1: $25.00, Day 2: $26.00, Day 3: $27.00, Day 4: $26.50, Day 5: $27.50, Day 6: $28.00, Day 7: $29.00, Day 8: $29.50, Day 9: $30.00, Day 10: $31.00
The EMA now reflects recent price changes with heavier weighting and would continue to update as each new closing price becomes available. This step-by-step adjustment highlights how the EMA places greater emphasis on recent prices, making it responsive to changes in the stock's trend. But don't worry if those calculations seem difficult for you. You don't have to calculate everything manually. You can extract data using Financial modeling prep Exponential Moving Average API endpoint. Lets consider how you can do that.
1. Set up the API Endpoint.
To access the EMA data for Apple (AAPL) on a 5-minute interval, you'll use the Exponential Moving Average API endpoint
The endpoint looks like this:
https://financialmodelingprep.com/api/v3/technical_indicator/5min/AAPL?type=ema&period=10&apikey="your custom API key”
Replace “your custom API key” with your unique API key from FMP. For that you will need to register with FMP and obtain your key.
2. Define Parameters in the API URL
3. Make the API Call
Once the URL is configured with your API key, you can enter it into your browser or send a request using any HTTP client ( like
Postman for example). And you can also use this endpoint for building your custom stock analysis app. But if you simply want to see the data you can run it in your browser and get the below response.
The API returns a JSON array with the latest EMA values for each interval. Here is a sample response:
[
{
"date": "2024-10-09 15:55:00",
"open": 229.57,
"high": 229.75,
"low": 229.44,
"close": 229.49,
"volume": 1332751,
"ema": 229.39818494063962
},
...
]
Each object in the JSON array includes:
- Date: Timestamp for the price data.
- Open, High, Low, Close: Price data points.
- Volume: Volume traded during that interval.
- EMA: The calculated Exponential Moving Average for the specified period (in this case, a 10-period EMA).
If you want to build your custom app and get data using JavaScript, or you can export your findings into excel using Playground. Here is how you can extract data.
1. Define API parameters
const apiKey = “your custom API key”;
const symbol = “AAPL”;
const interval = “5min”;
const period = 10;
2. Construct API URL
const url = “https://financialmodelingprep.com/api/v3/technical_indicator/${interval}/${symbol}?type=ema&period=${period}&apikey=${apiKey}";
3. Fetch EMA data from the API
fetch(url)
.then(response => response.json()) .then(data => {
data.forEach(entry => {
console.log(`Date: ${entry.date}, EMA: ${entry.ema}`);
});
})
.catch(error => console.error('Error fetching EMA data:', error));
1. Go to FMP Playground
2. Choose indicators.
In the left side bar, choose The Technical Indicators field, then click on the Exponential Moving Average
3. Input data.
Choose stock Tiker, type, period.
4. Export data.
You can find the Export button at the top right corner. Click on it to export in different formats like JSON, CSV or Text.
Let's say you're analyzing AAPL using this data:
The EMA can also serve as a support/resistance level. For instance, if AAPL's price falls to the EMA but then bounces back, the EMA acts as a support level.
Understanding and applying the Exponential Moving Average can provide valuable insights into price trends and potential trading opportunities. The Financial Modeling Prep API simplifies accessing this data, making it easy to integrate into your trading tools. Try experimenting with different time intervals and periods to find the EMA settings that best align with your trading strategy.
May 14, 2024 11:41 AM - Sanzhi Kobzhan
A stock's target price, also known as its fair value, is an indication of what a share can cost based on the company’s forecasted financial statements. It is important to know a stock's fair value to find undervalued stocks with great growth potential. Let's consider how investment analysts calculat...
May 24, 2024 9:30 AM - Rajnish Katharotiya
Earnings call transcripts are invaluable resources for investors, analysts, and financial enthusiasts. They provide insights into a company's performance, strategy, and future outlook, making them essential for making informed investment decisions. With Financial Modeling Prep, Earnings Call Transcr...
May 27, 2024 3:30 PM - Rajnish Katharotiya
In the ever-evolving world of technology, certain sectors have consistently demonstrated exceptional growth and innovation. The graphics processing units (GPUs) industry is one such sector, offering investors a golden opportunity for potentially high returns. In this blog, we'll delve into why inves...