/******************************************************************** Title: Maximum Entropy Spectrum Analysis Script for eSignal By: Divergence Software, Inc. Web: http://www.sr-analyst.com ===================================================================== Project Description: This script calculates the power spectrum of a data series using the Maximum Entropy Spectrum Estimation method and produces a power spectrum plot. The Maximum Entropy algorithm, unlike a simple FFT transform, will include frequencies from the entire complex frequency plane and not just the Nyquist interval which, in general terms, means that it can resolve cycle periods that are larger than the data window passed to the function. In addition, MESA has the ability to fit very sharp spectral features which are often missed by other analysis methods. The displayed power spectrum will highlight the dominant cycles and frequencies within the data and will display the Period and Frequency below each peak. Prior to being passed to the MESA algorithm, the log of the price data is detrended using a least means squared filter. To test the operation of the MESA algorithm, a sine-wave generator is included (set the variable bSineTest to 'true' in the EFS script below). If you experiment with this tool, you will quickly find that most financial time series have their highest amplitudes at the low end of the frequency spectrum and most of these 'dominant' cycles are too long to be used for short-term trading. The script has two display filters that can be applied (frUCycle and frLCycle) where you can input an upper and lower cycle period boundary. This allows you to effectively ignore the very high and/or very low frequencies so that you can concentrate on finding cycles within in a period range that makes sense for your trading style. Periods are calculated as the number of bars required to complete a cycle and frequencies are calculated as the number of degrees of change per bar. P = Bars per Cycle; F = 360/P (360-degrees divided by period) An alternative F value can be calculated as number of cycles in the data period N: F = N/P. The spectral information can be used as the basis for additional cycle study work or it can be used to fine-tune various oscillators and indicators. The typical approach is to use the Power Spectrum to identify the dominant cycle in your data and then set your moving average or oscillator to a period that is 1/2 of the dominant cycle. This indicator uses a eSignal EFS Library to perform the calculations. The required library file is included along with the indicator in the Zip file. Please copy this library file (e.g., dsMesa.efsLib) into your eSignal FunctionLibrary directory (which is typically found at C:\\Interactive Data\FunctionLibrary\) ===================================================================== Loading the Indicator: Once the installation has completed, the indicator will be stored in a eSignal Formulas folder called "MESA". Follow these steps to load the indicator into a chart. 1. Pull up a chart in eSignal. 2. Right-click in the chart and select the Insert Study option from the menu. 3. In the Insert Study dialog, click on the "Formulas" tab. 4. Now, scroll down until you see a folder called "MESA". Double-click on this folder to open it. 5. You should see a file in that folder called MESASpectrum_for_v12.efs. Click on this file, then click on the Apply button, then close the Insert Study dialog. 6. The MESA Spectrum indicator is now loaded into your chart. ===================================================================== Time Template: When you first load the MESA Spectrum indicator, you may very well see a message "Not enough bars of data in your chart". If you see this message then you will need to apply a eSignal Time Template to your chart that pre-loads enough data for the Spectrum indicator to perform its calculations. By default (with no Time Template applied) a eSignal chart will only contain a couple of hundred bars of data. The default Window Size for the MESA Spectrum is 512 bars, meaning it needs at least 512 bars of data. I recommend that you create a Time Template that pre-loads 1200 bars of data so that, regardless of which Window Size you select the indicator will have enough data to operate. If you are not familiar with eSignal Time Templates or how to use them, please browse to the eSignal Knowledgebase (http://kb.esignalcentral.com/), type in the search term "Time Template" and review the first few articles. ===================================================================== Various parameters can be adjusted via indicator menu: Window Size: This is the data window size to use when performing the anaysis. Valid values are 64, 128, 256, 512 and 1024. Based upon the window size you select, the requisite number of bars will be loaded and passed to the MESA function. Default value is 512. Poles: The number of 'poles' of the approximation. This represents the number of coefficients used in the autocorrelation function and can be a number from 1 to N where N is the size of the data window being used. Generally, the larger the number of poles, the sharper the frequency distinction becomes. You can use the 'P++' and 'P--' buttons to quickly increase/decrease the Poles value while viewing a power spectrum. Default is 200. The best analogy I can come up with for the 'poles' is adjusting the contrast on your TV. This value will typically need to be adjusted for each new data series you are analyzing to bring the desired spectral features into focus. Multiplier: A multiplier to be applied to the base number of output data points to create the desired number of output data points. This represents the total number of frequencies for which coefficients will be evaluated. The larger the number, the 'denser' the spectrum plot will be. Typically, a number in the range of 1 to 40 is expected and a value of 20 seems to work well with financial time series (which contain a lot of noise and create a broad spectrum). Offset: This is the offset in the data series from which point the data collection will begin. The default value is 0 which means that data collection will start on the most recent bar. If you set the Offset value to 100 then the window will be filled with data starting at 100 bars ago and working backwards in time from there. Upper Cycle Limit: Upper cycle period limit. Default is 110. This represents the highest Cycle Period value that you want displayed on the histogram. You can use this to filter the display output. Lower Cycle Limit: Lower cycle period limit. Default is 4. This represents the lowest Cycle Period value that you want displayed on the histogram. You can use this to filter the display output. Use MA?: Use an exponential moving average to fill the data window (instead of the actual price data). Select true or false. If true then a 3-period exponential MA of the data will be created and Window Size bars of this MA will be passed to the MESA function. If false, then the raw price data (H/L)/2 will be used. Cosmetics: The remaining menu options allow you to customize the colors and font sizes used to display the spectrum information. The [Off] button (it stands for Offset) allows you to change the bar at which the spectrum will be calculated. To use this feature simply hold down your SHIFT key, then click on the [Off] button (it will highlight after you click on it to let you know it is active) and then double-click your mouse at any bar offset in the indicator pane. The spectrum will recalculate based on this new location and display the results. Note: Hold down your SHIFT key and click on the info label (below the study title) for quick access to the study parameters. Note: You must hold down your SHIFT key while clicking on the [P++] and [P--] buttons. Disclaimer: For educational purposes only! Obviously, no guarantees whatsoever and use at your own risk. *******************************************************************************************************/