Price Data Components
Miscellaneous
0
Views
0
Downloads
0
Favorites
_MK_LaguerreMultiPeriodV2
//+------------------------------------------------------------------+
//| MK_LaguerreMultiPeriodV2.mq4 |
//| Copyright 2016, Mikhail <Sepulca> Kozhemyako |
//| ua3xcm@obninsk.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, Mikhail <Sepulca> Kozhemyako"
#property link "ua3xcm@obninsk.ru"
#property version "2.00"
#property strict
#define drawLaguerre DRAW_LINE
#define clrM1 clrCoral
#define clrM5 clrMediumBlue
#define clrM15 clrDarkOrchid
#define clrM30 clrTurquoise
#define clrH1 clrViolet
#define clrH4 clrDeepPink
#define clrD1 clrYellow
#define clrW1 clrGreen
#define clrMN1 clrRed
#property indicator_separate_window
#property indicator_buffers 9
#property indicator_minimum -0.3
#property indicator_maximum 1.15
//---- input parameters
input double gamma=0.66;
input ENUM_TIMEFRAMES OldestTF=PERIOD_D1;
//
int usedTF[9],oldbar[9];
double L0[9],L1[9],L2[9],L3[9],L0A[9],L1A[9],L2A[9],L3A[9];
double LaguerreM1[];
double LaguerreM5[];
double LaguerreM15[];
double LaguerreM30[];
double LaguerreH1[];
double LaguerreH4[];
double LaguerreD1[];
double LaguerreW1[];
double LaguerreMN1[];
string shortname=StringConcatenate("LaguerreMulti(",DoubleToString(gamma,3),")");
//| Custom indicator initialization function |
int OnInit()
{
int width=1,InpX=0,InpY=0,oldesttf;
IndicatorShortName(shortname);
IndicatorSetInteger(INDICATOR_LEVELS,9);IndicatorSetDouble(INDICATOR_LEVELVALUE,1,0);IndicatorSetDouble(INDICATOR_LEVELVALUE,2,1);
ArrayFill(usedTF,0,9,0);ArrayFill(L0,0,9,0);ArrayFill(L1,0,9,0);ArrayFill(L2,0,9,0);ArrayFill(L3,0,9,0);
if(OldestTF<=PERIOD_CURRENT)oldesttf=Period();else oldesttf=OldestTF;
if(oldesttf>=PERIOD_M1 && Period()<=PERIOD_M1)
{
LabelCreate(0,shortname+"M1",ChartWindowFind(),InpX,InpY,CORNER_LEFT_LOWER,"M1","Arial",20,clrM1,0,ANCHOR_LEFT_LOWER,false,false,true,0);
usedTF[8]=PERIOD_M1;
SetIndexBuffer(8,LaguerreM1);
SetIndexArrow(8,108);
SetIndexStyle(8,drawLaguerre,EMPTY,width,clrM1);
SetIndexLabel(8,"M1 Laguerre");
width+=2;InpX+=60;
}
else SetIndexLabel(8,"M1 Not Used");
if(oldesttf>=PERIOD_M5 && Period()<=PERIOD_M5)
{
LabelCreate(0,shortname+"M5",ChartWindowFind(),InpX,InpY,CORNER_LEFT_LOWER,"M5","Arial",20,clrM5,0,ANCHOR_LEFT_LOWER,false,false,true,0);
usedTF[7]=PERIOD_M5;
SetIndexBuffer(7,LaguerreM5);
SetIndexStyle(7,drawLaguerre,EMPTY,width,clrM5);
SetIndexLabel(7,"M5 Laguerre");
width+=2;InpX+=60;
}
else SetIndexLabel(7,"M5 Not Used");
if(oldesttf>=PERIOD_M15 && Period()<=PERIOD_M15)
{
LabelCreate(0,shortname+"M15",ChartWindowFind(),InpX,InpY,CORNER_LEFT_LOWER,"M15","Arial",20,clrM15,0,ANCHOR_LEFT_LOWER,false,false,true,0);
usedTF[6]=PERIOD_M15;
SetIndexBuffer(6,LaguerreM15);
SetIndexStyle(6,drawLaguerre,EMPTY,width,clrM15);
SetIndexLabel(6,"M15 Laguerre");
width+=2;InpX+=60;
}
else SetIndexLabel(6,"M15 Not Used");
if(oldesttf>=PERIOD_M30 && Period()<=PERIOD_M30)
{
LabelCreate(0,shortname+"M30",ChartWindowFind(),InpX,InpY,CORNER_LEFT_LOWER,"M30","Arial",20,clrM30,0,ANCHOR_LEFT_LOWER,false,false,true,0);
usedTF[5]=PERIOD_M30;
SetIndexBuffer(5,LaguerreM30);
SetIndexStyle(5,drawLaguerre,EMPTY,width,clrM30);
SetIndexLabel(5,"M30 Laguerre");
width+=2;InpX+=60;
}
else SetIndexLabel(5,"M30 Not Used");
if(oldesttf>=PERIOD_H1 && Period()<=PERIOD_H1)
{
LabelCreate(0,shortname+"H1",ChartWindowFind(),InpX,InpY,CORNER_LEFT_LOWER,"H1","Arial",20,clrH1,0,ANCHOR_LEFT_LOWER,false,false,true,0);
usedTF[4]=PERIOD_H1;
SetIndexBuffer(4,LaguerreH1);
SetIndexStyle(4,drawLaguerre,EMPTY,width,clrH1);
SetIndexLabel(4,"H1 Laguerre");
width+=2;InpX+=60;
}
else SetIndexLabel(4,"H1 Not Used");
if(oldesttf>=PERIOD_H4 && Period()<=PERIOD_H4)
{
LabelCreate(0,shortname+"H4",ChartWindowFind(),InpX,InpY,CORNER_LEFT_LOWER,"H4","Arial",20,clrH4,0,ANCHOR_LEFT_LOWER,false,false,true,0);
usedTF[3]=PERIOD_H4;
SetIndexBuffer(3,LaguerreH4);
SetIndexStyle(3,drawLaguerre,EMPTY,width,clrH4);
SetIndexLabel(3,"H4 Laguerre");
width+=2;InpX+=60;
}
else SetIndexLabel(3,"H4 Not Used");
if(oldesttf>=PERIOD_D1 && Period()<=PERIOD_D1)
{
LabelCreate(0,shortname+"D1",ChartWindowFind(),InpX,InpY,CORNER_LEFT_LOWER,"D1","Arial",20,clrD1,0,ANCHOR_LEFT_LOWER,false,false,true,0);
usedTF[2]=PERIOD_D1;
SetIndexBuffer(2,LaguerreD1);
SetIndexStyle(2,drawLaguerre,EMPTY,width,clrD1);
SetIndexLabel(2,"D1 Laguerre");
width+=4;InpX+=60;
}
else SetIndexLabel(2,"D1 Not Used");
if(oldesttf>=PERIOD_W1 && Period()<=PERIOD_W1)
{
LabelCreate(0,shortname+"W1",ChartWindowFind(),InpX,InpY,CORNER_LEFT_LOWER,"W1","Arial",20,clrW1,0,ANCHOR_LEFT_LOWER,false,false,true,0);
usedTF[1]=PERIOD_W1;
SetIndexBuffer(1,LaguerreW1);
SetIndexStyle(1,drawLaguerre,EMPTY,width,clrW1);
SetIndexLabel(1,"W1 Laguerre");
width+=4;InpX+=60;
}
else SetIndexLabel(1,"W1 Not Used");
if(oldesttf>=PERIOD_MN1 && Period()<=PERIOD_MN1)
{
LabelCreate(0,shortname+"MN1",ChartWindowFind(),InpX,InpY,CORNER_LEFT_LOWER,"MN1","Arial",20,clrMN1,0,ANCHOR_LEFT_LOWER,false,false,true,0);
usedTF[0]=PERIOD_MN1;
SetIndexBuffer(0,LaguerreMN1);
SetIndexStyle(0,drawLaguerre,EMPTY,width,clrMN1);
SetIndexLabel(0,"MN1 Laguerre");
}
else SetIndexLabel(0,"MN1 Not Used");
IndicatorDigits(Digits());
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason)
{
ObjectDelete(shortname+"M1");ObjectDelete(shortname+"M15");ObjectDelete(shortname+"M30");
ObjectDelete(shortname+"H1");ObjectDelete(shortname+"H4");ObjectDelete(shortname+"D1");
ObjectDelete(shortname+"W1");ObjectDelete(shortname+"MN1");ObjectDelete(shortname+"M5");
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total, // êîëè÷åñòâî áàðîâ, äîñòóïíûõ èíäèêàòîðó äëÿ ðàñ÷åòà
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
double LRSI=0,CU=0,CD=0;
int i,limit,k,bar;
//--- last counted bar will be recounted
limit=rates_total-prev_calculated;
if(prev_calculated>0) limit++;
for(k=0;k<9;k++)
{
if(usedTF[k]==0)continue;
for(i=limit-1; i>=0; i--)
{
if(oldbar[k]<iBars(NULL,usedTF[k]) || prev_calculated==0)
{
oldbar[k]=iBars(NULL,usedTF[k]);
L0A[k] = L0[k];
L1A[k] = L1[k];
L2A[k] = L2[k];
L3A[k] = L3[k];
}
bar=iBarShift(NULL,usedTF[k],iTime(NULL,Period(),i));
L0[k] = (1 - gamma)*iClose(NULL,usedTF[k],bar) + gamma*L0A[k];//Close[i]
L1[k] = - gamma *L0[k] + L0A[k] + gamma *L1A[k];
L2[k] = - gamma *L1[k] + L1A[k] + gamma *L2A[k];
L3[k] = - gamma *L2[k] + L2A[k] + gamma *L3A[k];
CU = 0;
CD = 0;
if (L0[k] >= L1[k]) CU = L0[k] - L1[k]; else CD = L1[k] - L0[k];
if (L1[k] >= L2[k]) CU = CU + L1[k] - L2[k]; else CD = CD + L2[k] - L1[k];
if (L2[k] >= L3[k]) CU = CU + L2[k] - L3[k]; else CD = CD + L3[k] - L2[k];
if (CU + CD != 0) LRSI = CU / (CU + CD);
switch(k)
{
case 8: LaguerreM1[i]=LRSI;break;
case 7: LaguerreM5[i]=LRSI;break;
case 6: LaguerreM15[i]=LRSI;break;
case 5: LaguerreM30[i]=LRSI;break;
case 4: LaguerreH1[i]=LRSI;break;
case 3: LaguerreH4[i]=LRSI;break;
case 2: LaguerreD1[i]=LRSI;break;
case 1: LaguerreW1[i]=LRSI;break;
case 0: LaguerreMN1[i]=LRSI;break;
default:break;
}
}
}
return(rates_total);
}
//+------------------------------------------------------------------+
//| Ñîçäàåò òåêñòîâóþ ìåòêó |
//+------------------------------------------------------------------+
bool LabelCreate(const long chart_ID=0, // ID ãðàôèêà
const string name="Label", // èìÿ ìåòêè
const int sub_window=0, // íîìåð ïîäîêíà
const int x=0, // êîîðäèíàòà ïî îñè X
const int y=0, // êîîðäèíàòà ïî îñè Y
const ENUM_BASE_CORNER corner=CORNER_LEFT_UPPER, // óãîë ãðàôèêà äëÿ ïðèâÿçêè
const string text="Label", // òåêñò
const string font="Arial", // øðèôò
const int font_size=10, // ðàçìåð øðèôòà
const color clr=clrRed, // öâåò
const double angle=0.0, // íàêëîí òåêñòà
const ENUM_ANCHOR_POINT anchor=ANCHOR_LEFT_UPPER, // ñïîñîá ïðèâÿçêè
const bool back=false, // íà çàäíåì ïëàíå
const bool selection=false, // âûäåëèòü äëÿ ïåðåìåùåíèé
const bool hidden=true, // ñêðûò â ñïèñêå îáúåêòîâ
const long z_order=0) // ïðèîðèòåò íà íàæàòèå ìûøüþ
{
//--- ñáðîñèì çíà÷åíèå îøèáêè
ResetLastError();
//--- ñîçäàäèì òåêñòîâóþ ìåòêó
if(!ObjectCreate(chart_ID,name,OBJ_LABEL,sub_window,0,0))
{
Print(__FUNCTION__,
": íå óäàëîñü ñîçäàòü òåêñòîâóþ ìåòêó! Êîä îøèáêè = ",GetLastError());
return(false);
}
//--- óñòàíîâèì êîîðäèíàòû ìåòêè
ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);
ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);
//--- óñòàíîâèì óãîë ãðàôèêà, îòíîñèòåëüíî êîòîðîãî áóäóò îïðåäåëÿòüñÿ êîîðäèíàòû òî÷êè
ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner);
//--- óñòàíîâèì òåêñò
ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);
//--- óñòàíîâèì øðèôò òåêñòà
ObjectSetString(chart_ID,name,OBJPROP_FONT,font);
//--- óñòàíîâèì ðàçìåð øðèôòà
ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);
//--- óñòàíîâèì óãîë íàêëîíà òåêñòà
ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle);
//--- óñòàíîâèì ñïîñîá ïðèâÿçêè
ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor);
//--- óñòàíîâèì öâåò
ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
//--- îòîáðàçèì íà ïåðåäíåì (false) èëè çàäíåì (true) ïëàíå
ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
//--- âêëþ÷èì (true) èëè îòêëþ÷èì (false) ðåæèì ïåðåìåùåíèÿ ìåòêè ìûøüþ
ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
//--- ñêðîåì (true) èëè îòîáðàçèì (false) èìÿ ãðàôè÷åñêîãî îáúåêòà â ñïèñêå îáúåêòîâ
ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
//--- óñòàíîâèì ïðèîðèòåò íà ïîëó÷åíèå ñîáûòèÿ íàæàòèÿ ìûøè íà ãðàôèêå
ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
//--- óñïåøíîå âûïîëíåíèå
return(true);
}
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
---