-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlligator.mq5
148 lines (147 loc) · 5.91 KB
/
Alligator.mq5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
//+------------------------------------------------------------------+
//| Alligator.mq5 |
//| Copyright 2009-2020, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2020, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_plots 3
#property indicator_type1 DRAW_LINE
#property indicator_type2 DRAW_LINE
#property indicator_type3 DRAW_LINE
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Lime
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 1
#property indicator_label1 "Jaws"
#property indicator_label2 "Teeth"
#property indicator_label3 "Lips"
//--- input parameters
input int InpJawsPeriod=13; // Jaws period
input int InpJawsShift=8; // Jaws shift
input int InpTeethPeriod=8; // Teeth period
input int InpTeethShift=5; // Teeth shift
input int InpLipsPeriod=5; // Lips period
input int InpLipsShift=3; // Lips shift
input ENUM_MA_METHOD InpMAMethod=MODE_SMMA; // Moving average method
input ENUM_APPLIED_PRICE InpAppliedPrice=PRICE_MEDIAN; // Applied price
//--- indicator buffers
double ExtJaws[];
double ExtTeeth[];
double ExtLips[];
//--- handles for moving averages
int ExtJawsHandle;
int ExtTeethHandle;
int ExtLipsHandle;
//--- bars minimum for calculation
int ExtBarsMinimum;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,ExtJaws,INDICATOR_DATA);
SetIndexBuffer(1,ExtTeeth,INDICATOR_DATA);
SetIndexBuffer(2,ExtLips,INDICATOR_DATA);
//--- set accuracy
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//--- sets first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpJawsPeriod-1);
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,InpTeethPeriod-1);
PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,InpLipsPeriod-1);
//--- line shifts when drawing
PlotIndexSetInteger(0,PLOT_SHIFT,InpJawsShift);
PlotIndexSetInteger(1,PLOT_SHIFT,InpTeethShift);
PlotIndexSetInteger(2,PLOT_SHIFT,InpLipsShift);
//--- name for DataWindow
PlotIndexSetString(0,PLOT_LABEL,"Jaws("+string(InpJawsPeriod)+")");
PlotIndexSetString(1,PLOT_LABEL,"Teeth("+string(InpTeethPeriod)+")");
PlotIndexSetString(2,PLOT_LABEL,"Lips("+string(InpLipsPeriod)+")");
//--- get MA's handles
ExtJawsHandle=iMA(NULL,0,InpJawsPeriod,0,InpMAMethod,InpAppliedPrice);
ExtTeethHandle=iMA(NULL,0,InpTeethPeriod,0,InpMAMethod,InpAppliedPrice);
ExtLipsHandle=iMA(NULL,0,InpLipsPeriod,0,InpMAMethod,InpAppliedPrice);
//--- bars minimum for calculation
ExtBarsMinimum=InpJawsPeriod+InpJawsShift;
if(ExtBarsMinimum<(InpTeethPeriod+InpTeethShift))
ExtBarsMinimum=InpTeethPeriod+InpTeethShift;
if(ExtBarsMinimum<(InpLipsPeriod+InpLipsPeriod))
ExtBarsMinimum=InpLipsPeriod+InpLipsPeriod;
}
//+------------------------------------------------------------------+
//| Alligator OnCalculate 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[])
{
if(rates_total<ExtBarsMinimum)
return(0);
//--- not all data may be calculated
int calculated=BarsCalculated(ExtJawsHandle);
if(calculated<rates_total)
{
Print("Not all data of ExtJawsHandle is calculated (",calculated," bars). Error ",GetLastError());
return(0);
}
calculated=BarsCalculated(ExtTeethHandle);
if(calculated<rates_total)
{
Print("Not all data of ExtTeethHandle is calculated (",calculated," bars). Error ",GetLastError());
return(0);
}
calculated=BarsCalculated(ExtLipsHandle);
if(calculated<rates_total)
{
Print("Not all data of ExtLipsHandle is calculated (",calculated," bars). Error ",GetLastError());
return(0);
}
//--- we can copy not all data
int to_copy;
if(prev_calculated>rates_total || prev_calculated<0)
to_copy=rates_total;
else
{
to_copy=rates_total-prev_calculated;
if(prev_calculated>0)
to_copy++;
}
//--- get ma buffers
if(IsStopped()) // checking for stop flag
return(0);
if(CopyBuffer(ExtJawsHandle,0,0,to_copy,ExtJaws)<=0)
{
Print("getting ExtJawsHandle is failed! Error ",GetLastError());
return(0);
}
if(IsStopped()) // checking for stop flag
return(0);
if(CopyBuffer(ExtTeethHandle,0,0,to_copy,ExtTeeth)<=0)
{
Print("getting ExtTeethHandle is failed! Error ",GetLastError());
return(0);
}
if(IsStopped()) // checking for stop flag
return(0);
if(CopyBuffer(ExtLipsHandle,0,0,to_copy,ExtLips)<=0)
{
Print("getting ExtLipsHandle is failed! Error ",GetLastError());
return(0);
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+