-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathcurrency.mq4
162 lines (140 loc) · 3.53 KB
/
currency.mq4
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
156
157
158
159
160
161
162
// Forex currency template v1.2
#property copyright ""
#property link ""
#property version "1.0"
#property strict
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Green
#property indicator_level1 0
#property indicator_levelcolor Red
#property indicator_levelwidth 2
#property indicator_levelstyle STYLE_DOT
extern int Length = 20;
enum CurrencyPairs
{
USD = 1,
EUR = 2,
GBP = 3,
JPY = 4,
CHF = 5,
AUD = 6,
NZD = 7,
CAD = 8,
ANY = 9
};
string Default[] = { "USD", "EUR", "GBP","JPY", "CHF", "AUD", "NZD", "CAD", "Any" };
string currencies[] =
{
//majors
"AUD", "CAD", "CHF", "EUR", "GBP", "JPY", "NZD", "USD",
// minors
"AED", "BHD", "BRL", "CNY", "CYP", "CZK", "DKK", "DZD", "EEK", "EGP", "HKD", "HRK", "HUF", "IDR", "ILS", "INR", "IQD", "IRR", "ISK", "JOD",
"KRW", "KWD", "LBP", "LTL", "LVL", "LYD", "MAD", "MXN", "MYR", "NOK", "OMR", "PHP", "PLN", "QAR", "RON", "RUB", "SAR", "SEK", "SGD", "SKK",
"SYP", "THB", "TND", "TRY", "TWD", "VEB", "XAG", "XAU", "YER", "ZAR"
};
#define majorsCount 8
input CurrencyPairs Selected = USD; // Currency
input bool UseMajorsOnly = true; // Use majors only
double Line[];
class SymbolData
{
public:
string Symbol;
int Side;
};
SymbolData* Symbols[];
string IndicatorObjPrefix;
bool NamesCollision(const string name)
{
for (int k = ObjectsTotal(); k >= 0; k--)
{
if (StringFind(ObjectName(0, k), name) == 0)
{
return true;
}
}
return false;
}
string GenerateIndicatorPrefix(const string target)
{
for (int i = 0; i < 1000; ++i)
{
string prefix = target + "_" + IntegerToString(i);
if (!NamesCollision(prefix))
{
return prefix;
}
}
return target;
}
int init()
{
IndicatorObjPrefix = GenerateIndicatorPrefix("...");
IndicatorShortName("...");
IndicatorBuffers(1);
IndicatorDigits(Digits);
SetIndexStyle(0, DRAW_LINE);
SetIndexBuffer(0, Line);
CreateSymbolList();
return(0);
}
int deinit()
{
for (int i = 0; i < ArraySize(Symbols); ++i)
{
delete Symbols[i];
}
ArrayResize(Symbols, 0);
ObjectsDeleteAll(ChartID(), IndicatorObjPrefix);
return(0);
}
int start()
{
if (Bars <= 1)
return 0;
int ExtCountedBars = IndicatorCounted();
if (ExtCountedBars < 0)
return -1;
int limit = Bars - 2;
if (ExtCountedBars > 1)
limit = Bars - ExtCountedBars;
int pos = limit;
while (pos >= 0)
{
double value = 0;
for (int index = 0; index < ArraySize(Symbols); index++)
{
SymbolData* symbolData = Symbols[index];
}
Line[pos] = value;
pos--;
}
return(0);
}
void CreateSymbolList()
{
int currencyCount = UseMajorsOnly ? majorsCount : ArrayRange(currencies, 0);
int symbolCount = 0;
for (int i = 0; i < currencyCount; i++)
{
for (int ii = 0; ii < currencyCount; ii++)
{
if (currencies[i] == Default[Selected - 1]
|| currencies[ii] == Default[Selected - 1]
|| Default[Selected - 1] == "Any")
{
string symbol = currencies[i] + currencies[ii];
if (MarketInfo(symbol, MODE_BID) > 0)
{
ArrayResize(Symbols, symbolCount + 1);
Symbols[symbolCount] = new SymbolData();
Symbols[symbolCount].Symbol = symbol;
Symbols[symbolCount].Side = currencies[i] == Default[Selected - 1] ? 1 : -1;
symbolCount++;
}
}
}
}
return;
}