Fourier Extrapolator of Price w/ Projection Forecast [Loxx]Due to popular demand, I'm pusblishing Fourier Extrapolator of Price w/ Projection Forecast.. As stated in it's twin indicator, this one is also multi-harmonic (or multi-tone) trigonometric model of a price series xi, i=1..n, is given by:
xi = m + Sum( a*Cos(w*i) + b*Sin(w*i), h=1..H )
Where:
xi - past price at i-th bar, total n past prices;
m - bias;
a and b - scaling coefficients of harmonics;
w - frequency of a harmonic ;
h - harmonic number;
H - total number of fitted harmonics.
Fitting this model means finding m, a, b, and w that make the modeled values to be close to real values. Finding the harmonic frequencies w is the most difficult part of fitting a trigonometric model. In the case of a Fourier series, these frequencies are set at 2*pi*h/n. But, the Fourier series extrapolation means simply repeating the n past prices into the future.
This indicator uses the Quinn-Fernandes algorithm to find the harmonic frequencies. It fits harmonics of the trigonometric series one by one until the specified total number of harmonics H is reached. After fitting a new harmonic , the coded algorithm computes the residue between the updated model and the real values and fits a new harmonic to the residue.
see here: A Fast Efficient Technique for the Estimation of Frequency , B. G. Quinn and J. M. Fernandes, Biometrika, Vol. 78, No. 3 (Sep., 1991), pp . 489-497 (9 pages) Published By: Oxford University Press
The indicator has the following input parameters:
src - input source
npast - number of past bars, to which trigonometric series is fitted;
Nfut - number of predicted future bars;
nharm - total number of harmonics in model;
frqtol - tolerance of frequency calculations.
The indicator plots two curves: the green/red curve indicates modeled past values and the yellow/fuchsia curve indicates the modeled future values.
The purpose of this indicator is to showcase the Fourier Extrapolator method to be used in future indicators.
Fourier
Fourier Extrapolator of Price [Loxx]Fourier Extrapolator of Price is a multi-harmonic (or multi-tone) trigonometric model of a price series xi, i=1..n, is given by:
xi = m + Sum( a *Cos(w *i) + b *Sin(w *i), h=1..H )
Where:
xi - past price at i-th bar, total n past prices;
m - bias;
a and b - scaling coefficients of harmonics;
w - frequency of a harmonic;
h - harmonic number;
H - total number of fitted harmonics.
Fitting this model means finding m, a , b , and w that make the modeled values to be close to real values. Finding the harmonic frequencies w is the most difficult part of fitting a trigonometric model. In the case of a Fourier series, these frequencies are set at 2*pi*h/n. But, the Fourier series extrapolation means simply repeating the n past prices into the future.
This indicator uses the Quinn-Fernandes algorithm to find the harmonic frequencies. It fits harmonics of the trigonometric series one by one until the specified total number of harmonics H is reached. After fitting a new harmonic, the coded algorithm computes the residue between the updated model and the real values and fits a new harmonic to the residue.
see here: A Fast Efficient Technique for the Estimation of Frequency , B. G. Quinn and J. M. Fernandes, Biometrika, Vol. 78, No. 3 (Sep., 1991), pp. 489-497 (9 pages) Published By: Oxford University Press
The indicator has the following input parameters:
src - input source
npast - number of past bars, to which trigonometric series is fitted;
nharm - total number of harmonics in model;
frqtol - tolerance of frequency calculations.
The indicator plots the modeled past values
The purpose of this indicator is to showcase the Fourier Extrapolator method to be used in future indicators. While this method can also prediction future price movements, for our purpose here we will avoid doing.
FFTLibraryLibrary "FFTLibrary" contains a function for performing Fast Fourier Transform (FFT) along with a few helper functions. In general, FFT is defined for complex inputs and outputs. The real and imaginary parts of formally complex data are treated as separate arrays (denoted as x and y). For real-valued data, the array of imaginary parts should be filled with zeros.
FFT function
fft(x, y, dir) : Computes the one-dimensional discrete Fourier transform using an in-place complex-to-complex FFT algorithm . Note: The transform also produces a mirror copy of the frequency components, which correspond to the signal's negative frequencies.
Parameters:
x : float array, real part of the data, array size must be a power of 2
y : float array, imaginary part of the data, array size must be the same as x ; for real-valued input, y must be an array of zeros
dir : string, options = , defines the direction of the transform: forward" (time-to-frequency) or inverse (frequency-to-time)
Returns: x, y : tuple (float array, float array), real and imaginary parts of the transformed data (original x and y are changed on output)
Helper functions
fftPower(x, y) : Helper function that computes the power of each frequency component (in other words, Fourier amplitudes squared).
Parameters:
x : float array, real part of the Fourier amplitudes
y : float array, imaginary part of the Fourier amplitudes
Returns: power : float array of the same length as x and y , Fourier amplitudes squared
fftFreq(N) : Helper function that returns the FFT sample frequencies defined in cycles per timeframe unit. For example, if the timeframe is 5m, the frequencies are in cycles/(5 minutes).
Parameters:
N : int, window length (number of points in the transformed dataset)
Returns: freq : float array of N, contains the sample frequencies (with zero at the start).
Function Sawtooth WaveThis is an indicator to draw a sawtooth wave on the chart.
It can be a useful perspective, as decaying markets tend to oscillate in reverse sawtooth waves, and bullish markets can oscillate in conventional sawtooth waves. With the right inputs, it can be an early warning signal for potential movements.
Something I've noted is that large waves cause a ripple effect and sets the frequency for the market until a change occurs. Sawtooth waves may help in capturing ripple waves.
Useful inputs are:
- Average True Range as wave height (amplitude)
- Periodicity of market as wave duration (frequency)
(Inputs will change the wave from conventional to reverse)
I hope that it is helpful.
GLHF
- DPT
Function: Discrete Fourier TransformExperimental:
function for inverse and discrete fourier transform in one, if you notice errors please let me know! use at your own risk...
Ehlers Discrete Fourier TransformThe Discrete Fourier Transform Indicator was written by John Ehlers and more details can be found at www.mesasoftware.com
I have color coded everything as follows: blue line is the dominant cycle, orange line is the power converted to decibels, and I have marked the other line as red if you should sell or green if you should buy
Let me know if you would like to see me write any other scripts!
FTSMA - Trend is your frendThis my new solid strategy: if you belive that "TREND IS YOUR FRIEND" this is for you!
I have tested with many pairs and at many timeframes and have profit with just minor changes in settings.
I suggest to use it for intraday trading .
VERY IMPORTANT NOTE: this is a trend following strategy, so the target is to stay in the trade as much as possible. If your trading style is more focused on scalping and/or pullbaks, this strategy is not for you.
This strategy uses moving averages applied to Fourier waves for forecasting trend direction.
How strategy works:
- Buy when fast MA is above mid MA and price is above slow MA, which acts as a trend indicator.
- Sell when fast MA is below mid MA and price is below slow MA, which acts as a trend indicator.
Strategy uses a lot of pyramiding orders because when you are in a flat market phase it will close 1 or 2 orders with a loss, but when a big trend starts, it will have profit in a lot of orders.
So, if you analize carefully the strategy results, you will note that "Percent Profitable" is very low (30% in this case) because strategy opened a lot of orders also in flat markets with small losses, BUT "Avg # bars in winning trades" is very high and overall Profit is very high: when a big trend starts, orders are kept open for long time generating big profits.
Thanks to all pinescripters mentioned in the code for their snippets.
I have also a study with alerts. Next improvement (only to whom is interested to this script and follows me): study with alerts on multiple tickers all at one. Leave a comment if you want to have access to study.
HOW TO USE STRATEGY AND STUDY TOGHETER:
1- Add to chart the strategy first, so your workspace will be as clean as possible.
2- Open the Strategy Tester tab at footer of the page.
3- Modify settings to get best results (Profit, Profit Factor, Drawdown).
4- Add study with alerts to your chart with same setting of strategy.
I WILL PROVIDE A DETAILED QUICK INSTALLATION GUIDE WITH THE STUDY!
Please use comment section for any feedback or contact me if you need support.
Low Frequency Fourier TransformThis Study uses the Real Discrete Fourier Transform algorithm to generate 3 sinusoids possibly indicative of future price.
I got information about this RDFT algorithm from "The Scientist and Engineer's Guide to Digital Signal Processing" By Steven W. Smith, Ph.D.
It has not been tested thoroughly yet, but it seems that that the RDFT isn't suited for predicting prices as the Frequency Domain Representation shows that the signal is similar to white noise, showing no significant peaks, indicative of very low periodicity of price movements.
[e2] Fourier series Model Of The MarketFourier series Model Of The Market
John F. Ehlers
TASC Jun 2019
WAMI Strategy Backtest The WAMI-based trading lies in the application and iteration of the
optimization process until the indicated trades on past market data
give consistent, profitable results. It is rather difficult process
based on Fourier analysis.
You can to change Trigger parameter for to get best values of strategy.
You can change long to short in the Input Settings
Please, use it only for learning or paper trading. Do not for real trading.