-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathCCI Arrows.mq5
155 lines (130 loc) · 5.49 KB
/
CCI Arrows.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
149
150
151
152
153
154
155
//+------------------------------------------------------------------+
//| CCI Arrows |
//| Copyright © 2009-2022, EarnForex |
//| https://www.earnforex.com/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009-2022, EarnForex"
#property link "https://www.earnforex.com/metatrader-indicators/CCI-Arrows/"
#property version "1.02"
#property description "CCI arrows based on the cross of the zero line from below or from above."
#property description "Displays red and blue arrows for Short and Long signals."
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots 2
#property indicator_color1 clrBlue
#property indicator_type1 DRAW_ARROW
#property indicator_width1 2
#property indicator_color2 clrRed
#property indicator_type2 DRAW_ARROW
#property indicator_width2 2
enum enum_candle_to_check
{
Current,
Previous
};
input int CCI_Period = 14; // CCI Period
input bool EnableNativeAlerts = false;
input bool EnableEmailAlerts = false;
input bool EnablePushAlerts = false;
input enum_candle_to_check TriggerCandle = Previous;
double dUpCCIBuffer[];
double dDownCCIBuffer[];
int myCCI;
int LastAlertDirection;
datetime LastAlertTime;
bool FirstRun;
void OnInit()
{
FirstRun = true;
LastAlertDirection = 0;
LastAlertTime = D'01.01.1970';
IndicatorSetString(INDICATOR_SHORTNAME, "CCI Arrows (" + IntegerToString(CCI_Period) + ")");
SetIndexBuffer(0, dUpCCIBuffer, INDICATOR_DATA);
SetIndexBuffer(1, dDownCCIBuffer, INDICATOR_DATA);
ArraySetAsSeries(dUpCCIBuffer, true);
ArraySetAsSeries(dDownCCIBuffer, true);
PlotIndexSetInteger(0, PLOT_ARROW, 233);
PlotIndexSetInteger(1, PLOT_ARROW, 234);
PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, 0.0);
PlotIndexSetDouble(1, PLOT_EMPTY_VALUE, 0.0);
PlotIndexSetString(0, PLOT_LABEL, "CCI Buy");
PlotIndexSetString(1, PLOT_LABEL, "CCI Sell");
myCCI = iCCI(NULL, 0, CCI_Period, PRICE_CLOSE);
}
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[])
{
ArraySetAsSeries(High, true);
ArraySetAsSeries(Low, true);
ArraySetAsSeries(Time, true);
int counted_bars = prev_calculated;
if (counted_bars > 0) counted_bars--;
int limit = rates_total - 1 - counted_bars;
double CCIBuffer[];
CopyBuffer(myCCI, 0, 0, rates_total, CCIBuffer);
ArraySetAsSeries(CCIBuffer, true);
if (limit == 1) limit++; // Always redraw latest two bars.
for (int i = 0; i < limit; i++)
{
dUpCCIBuffer[i] = 0;
dDownCCIBuffer[i] = 0;
double myCCInow = CCIBuffer[i];
double myCCI2 = CCIBuffer[i + 1]; // CCI one bar ago.
if (myCCInow >= 0) // Is above zero.
{
if((myCCInow > 0) && (myCCI2 < 0)) // Did it cross from below 0?
{
double distance = (High[iHighest(Symbol(), Period(), MODE_HIGH, 20, i)] - Low[iLowest(Symbol(), Period(), MODE_LOW, 20, i)]) * 0.02;
dUpCCIBuffer[i] = Low[i] - 2 * distance;
}
}
if (myCCInow < 0) // Is below zero.
{
if((myCCInow < 0) && (myCCI2 > 0)) // Did it cross from above 0?
{
double distance = (High[iHighest(Symbol(), Period(), MODE_HIGH, 20, i)] - Low[iLowest(Symbol(), Period(), MODE_LOW, 20, i)]) * 0.02;
dDownCCIBuffer[i] = High[i] + 2 * distance;
}
}
}
if ((!FirstRun) && ((EnableNativeAlerts) || (EnableEmailAlerts) || (EnablePushAlerts)))
{
if (((TriggerCandle > 0) && (Time[0] > LastAlertTime)) || (TriggerCandle == 0))
{
string Text;
// Up arrow alert.
if ((dUpCCIBuffer[TriggerCandle] != 0) && (LastAlertDirection != 1))
{
Text = "Up Arrow";
if (EnableNativeAlerts) Alert(Text);
Text = "CCI Arrows: " + Symbol() + " - " + StringSubstr(EnumToString((ENUM_TIMEFRAMES)Period()), 7) + " - " + Text + ".";
if (EnableEmailAlerts) SendMail("CCI Arrows Alert", Text);
if (EnablePushAlerts) SendNotification(Text);
LastAlertTime = Time[0];
LastAlertDirection = 1;
}
// Down arrow alert.
if ((dDownCCIBuffer[TriggerCandle] != 0) && (LastAlertDirection != -1))
{
Text = "Down Arrow";
if (EnableNativeAlerts) Alert(Text);
Text = "CCI Arrows: " + Symbol() + " - " + StringSubstr(EnumToString((ENUM_TIMEFRAMES)Period()), 7) + " - " + Text + ".";
if (EnableEmailAlerts) SendMail("CCI Arrows Alert", Text);
if (EnablePushAlerts) SendNotification(Text);
LastAlertTime = Time[0];
LastAlertDirection = -1;
}
}
}
FirstRun = false;
return rates_total;
}
//+------------------------------------------------------------------+