> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.ninjatrader.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.ninjatrader.com/_mcp/server.

# Fourier Moving Average

## Indicator Tutorial 9

Tradovate Trader includes some third-party libraries that can be helpful for indicators.

[Lodash](https://lodash.com/docs) is a very popular and high-performance library to work with arrays and objects. All you need to do is to include `const lodash = require("lodash")` in your module.

Another is a library for [Fast Fourier Transform](https://en.wikipedia.org/wiki/Fast_Fourier_transform). Here is an example of how to apply this library to build a moving average that calculated as FFT of input data, a filter of high frequencies, and inverse FFT.

```javascript
const predef = require("./tools/predef");
const FFT = require("fft");
 
class fourierMA {
   init() {
       const period = this.props.period;
       this.fft = FFT(period);
       this.signal = new Array(period);
       this.zero = new Array(period);
       for(let i=0; i<period; ++i) {
           this.zero[i] = 0.0;
       }
       this.lastIndex = -1;
   }
 
   map(d, index) {
       const period = this.props.period;
       const value = d.value();
 
       if (index < period) {
           this.signal[period - index - 1] = value;
       }
       else {
           if (this.lastIndex < index) {
               this.signal.pop();
               this.signal.unshift(value);
           }
           else {
               this.signal[0] = value;
           }
       }
 
       this.lastIndex = index;
 
       if (index >= period) {
           const re = [].concat(this.signal);
           const im = [].concat(this.zero);
           this.fft.fft1d(re, im);
 
           const middle = period / 2 + 1;
           const startFreq = this.props.filterFreqStart;
           for(let i=startFreq; i<middle; ++i) {
               re[i] = im[i] = 0.0;
               re[period - i] = im[period - i] = 0.0;
           }
           this.fft.ifft1d(re, im);
 
           return re[0];
       }
   }
}
 
module.exports = {
   name: "fourierMA",
   description: "Fourier MA",
   calculator: fourierMA,
   params: {
       period: predef.paramSpecs.period(64),
       filterFreqStart: predef.paramSpecs.period(16),
   },
   tags: ["My Indicators"],
};
```

![FFT MA](https://tradovate.github.io/custom-indicators/media/FFTMA.png)