Calculating the Force Index as an EMA of Price-Volume Change
Summary
The Force Index combines the change in closing price from one period to the next with the current period’s volume. A smoothed Force Index applies an exponential moving average to those raw price-volume values; volume belongs in each raw observation before smoothing, rather than being added separately to the EMA update. The response confirms that the EMA recurrence should use the prior smoothed Force Index and the current raw Force Index as its input.
For initialization, the suggested approach is to seed the EMA with a simple average of the first period of raw Force Index observations, then continue with the exponential update. Starting from zero is also possible, but the response cautions that it can take many bars for the estimate to converge sufficiently. The question includes C++ attempts, but the explanation focuses on the calculation rather than a full code review. It does not assess the indicator’s trading effectiveness or specify details such as data alignment and handling missing observations.
Key ideas
- Calculate raw Force Index from the close-to-close price change multiplied by volume.
- Apply the EMA to the sequence of raw Force Index observations.
- Seed the EMA with a simple average of an initial window of raw values.
- Starting the EMA at zero can delay convergence to a useful estimate.
- The explanation concerns calculation and initialization, not trading performance.
Tags
Full text
# Force Index EMA calculation for stock indicator
# Force Index EMA calculation for stock indicator
I am trying to smooth a 13 period EMA Elder Force Index in c++, and nobody really describes this as anything more than :
```
Force Index(1) = {Close (current period) - Close (prior period)} x Volume.
Force Index(13) = 13-period EMA of Force Index(1).
```
I must be a bit thick, but when you use a moving average with a period, you get an average of that period, and then use that as a reference for further day MA's. I have calculated SMA & Exp MA for exstensive data sets before, but how are you supposed to calculate smoothed Force Index for an exstensive period of time ?
```
void indicators::EMA(input* Close1, size_t Start, size_t Period) {
vector<double> CloseRe (Close1->Close.rbegin(), Close1->Close.rend());
vector<double> Xtemp;
for(size_t i = Start; i < Period; i++) {
Xtemp.push_back(CloseRe[i]);
}
// cout << Xtemp.size() << endl;
double InitXavg = (std::accumulate(Xtemp.begin(), Xtemp.end(), 0.0) / Xtemp.size());
ExpMA.push_back(InitXavg);
for(size_t j = Period; j < CloseRe.size(); j++) {
tmpEMA = ((CloseRe[j] - ExpMA[j-Period]) * (2.0 / (Period + 1.0))) + ExpMA[j-Period];
// cout << j << " is " << CloseRe[j] << endl;
ExpMA.push_back(tmpEMA);
tmpEMA = 0.0;
}
return;
}
```
The above calculates Exponential Moving Average , and the below was supposed to calculate the force index smoothed for extensive data set, with 13-day period. But I can't say I really understand how this is supposed to work, as the standard EMA uses only close price & previous day average & multiplier. How are you supposed to incorporate volume there beyond the original 13 day period ? :
```
void indicators::ForceIndexEMA(input* Close1, input* Volume1, size_t Start, size_t Period) {
vector<double> CloseRe (Close1->Close.rbegin(), Close1->Close.rend());
vector<double> VolumeRe(Volume1->Volume.rbegin(), Volume1->Volume.rend());
vector<double> FXtemp;
for(size_t i = Start; i < Period; i++) {
FXtemp.push_back((CloseRe[i+1] - CloseRe[i]) * VolumeRe[i]);
}
ForceXMA.push_back(std::accumulate(FXtemp.begin(), FXtemp.end(), 0.0) / FXtemp.size());
for(size_t j = Period; j < CloseRe.size(); j++) {
ForceXMA.push_back(((CloseRe[j] - ForceXMA[j-Period]) * (2.0 / (Period + 1.0))) + ForceXMA[j-Period]);
}
return;
}
```
You could just calculate day-to day force index with a loop, but I keep seeing everywhere how the smoothed EMA average is supposed to give more reliable signals in certain scenarios. So my question would be what I am doing wrong here.... ? I understand this is not a forum for programming, but I am not dependent on having this explained as such. I just haven't seen anyone explain it well at all ? What about the current volume ? An EMA does not in general work with volume, so using the standard way of calculating the EMA would just be nearing the day's closing prices as you looped through the data set...
EDIT: I have managed to do what I see as an "EMA" of the 1-period force index values here, but could anyone correct me if it is wrong ? :
```
void indicators::ForceIndex(input* Close1, input* Volume1, size_t Start, size_t Period) {
vector<double> CloseRe (Close1->Close.rbegin(), Close1->Close.rend());
vector<double> VolumeRe(Volume1->Volume.rbegin(), Volume1->Volume.rend());
vector<double> FXtemp;
for(size_t i = Start; i < Period; i++) {
FXtemp.push_back((CloseRe[i+1] - CloseRe[i]) * VolumeRe[i+1]);
}
ForceXMA.push_back(std::accumulate(FXtemp.begin(), FXtemp.end(), 0.0) / FXtemp.size());
for(size_t j = Period; j < CloseRe.size(); j++) {
double daily = ((CloseRe[j+1] - CloseRe[j]) * VolumeRe[j+1]);
ForceXMA.push_back(((daily - ForceXMA[j-Period]) * (2.0 / (Period + 1.0))) + ForceXMA[j-Period]);
daily = 0.0;
}
return;
}
```
As far as I can see this should weight the volume also, but as for the logic of the "average" of the calculation I am still a bit uncertain...
## Answer by Dave Skender (score 1)
https://quant.stackexchange.com/a/64298
Simply put, Force Index by Alexander Elder is an EMA of a "raw" Force Index, which is:
```
# raw force index
RFI = Volume * (Close - Prev Close)
```
To initialize the EMA of RFI, you'd need to do a basic Simple Moving Average (SMA) of the first `Period` bars of the `daily` RFI. Without this initialization, you're essentially using `0` as the initialization, which is not terrible, but it might take an extra 100-200 bars before it converges to acceptable accuracy due to the way EMA works.
```
# EMA of RFI
# For the first instance, substitute SMA of RFI for Previous Force Index (not shown)
k = 2 / (Period + 1)
ForceIndex = Prev Force Index + k * (RFI - Previous Force Index)
```
From what I can tell, your final formula appears to be correct. My open-source C# .NET library includes the formula for Force Index and a manually calculated Excel spreadsheet. Might be worth a comparison.Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.