Indicators Used
0
Views
0
Downloads
0
Favorites
laguerre_plusdi_v1
//+--------------------------------------------------------------------------+
//| Laguerre_PlusDi.mq5 |
//| Copyright © 2005, Emerald King / transport_david |
//| http://finance.groups.yahoo.com/group/MetaTrader_Experts_and_Indicators/ |
//+--------------------------------------------------------------------------+
#property copyright "Copyright © 2007, Emerald King / transport_david"
#property link "http://finance.groups.yahoo.com/group/MetaTrader_Experts_and_Indicators/"
//--- indicator version
#property version "1.00"
//--- drawing the indicator in a separate window
#property indicator_separate_window
//--- one buffer is used for calculation and drawing of the indicator
#property indicator_buffers 1
//--- one plot is used
#property indicator_plots 1
//+----------------------------------------------+
//| Indicator drawing parameters |
//+----------------------------------------------+
//--- drawing the indicator as a line
#property indicator_type1 DRAW_LINE
//--- Teal color is used for the indicator line
#property indicator_color1 clrTeal
//--- Indicator line is a solid one
#property indicator_style1 STYLE_SOLID
//--- indicator line width is 2
#property indicator_width1 2
//+----------------------------------------------+
//| Parameters of displaying horizontal levels |
//+----------------------------------------------+
#property indicator_level2 0.75
#property indicator_level3 0.45
#property indicator_level4 0.15
//--- â êà÷åñòâå öâåòà ëèíèè ãîðèçîíòàëüíîãî óðîâíÿ èñïîëüçîâàí ðîçîâûé öâåò
#property indicator_levelcolor clrMagenta
//--- Short dot-dash is used for the horizontal level line
#property indicator_levelstyle STYLE_DASHDOTDOT
//+----------------------------------------------+
//| declaring constants |
//+----------------------------------------------+
#define RESET 0 // the constant for getting the command for the indicator recalculation back to the terminal
//+----------------------------------------------+
//| Indicator input parameters |
//+----------------------------------------------+
input uint ADXPeriod=14;
input double gamma=0.764;
//+----------------------------------------------+
//--- declaration of a dynamic array that
//--- will be used as an indicator buffer
double ExtLineBuffer[];
//--- declaration of integer variables of data starting point
int min_rates_total;
//--- declaration of integer variables for the indicators handles
int ADX_Handle;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- initialization of variables of the start of data calculation
min_rates_total=int(ADXPeriod);
//--- getting the handle of the iADX indicator
ADX_Handle=iADX(NULL,0,ADXPeriod);
if(ADX_Handle==INVALID_HANDLE)
{
Print(" Failed to get the handle of the iADX indicator");
return(INIT_FAILED);
}
//--- set ExtLineBuffer dynamic array as indicator buffer
SetIndexBuffer(0,ExtLineBuffer,INDICATOR_DATA);
//--- indexing elements in the buffer as in timeseries
ArraySetAsSeries(ExtLineBuffer,true);
//--- initializations of a variable for the indicator short name
string shortname;
StringConcatenate(shortname,"Laguerre_PlusDi(",ADXPeriod,", ",gamma,")");
//--- create a label to display in the Data Window
PlotIndexSetString(0,PLOT_LABEL,shortname);
//--- creation of the name to be displayed in a separate sub-window and in a pop up help
IndicatorSetString(INDICATOR_SHORTNAME,shortname);
//--- determining the accuracy of the indicator values
IndicatorSetInteger(INDICATOR_DIGITS,2);
//--- restriction to draw empty values for the indicator
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
//--- shifting the start of drawing of the indicator 1
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);
//--- initialization end
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total, // number of bars in history at the current tick
const int prev_calculated,// amount of history in bars at the previous tick
const datetime &time[],
const double &open[],
const double& high[], // price array of maximums of price for the calculation of indicator
const double& low[], // price array of price lows for the indicator calculation
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//--- checking if the number of bars is enough for the calculation
if(BarsCalculated(ADX_Handle)<rates_total || rates_total<min_rates_total) return(RESET);
//--- declarations of local variables
int to_copy,limit,bar;
double L0,L1,L2,L3,L0A,L1A,L2A,L3A,LDMIP=0,CU,CD,DMIP[];
//--- declarations of static variables for storing real values of coefficients
static double L0_,L1_,L2_,L3_,L0A_,L1A_,L2A_,L3A_;
//--- calculation of the starting number for the cycle of recalculation of bars
if(prev_calculated>rates_total || prev_calculated<=0) // checking for the first start of the indicator calculation
{
limit=rates_total-min_rates_total-1; // starting index for the calculation of all bars
//--- the starting initialization of calculated coefficients
L0_ = 0.0;
L1_ = 0.0;
L2_ = 0.0;
L3_ = 0.0;
L0A_ = 0.0;
L1A_ = 0.0;
L2A_ = 0.0;
L3A_ = 0.0;
}
else limit=rates_total-prev_calculated; // starting index for the calculation of new bars
to_copy=limit+1;
//--- copy newly appeared data in the arrays
if(CopyBuffer(ADX_Handle,PLUSDI_LINE,0,to_copy,DMIP)<=0) return(RESET);
//--- apply timeseries indexing to array elements
ArraySetAsSeries(DMIP,true);
//--- Restore values of the variables
L0 = L0_;
L1 = L1_;
L2 = L2_;
L3 = L3_;
L0A = L0A_;
L1A = L1A_;
L2A = L2A_;
L3A = L3A_;
//--- main calculation loop of the indicator
for(bar=limit; bar>=0 && !IsStopped(); bar--)
{
L0A = L0;
L1A = L1;
L2A = L2;
L3A = L3;
//---
L0 = (1 - gamma) * DMIP[bar] + gamma * L0A;
L1 = - gamma * L0 + L0A + gamma * L1A;
L2 = - gamma * L1 + L1A + gamma * L2A;
L3 = - gamma * L2 + L2A + gamma * L3A;
//---
CU = 0;
CD = 0;
//---
if(L0 >= L1) CU = L0 - L1; else CD = L1 - L0;
if(L1 >= L2) CU += L1 - L2; else CD += L2 - L1;
if(L2 >= L3) CU += L2 - L3; else CD += L3 - L2;
//---
if(CU+CD!=0) LDMIP=CU/(CU+CD);
//--- initialization of the cell of the indicator buffer by the obtained value of LRSI
ExtLineBuffer[bar]=LDMIP;
//--- save values of the variables before running at the current bar
if(bar==1)
{
L0_ = L0;
L1_ = L1;
L2_ = L2;
L3_ = L3;
L0A_ = L0A;
L1A_ = L1A;
L2A_ = L2A;
L3A_ = L3A;
}
}
//---
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
---