2
Views
0
Downloads
0
Favorites
Modified_Optimum_Elliptic_Filter
//+------------------------------------------------------------------+
//| Modified_Optimum_Elliptic_Filter.mq5 |
//| |
//| Modified Optimum Elliptic Filter |
//| |
//| Algorithm taken from book |
//| "Cybernetics Analysis for Stock and Futures" |
//| by John F. Ehlers |
//| |
//| contact@mqlsoft.com |
//| http://www.mqlsoft.com/ |
//+------------------------------------------------------------------+
//---- author of the indicator
#property copyright "Coded by Witold Wozniak"
//---- link to the website of the author
#property link "www.mqlsoft.com"
//---- indicator version
#property version "1.00"
//---- drawing the indicator in the main window
#property indicator_chart_window
//---- one buffer is used for calculation and drawing the indicator
#property indicator_buffers 1
//---- only one plot is used
#property indicator_plots 1
//+----------------------------------------------+
//| Indicator drawing parameters |
//+----------------------------------------------+
//---- drawing the indicator as a line
#property indicator_type1 DRAW_LINE
//---- magenta color is used for the indicator line
#property indicator_color1 Magenta
//---- the indicator line is a continuous curve
#property indicator_style1 STYLE_SOLID
//---- Indicator line width is equal to 2
#property indicator_width1 2
//---- displaying the indicator label
#property indicator_label1 "Modified Optimum Elliptic Filter"
//+----------------------------------------------+
//| Indicator input parameters |
//+----------------------------------------------+
input int Shift=0; // Horizontal shift of the indicator in bars
//+----------------------------------------------+
//---- declaration of a dynamic array that
//---- will be used as an indicator buffer
double ExtLineBuffer[];
//---- declaration of the integer variables for the start of data calculation
int min_rates_total;
//---- declaration of global variables
double coef1,coef2,coef3,coef4;
//+------------------------------------------------------------------+
//| Getting the average from the price time series |
//+------------------------------------------------------------------+
double Get_Price(const double &High[],const double &Low[],int bar)
{
//----
return((High[bar]+Low[bar])/2);
}
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//---- initialization of variables of the start of data calculation
min_rates_total=4;
//---- set ExtLineBuffer dynamic array as an indicator buffer
SetIndexBuffer(0,ExtLineBuffer,INDICATOR_DATA);
//---- shifting horizontally by Shift
PlotIndexSetInteger(0,PLOT_SHIFT,Shift);
//---- performing the shift of the beginning of the indicator drawing
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);
//---- initializations of a variable for the indicator short name
string shortname;
StringConcatenate(shortname,"Modified Optimum Elliptic Filter(",Shift,")");
//---- creating a name for displaying in a separate sub-window and in a tooltip
IndicatorSetString(INDICATOR_SHORTNAME,shortname);
//---- determination of accuracy of displaying the indicator values
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
//----
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total, // number of bars in history at the current tick
const int prev_calculated,// number of bars calculated at previous call
const datetime &time[],
const double &open[],
const double& high[], // price array of maximums of price for the indicator calculation
const double& low[], // price array of minimums of price for the indicator calculation
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//---- checking the number of bars to be enough for the calculation
if(rates_total<min_rates_total) return(0);
//---- declarations of local variables
int first,bar;
//---- calculation of the 'first' starting index for the bars recalculation loop
if(prev_calculated>rates_total || prev_calculated<=0) // checking for the first start of the indicator calculation
first=0; // starting index for calculation of all bars
else first=prev_calculated-1; // starting index for calculation of new bars
//---- main indicator calculation loop
for(bar=first; bar<rates_total; bar++)
{
//---- formula for the filter calculation
if(bar>min_rates_total) ExtLineBuffer[bar]=
0.13785*(2*Get_Price(high,low,bar)-Get_Price(high,low,bar-1))
+0.0007*(2*Get_Price(high,low,bar-1)-Get_Price(high,low,bar-2))
+ 0.13785*(2*Get_Price(high,low,bar-2) - Get_Price(high,low,bar-3))
+ 1.2103 *ExtLineBuffer[bar-1] - 0.4867*ExtLineBuffer[bar-2];
else ExtLineBuffer[bar]=Get_Price(high,low,bar);
}
//----
return(rates_total);
}
//+------------------------------------------------------------------+
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---