MT4 Files

Check-in [47b6dcdf38]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Imported my .mq4 files
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:47b6dcdf3859c0b088ebab1a331847c0a59d05af
User & Date: onagano 2010-11-22 08:56:19
Context
2010-12-13
07:23
Added dll related files check-in: 4b1266837b user: onagano tags: trunk
2010-11-22
08:56
Imported my .mq4 files check-in: 47b6dcdf38 user: onagano tags: trunk
02:45
Added samples directory check-in: 285f35bddd user: onagano tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added experts/busy_option.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
//+------------------------------------------------------------------+
//|                                                  busy_option.mq4 |
//|                                                   Othello Nagano |
//|                   http://www.google.com/profiles/onagano.g#about |
//+------------------------------------------------------------------+
#property copyright "Othello Nagano"
#property link      "http://www.google.com/profiles/onagano.g#about"

//---- input parameters
extern int        ExtSlippage = 3;
extern int       ExtStopLevel = 20;
extern double ExtPositionSize = 0.1;
extern int        ExtMAPeriod = 13;
extern int        ExtStopLoss = 295;
extern int    ExtTrailingStep = 305;
extern int      ExtTakeProfit = 0;
//---- global variables
int    TrTicket      = -1;
double TrPosition    = 0.0;
double TrOpenPrice   = 0.0;
double TrStopLoss    = 0.0;
double TrTakeProfit  = 0.0;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   //MarketInfo(Symbol(), MODE_STOPLEVEL)
   //MarketInfo(Symbol(), MODE_SPREAD)
   //MarketInfo(Symbol(), MODE_FREEZELEVEL)
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   //Print("Total points earned: ", TrTotalPoints);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   if (Bars > 2 * ExtMAPeriod) eatTick();
//----
   return(0);
  }
//+------------------------------------------------------------------+

void eatTick() {
   updatePosition();
   if (TrPosition != 0.0) {
      // to close the trade
      double price = GetExitPrice(TrPosition);
      double closePrice = shouldCloseTrade(price);
      if (closePrice > 0.0) {
         closeTrade(closePrice);
      } else {
         // to update the trade
         double newClose = shouldUpdateTrade(price);
         if (newClose > 0.0) {
            updateTrade(newClose);
         }
      }
   } else {
      // to open a trade
      double position = shouldOpenTrade();
      if (position != 0.0) {
         openTrade(GetEntryPrice(position), position);
      }
   }
}

//+------------------------------------------------------------------+

void updatePosition() {
   TrPosition = getPosition(TrTicket);
   if (TrPosition == 0.0) TrTicket = -1;
}

double shouldOpenTrade() {
   double position = 0.0;
   // Use open prices to ignore recent ticks
   double prev = iMACD(NULL, 0, ExtMAPeriod, 2 * ExtMAPeriod, ExtMAPeriod,
                       PRICE_OPEN, MODE_SIGNAL, 1);
   double next = iMACD(NULL, 0, ExtMAPeriod, 2 * ExtMAPeriod, ExtMAPeriod,
                       PRICE_OPEN, MODE_SIGNAL, 0);
   if (prev <= 0.0 && 0.0 < next) position =  1.0;
   if (prev >= 0.0 && 0.0 > next) position = -1.0;   
   return(position);
}

void openTrade(double price, double position) {
   double stopLoss = CalcStopLoss(price, position, ExtStopLoss);
   double takeProfit = CalcTakeProfit(price, position, ExtTakeProfit);
   TrTicket = sendOrder(price, position, stopLoss, takeProfit);
   if (TrTicket > -1) {
      TrPosition = position;
      TrOpenPrice = price;
      TrStopLoss = stopLoss;
      TrTakeProfit = takeProfit;
   }
}

double shouldCloseTrade(double price) {
   double closePrice = 0.0; // zero or less means no.
   if (TrStopLoss > 0.0) {
      if ((TrPosition > 0.0 && TrStopLoss >= price)
       || (TrPosition < 0.0 && price >= TrStopLoss))
          closePrice = TrStopLoss;
   }
   if (TrTakeProfit > 0.0) {
      if ((TrPosition > 0.0 && price >= TrTakeProfit)
       || (TrPosition < 0.0 && TrTakeProfit >= price))
         closePrice = TrTakeProfit;
   }
   return(closePrice);
}

void closeTrade(double price) {
   if (closeOrder(TrTicket, price, TrPosition)) {
      TrTicket = -1;
      TrPosition = 0.0;
   }
}

double shouldUpdateTrade(double price) {
   double closePrice = 0.0; // zero or less means no.
   if (ExtTakeProfit > 0) { // eliminate down side risk
      if (CalcProfit(price, TrOpenPrice, TrPosition) >= ExtStopLevel) {
         if ((TrPosition > 0.0 && TrOpenPrice > TrStopLoss)
          || (TrPosition < 0.0 && TrStopLoss > TrOpenPrice))
            closePrice = TrOpenPrice;
      }
   } else { // close by trailing stop
      if (MathAbs(price - TrStopLoss) > (ExtStopLoss + ExtTrailingStep) * Point) {
         closePrice = CalcStopLoss(price, TrPosition, ExtStopLoss);
      }
   }
   return(closePrice);
}

void updateTrade(double closePrice) {
   if (modifyOrder(TrTicket, TrOpenPrice, closePrice, TrTakeProfit)) {
      TrStopLoss = closePrice;
   }
}

//+------------------------------------------------------------------+

double CalcStopLoss(double price, double position, int points) {
   if (points <= 0) return(0.0);
   double stopLoss = price;
   if (position > 0.0) stopLoss = price - points * Point;
   if (position < 0.0) stopLoss = price + points * Point;
   stopLoss = NormalizeDouble(stopLoss, Digits);
   return(stopLoss);
}

double CalcTakeProfit(double price, double position, int points) {
   if (points <= 0) return(0.0);
   double takeProfit = price;
   if (position > 0.0) takeProfit = price + points * Point;
   if (position < 0.0) takeProfit = price - points * Point;
   takeProfit = NormalizeDouble(takeProfit, Digits);
   return(takeProfit);
}

int CalcProfit(double price, double openPrice, double position) {
   int profit = 0;
   double dProfit = 0.0;
   if (position > 0.0) dProfit = price - openPrice;
   if (position < 0.0) dProfit = openPrice - price;
   profit = NormalizeDouble(dProfit, Digits) / Point;
   return(profit);
}

double GetEntryPrice(double position) {
   RefreshRates();
   if (position > 0.0) return(Ask);
   if (position < 0.0) return(Bid);
   return(NormalizeDouble((Ask + Bid) / 2, Digits));
}

double GetExitPrice(double position) {
   RefreshRates();
   if (position > 0.0) return(Bid);
   if (position < 0.0) return(Ask);
   return(NormalizeDouble((Ask + Bid) / 2, Digits));
}

//+------------------------------------------------------------------+

int sendOrder(double price, double position, double stopLoss, double takeProfit) {
   int ticket = -1;
   int operation = 0;
   if (position > 0.0) operation = OP_BUY;
   if (position < 0.0) operation = OP_SELL;
   double lots = MathAbs(position);
   int slippage = ExtSlippage;
   ticket = OrderSend(Symbol(), operation, lots, price, slippage,
                        stopLoss, takeProfit);
   if (ticket < 0) {
      Print("OrderSend failed with error #", GetLastError());
   }
   return(ticket);
}

bool closeOrder(int ticket, double price, double position) {
   bool closed = false;
   if (ticket > -1) {
      double lots = MathAbs(position);
      int slippage = ExtSlippage;
      closed = OrderClose(ticket, lots, price, slippage);
      if (closed) {
         Print("OrderClose failed with error #", GetLastError());
      }
   }
   return(closed);
}

bool modifyOrder(int ticket, double openPrice, double stopLoss, double takeProfit) {
   bool modified = false;
   if (ticket > -1) {
      modified = OrderModify(ticket, openPrice, stopLoss, takeProfit, 0);
      if (modified) {
         Print("OrderModify failed with error #", GetLastError());
      }
   }
   return(modified);
}

double getPosition(int ticket) {
   double lots = 0.0;
   if (ticket > -1 && OrdersTotal() > 0) {
      if (OrderSelect(ticket, SELECT_BY_TICKET)) {
         lots = OrderLots();
         int type = OrderType();
         switch (type) {
            case OP_BUY:
            case OP_BUYLIMIT:
            case OP_BUYSTOP:
               lots = MathAbs(lots);
               break;
            case OP_SELL:
            case OP_SELLLIMIT:
            case OP_SELLSTOP:
               lots = -MathAbs(lots);
               break;
            default:
               Print("OrderType returned unknown type ", type);
         }
      } else {
         Print("OrderSelect failed with error #", GetLastError(), ", ticket #", ticket);
         lots = 0.0;
      }
   }
   return(lots);
}

Added experts/indicators/candle_study.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
//+------------------------------------------------------------------+
//|                                                 candle_study.mq4 |
//|                                                   Othello Nagano |
//|                   http://www.google.com/profiles/onagano.g#about |
//+------------------------------------------------------------------+
#property copyright "Othello Nagano"
#property link      "http://www.google.com/profiles/onagano.g#about"

#property indicator_separate_window
#property indicator_buffers 7
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_color4 Red
#property indicator_color5 Lime
#property indicator_color6 Yellow
#property indicator_color7 Yellow
//---- input parameters
extern int     ExtMAPeriod = 200;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
double ExtMapBuffer6[];
double ExtMapBuffer7[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexLabel( 0, "High-Low");
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexLabel( 1, "Open-Close");
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexLabel( 2, "HL " + ExtMAPeriod + "MA");
   SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(3,ExtMapBuffer4);
   SetIndexLabel( 3, "OC " + ExtMAPeriod + "MA");
   SetIndexStyle(4,DRAW_HISTOGRAM);
   SetIndexBuffer(4,ExtMapBuffer5);
   SetIndexLabel( 4, "Disconnection");
   SetIndexStyle(5,DRAW_LINE,STYLE_DOT);
   SetIndexBuffer(5,ExtMapBuffer6);
   SetIndexLabel( 5, "Covered Rate");
   SetIndexStyle(6,DRAW_LINE,STYLE_SOLID);
   SetIndexBuffer(6,ExtMapBuffer7);
   SetIndexLabel( 6, "CR " + ExtMAPeriod + "MA");
   SetLevelValue(0, 50);
   SetLevelValue(1, 100);
   SetLevelValue(2, 200);
   SetLevelValue(3, 300);
   SetLevelValue(4, 400);
   SetLevelValue(5, 500);
   SetLevelValue(6, 600);
   SetLevelValue(7, 700);
   SetLevelValue(8, 800);
   SetLevelValue(9, 900);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//----
   for (int i = Bars - counted_bars - 1; i >= 0 ; i--) {
      ExtMapBuffer1[i] =
         NormalizeDouble(High[i] - Low[i], Digits) / Point;
      ExtMapBuffer2[i] =
         NormalizeDouble(MathAbs(Close[i] - Open[i]), Digits) / Point;
      if (i > Bars - ExtMAPeriod - 1) {
         ExtMapBuffer3[i] = 0.0;
         ExtMapBuffer4[i] = 0.0;
         ExtMapBuffer5[i] = 0.0;
         ExtMapBuffer6[i] = 0.0;
         ExtMapBuffer7[i] = 0.0;
      } else {
         ExtMapBuffer3[i] = calcMA(ExtMapBuffer1, i, ExtMAPeriod);
         ExtMapBuffer4[i] = calcMA(ExtMapBuffer2, i, ExtMAPeriod);
         ExtMapBuffer5[i] =
            NormalizeDouble(MathAbs(Open[i] - Close[i + 1]), Digits) / Point;
         ExtMapBuffer6[i] = calcCoveredRate(i);
         ExtMapBuffer7[i] = calcMA(ExtMapBuffer6, i, ExtMAPeriod);
      }
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+

double calcMA(double array[], int shift, int period) {
   double ma = 0.0;
   double sum = 0.0;
   for (int i = 0; i < period; i++) {
      sum += array[shift + i];
   }
   ma = NormalizeDouble(sum / period, Digits);
   return(ma);
}

double calcCoveredRate(int i) {
   double hnow = High[i];
   double lnow = Low[i];
   double hpre = High[i + 1];
   double lpre = Low[i + 1];
   if (hpre < lnow || lpre > hnow) return(0.0);
   if (hpre == lpre) return(100.0);
   double tooHigh = MathMax(0.0, NormalizeDouble(hpre - hnow, Digits));
   double tooLow = MathMax(0.0, NormalizeDouble(lnow - lpre, Digits));
   double exposed = tooHigh + tooLow;
   double denom = NormalizeDouble(hpre - lpre, Digits);
   double numer = NormalizeDouble(denom - exposed, Digits);
   double rate = NormalizeDouble(numer / denom, 2);
   return(rate * 100);
}

Added experts/indicators/composite_pair.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
//+------------------------------------------------------------------+
//|                                               composite_pair.mq4 |
//|                                                     Osamu Nagano |
//|                   http://www.google.com/profiles/onagano.g#about |
//+------------------------------------------------------------------+
#property copyright "Osamu Nagano"
#property link      "http://www.google.com/profiles/onagano.g#about"

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red
//---- input parameters
extern string    ExtLeft      = "EURUSD";
extern string    ExtRight     = "USDJPY";
extern bool      ExtMulOrDiv  = true;
//---- buffers
double ExtMapBuffer1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle( 0, DRAW_LINE);
   SetIndexBuffer(0, ExtMapBuffer1);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   static int lastIndCnt = 0;
   int            indCnt = IndicatorCounted();
   bool        hasNewBar = lastIndCnt != indCnt;
   lastIndCnt = indCnt;
//----
   for (int i = Bars - indCnt - 1; i >= 0 ; i--) {
      double left  = iClose(ExtLeft,  0, i);
      double right = iClose(ExtRight, 0, i);
      double comp  = left;
      if (ExtMulOrDiv) {
         comp = left * right;
      } else {
         if (right == 0.0) right = 1.0;
         comp = left / right;
      }
      ExtMapBuffer1[i] = NormalizeDouble(comp, Digits);
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Added experts/indicators/isosceles_dance.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
//+------------------------------------------------------------------+
//|                                              isosceles_dance.mq4 |
//|                                                     Osamu Nagano |
//|                   http://www.google.com/profiles/onagano.g#about |
//+------------------------------------------------------------------+
#property copyright "Osamu Nagano"
#property link      "http://www.google.com/profiles/onagano.g#about"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 Goldenrod
#property indicator_color4 Goldenrod
#property indicator_style3 STYLE_DASHDOTDOT
#property indicator_style4 STYLE_DASHDOTDOT
//---- input parameters
extern string    ExtTargetCcy   = "USD";
extern bool      ExtInvertMajor = true;
extern bool      ExtInvertMinor = false;
extern int       ExtLookBack    = 120;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
//---- global variables
string MajorPair;
string MinorPair;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string sym = Symbol();
   string majorCcy = StringSubstr(sym, 0, 3);
   string minorCcy = StringSubstr(sym, 3, 3);
   if (ExtInvertMajor) MajorPair = majorCcy + ExtTargetCcy;
   else                MajorPair = ExtTargetCcy + majorCcy;
   if (ExtInvertMinor) MinorPair = minorCcy + ExtTargetCcy;
   else                MinorPair = ExtTargetCcy + minorCcy;
   Print("MajorPair: " + MajorPair + ", MinorPair: " + MinorPair);
   if (MarketInfo(MajorPair, MODE_BID) == 0.0
    || MarketInfo(MinorPair, MODE_BID) == 0.0) {
      Print("Invalid Ccy Pair: ", MajorPair, " or ", MinorPair);
      //return(-1);
   }
//---- indicators
   SetIndexStyle( 0, DRAW_LINE);
   SetIndexBuffer(0, ExtMapBuffer1);
   SetIndexLabel( 0, ExtTargetCcy + " in " + majorCcy);
   SetIndexStyle( 1, DRAW_LINE);
   SetIndexBuffer(1, ExtMapBuffer2);
   SetIndexLabel( 1, ExtTargetCcy + " in " + minorCcy);
   SetIndexStyle( 2, DRAW_LINE);
   SetIndexBuffer(2, ExtMapBuffer3);
   SetIndexLabel( 2, "Max in last " + ExtLookBack);
   SetIndexStyle( 3, DRAW_LINE);
   SetIndexBuffer(3, ExtMapBuffer4);
   SetIndexLabel( 3, "Min in last " + ExtLookBack);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   static int lastIndCnt = 0;
   int            indCnt = IndicatorCounted();
   bool        hasNewBar = lastIndCnt != indCnt;
   lastIndCnt = indCnt;
//----
   for (int i = Bars - indCnt - 1; i >= 0 ; i--) {
      double thisHigh   = High[iHighest(NULL, 0, MODE_HIGH, ExtLookBack, i)];
      double thisLow    = Low[ iLowest( NULL, 0, MODE_LOW,  ExtLookBack, i)];
      double thisDenom  = NormalizeDouble(thisHigh - thisLow, Digits);
      double majorStoch = stochastic(i, MajorPair, ExtInvertMajor);
      double minorStoch = stochastic(i, MinorPair, ExtInvertMinor);
   
      ExtMapBuffer1[i] = NormalizeDouble(thisLow + thisDenom * majorStoch, Digits);
      ExtMapBuffer2[i] = NormalizeDouble(thisLow + thisDenom * minorStoch, Digits);
      ExtMapBuffer3[i] = thisHigh;
      ExtMapBuffer4[i] = thisLow;
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+

double stochastic(int i, string pair, bool invert) {
   double stoch = 0.5;

   double high   = iHigh(pair, 0, iHighest(pair, 0, MODE_HIGH, ExtLookBack, i));
   double low    = iLow( pair, 0, iLowest( pair, 0, MODE_LOW,  ExtLookBack, i));
   double close  = iClose(pair, 0, i);
   
   if (invert) {
      if (high == 0.0 || low == 0.0 || close == 0.0) return(stoch);
      high  = 1.0 / high;
      low   = 1.0 / low;
      close = 1.0 / close;
   }
      
   double numer;
   double denom;
   if (invert) {
      numer = close - high;
      denom = low   - high;
   } else {
      numer = close - low;
      denom = high  - low;
   }
   
   if (denom != 0.0) stoch = numer / denom;
   return(NormalizeDouble(stoch, Digits));
}

Added experts/indicators/isosceles_macd.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
//+------------------------------------------------------------------+
//|                                               isosceles_macd.mq4 |
//|                                                     Osamu Nagano |
//|                   http://www.google.com/profiles/onagano.g#about |
//+------------------------------------------------------------------+
#property copyright "Osamu Nagano"
#property link      "http://www.google.com/profiles/onagano.g#about"

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Gray
#property indicator_color2 Red
#property indicator_style2 STYLE_DOT
//---- input parameters
extern string    ExtTargetCcy   = "USD";
extern bool      ExtInvertMajor = true;
extern bool      ExtInvertMinor = false;
extern int       ExtLookBack    = 120;
extern int       ExtThreshold   = 250;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string sym = Symbol();
   string majorCcy = StringSubstr(sym, 0, 3);
   string minorCcy = StringSubstr(sym, 3, 3);
//---- indicators
   SetIndexStyle( 0, DRAW_HISTOGRAM);
   SetIndexBuffer(0, ExtMapBuffer1);
   SetIndexLabel( 0, minorCcy + " - " + majorCcy);
   SetIndexStyle( 1, DRAW_LINE);
   SetIndexBuffer(1, ExtMapBuffer2);
   SetIndexLabel( 1, "Signal");

   SetLevelStyle(STYLE_DOT, 1, Silver);
   SetLevelValue(3,  ExtThreshold * 2);
   SetLevelValue(1,  ExtThreshold);
   SetLevelValue(0,  0);
   SetLevelValue(2, -ExtThreshold);
   SetLevelValue(4, -ExtThreshold * 2);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   static int lastIndCnt = 0;
   int            indCnt = IndicatorCounted();
   bool        hasNewBar = lastIndCnt != indCnt;
   lastIndCnt = indCnt;
//----
   for (int i = Bars - indCnt - 1; i >= 0 ; i--) {
      double majorStoch = iCustom(NULL, 0,
                          "isosceles_dance",
                          ExtTargetCcy,
                          ExtInvertMajor,
                          ExtInvertMinor,
                          ExtLookBack,
                          0, i);
      double minorStoch = iCustom(NULL, 0,
                          "isosceles_dance",
                          ExtTargetCcy,
                          ExtInvertMajor,
                          ExtInvertMinor,
                          ExtLookBack,
                          1, i);
      ExtMapBuffer1[i] = NormalizeDouble(minorStoch - majorStoch, Digits) / Point;
      ExtMapBuffer2[i] = MathRound((ExtMapBuffer1[i] + ExtMapBuffer2[i + 1]) / 2);
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Added experts/indicators/stochastic_macd.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
//+------------------------------------------------------------------+
//|                                              stochastic_macd.mq4 |
//|                                                     Osamu Nagano |
//|                   http://www.google.com/profiles/onagano.g#about |
//+------------------------------------------------------------------+
#property copyright "Osamu Nagano"
#property link      "http://www.google.com/profiles/onagano.g#about"

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Gray
#property indicator_color2 Red
#property indicator_style2 STYLE_DOT
//---- input parameters
extern string    ExtCurrPair  = "EURUSD";
extern bool      ExtInvert    = false;
extern int       ExtLookBack  = 120;
extern int       ExtThreshold = 250;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle( 0, DRAW_HISTOGRAM);
   SetIndexBuffer(0, ExtMapBuffer1);
   SetIndexLabel( 0, "Stoch - Close");
   SetIndexStyle( 1, DRAW_LINE);
   SetIndexBuffer(1, ExtMapBuffer2);
   SetIndexLabel( 1, "Signal");
   
   SetLevelStyle(STYLE_DOT, 1, Silver);
   SetLevelValue(3,  ExtThreshold * 2);
   SetLevelValue(1,  ExtThreshold);
   SetLevelValue(0,  0);
   SetLevelValue(2, -ExtThreshold);
   SetLevelValue(4, -ExtThreshold * 2);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   static int lastIndCnt = 0;
   int            indCnt = IndicatorCounted();
   bool        hasNewBar = lastIndCnt != indCnt;
   lastIndCnt = indCnt;
//----
   for (int i = Bars - indCnt - 1; i >= 0 ; i--) {
      double close = Close[i];
      double stoch = iCustom(NULL, 0, 
                     "stochastic_overlay",
                     ExtCurrPair,
                     ExtInvert,
                     ExtLookBack,
                     0, i);
      ExtMapBuffer1[i] = NormalizeDouble(stoch - close, Digits) / Point;
      ExtMapBuffer2[i] = MathRound((ExtMapBuffer1[i] + ExtMapBuffer2[i + 1]) / 2);
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Added experts/indicators/stochastic_overlay.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
//+------------------------------------------------------------------+
//|                                           stochastic_overlay.mq4 |
//|                                                     Osamu Nagano |
//|                   http://www.google.com/profiles/onagano.g#about |
//+------------------------------------------------------------------+
#property copyright "Osamu Nagano"
#property link      "http://www.google.com/profiles/onagano.g#about"

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_color2 Goldenrod
#property indicator_color3 Goldenrod
#property indicator_style2 STYLE_DASHDOTDOT
#property indicator_style3 STYLE_DASHDOTDOT
//---- input parameters
extern string    ExtCurrPair = "EURUSD";
extern bool      ExtInvert   = false;
extern int       ExtLookBack = 120;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle( 0, DRAW_LINE);
   SetIndexBuffer(0, ExtMapBuffer1);
   if (ExtInvert)
      SetIndexLabel( 0, "Inverted " + ExtCurrPair);
   else
      SetIndexLabel( 0, ExtCurrPair);
   SetIndexStyle( 1, DRAW_LINE);
   SetIndexBuffer(1, ExtMapBuffer2);
   SetIndexLabel( 1, "Max in last " + ExtLookBack);
   SetIndexStyle( 2, DRAW_LINE);
   SetIndexBuffer(2, ExtMapBuffer3);
   SetIndexLabel( 2, "Min in last " + ExtLookBack);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   static int lastIndCnt = 0;
   int            indCnt = IndicatorCounted();
   bool        hasNewBar = lastIndCnt != indCnt;
   lastIndCnt = indCnt;
//----
   for (int i = Bars - indCnt - 1; i >= 0 ; i--) {
      double thisHigh  = High[iHighest(NULL, 0, MODE_HIGH, ExtLookBack, i)];
      double thisLow   = Low[ iLowest( NULL, 0, MODE_LOW,  ExtLookBack, i)];
      double thisDenom = NormalizeDouble(thisHigh - thisLow, Digits);
      double stoch     = stochastic(i, ExtCurrPair, ExtInvert);
      
      ExtMapBuffer1[i] = NormalizeDouble(thisLow + thisDenom * stoch, Digits);
      ExtMapBuffer2[i] = thisHigh;
      ExtMapBuffer3[i] = thisLow;
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+

double stochastic(int i, string pair, bool invert) {
   double stoch = 0.5;

   double high   = iHigh(pair, 0, iHighest(pair, 0, MODE_HIGH, ExtLookBack, i));
   double low    = iLow( pair, 0, iLowest( pair, 0, MODE_LOW,  ExtLookBack, i));
   double close  = iClose(pair, 0, i);
   
   if (invert) {
      if (high == 0.0 || low == 0.0 || close == 0.0) return(stoch);
      high  = 1.0 / high;
      low   = 1.0 / low;
      close = 1.0 / close;
   }
      
   double numer;
   double denom;
   if (invert) {
      numer = close - high;
      denom = low   - high;
   } else {
      numer = close - low;
      denom = high  - low;
   }
   
   if (denom != 0.0) stoch = numer / denom;
   return(NormalizeDouble(stoch, Digits));
}

Added experts/isosceles_nampin.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
//+------------------------------------------------------------------+
//|                                             isosceles_nampin.mq4 |
//|                                                     Osamu Nagano |
//|                   http://www.google.com/profiles/onagano.g#about |
//+------------------------------------------------------------------+
#property copyright "Osamu Nagano"
#property link      "http://www.google.com/profiles/onagano.g#about"

//---- input parameters
extern string    ExtTargetCcy    = "USD";
extern bool      ExtInvertMajor  = true;
extern bool      ExtInvertMinor  = false;
extern int       ExtLookBack     = 240;
extern int       ExtThreshold    = 200;
extern int       ExtMaxOrders    = 4;
extern double    ExtLotSize      = 0.1;
extern int       ExtSlippage     = 5;
extern int       ExtStopLoss     = 250;
extern int       ExtTakeProfit   = 1000;
extern int       ExtTrailingStep = 50;
//---- global variables
int OrderNum = 0; // Count manually to exclude stoplosses.
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
   static int lastBars = 0;
   bool hasNewBarCome  = lastBars != Bars;
   lastBars = Bars;
//----
   int rc = 0;
   // Warming up.
   if (Bars > ExtLookBack && hasNewBarCome) {
      rc = main();
   }
//----
   return(rc);
  }
//+------------------------------------------------------------------+

int main() {
   int rc = 0;
   
   double lastVal = indicator(0);
   double prevVal = indicator(1);

   if (
         (prevVal > 0 && 0 >= lastVal)
      || (prevVal < 0 && 0 <= lastVal)
      ) {
      // Close all orders.
      closeOrder();
   }
   else if (OrderNum > 0) {
      // Modify orders.
      modifyOrder();
   }   
   
   if (
         OrderNum < ExtMaxOrders
      && OrderNum < MathFloor(MathAbs(lastVal) / ExtThreshold)
      ) {
      // Open an order.
      if (lastVal > 0)
         openOrder(OP_SELL);
      if (lastVal < 0)
         openOrder(OP_BUY);
   }
   
   return(rc);
}

double indicator(int i) {
   double val = iCustom(NULL, 0,
                        "isosceles_macd",
                        ExtTargetCcy,
                        ExtInvertMajor,
                        ExtInvertMinor,
                        ExtLookBack,
                        ExtThreshold,
                        0,
                        i);
   return(val);
}

void openOrder(int cmd) {
   int ticket = OrderSend(
      Symbol(), cmd, ExtLotSize, openPrice(cmd), ExtSlippage, stopLoss(cmd), takeProfit(cmd)
   );
   if (ticket < 0) {
      logLastError("OrderSend");
   } else {
      OrderNum = OrderNum + 1;
   }
}

double openPrice(int type) {
   double price = 0.0;
   switch (type) {
      case OP_BUY:
      case OP_BUYLIMIT:
      case OP_BUYSTOP:
         price = Ask;
         break;
      case OP_SELL:
      case OP_SELLLIMIT:
      case OP_SELLSTOP:
         price = Bid;
         break;
      default:
         price = NormalizeDouble((Ask + Bid) / 2, Digits);
   }
   return(price);
}

double stopLoss(int type) {
   // Doesn't include spread.
   double price = 0.0;
   switch (type) {
      case OP_BUY:
      case OP_BUYLIMIT:
      case OP_BUYSTOP:
         price = Bid - Point * ExtStopLoss;
         break;
      case OP_SELL:
      case OP_SELLLIMIT:
      case OP_SELLSTOP:
         price = Ask + Point * ExtStopLoss;
         break;
      default:
         Print("Cannot calc stoploss for unknown type ", type);
   }
   return(price);
}

double takeProfit(int type) {
   // Doesn't include spread.
   double price = 0.0;
   switch (type) {
      case OP_BUY:
      case OP_BUYLIMIT:
      case OP_BUYSTOP:
         price = Bid + Point * ExtTakeProfit;
         break;
      case OP_SELL:
      case OP_SELLLIMIT:
      case OP_SELLSTOP:
         price = Ask - Point * ExtTakeProfit;
         break;
      default:
         Print("Cannot calc takeprofit for unknown type ", type);
   }
   return(price);
}

void modifyOrder() {
   int ot = OrdersTotal();
   for (int i = 0; i < ot; i++) {
      if (OrderSelect(i, SELECT_BY_POS)) {
         if (OrderProfit() > 0) {
            bool modify = false;
            int type = OrderType();
            double orgStls = OrderStopLoss();
            double curStls = stopLoss(type);
            if (type == OP_SELL) {
               modify = orgStls > curStls;
            } else {
               modify = orgStls < curStls;
            }
            bool enough =
               NormalizeDouble(MathAbs(orgStls - curStls), Digits) / Point
               > ExtTrailingStep;
            if (modify) {
               if (OrderModify(OrderTicket(), OrderOpenPrice(), curStls, OrderTakeProfit(), 0)) {
                  // Do nothing.
               } else {
                  logLastError("OrderModify #" + OrderTicket());
               }
            }
         }
      } else {
         logLastError("OrderSelect in modifyOrder");
      }
   }
}

void closeOrder() {
   int ot = OrdersTotal();
   for (int i = 0; i < ot; i++) {
      if (OrderSelect(i, SELECT_BY_POS)) {
         if (OrderClose(OrderTicket(), OrderLots(), closePrice(OrderType()), ExtSlippage)) {
            // Do nothing.
         } else {
            logLastError("OrderClose #" + OrderTicket());
         }
      } else {
         logLastError("OrderSelect in closeOrder");
      }
   }
   OrderNum = OrdersTotal(); // Should be 0 if no errors on closing.
}

double closePrice(int type) {
   double price = 0.0;
   switch (type) {
      case OP_BUY:
      case OP_BUYLIMIT:
      case OP_BUYSTOP:
         price = Bid;
         break;
      case OP_SELL:
      case OP_SELLLIMIT:
      case OP_SELLSTOP:
         price = Ask;
         break;
      default:
         price = NormalizeDouble((Ask + Bid) / 2, Digits);
   }
   return(price);
}

void logLastError(string operation) {
   Print(operation, " returned the error of ", GetLastError());
}

Added experts/scripts/correlation_matrix.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
//+------------------------------------------------------------------+
//|                                           correlation_matrix.mq4 |
//|                      Copyright  2010, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright  2010, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

// ArraySize(SYMBOLS)
#define SIZE 7
// ((SIZE * SIZE) - SIZE) / 2
#define NUM 21

extern int data_size = 200;
extern bool ignoreSign = false;

string SYMBOLS[SIZE] = {
     "EURUSD"
   , "GBPUSD"
   , "AUDUSD"
   , "NZDUSD"
   , "USDJPY"
   , "USDCHF"
   , "USDCAD"
/*
     "USDJPY"
   , "EURJPY"
   , "CHFJPY"
   , "GBPJPY"
   , "CADJPY"
   , "AUDJPY"
   , "NZDJPY"

     "EURUSD"
   , "EURJPY"
   , "EURGBP"
   , "EURCHF"
   , "EURCAD"
   , "EURAUD"
   , "EURNZD"

    "EURUSD"
   , "EURGBP"
   , "EURCHF"
   , "GBPUSD"
   , "USDCHF"

    "AUDUSD"
   , "AUDCHF"
   , "USDCAD"
   , "AUDCAD"
   , "NZDUSD"
   , "AUDNZD"
   , "GBPCAD"
*/
};

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
   int buffer[NUM];
   int bufInd = 0;
   string text = "";
   
   for (int i = 0; i < SIZE; i++) {
      for (int j = i + 1; j < SIZE; j++, bufInd++) {
         string symA = SYMBOLS[i];
         string symB = SYMBOLS[j];
         double corr = correlation(symA, symB, data_size);
         if (ignoreSign) corr = MathAbs(corr);
         buffer[bufInd] = encode(corr, i, j);
      }
   }

   ArraySort(buffer, WHOLE_ARRAY, 0, MODE_DESCEND);
   
   for (int k = 0; k < NUM; k++) {
      int num = buffer[k];
      int c = decode1(num);
      int a = decode2(num);
      int b = decode3(num);
      text = StringConcatenate(text, SYMBOLS[a], "/", SYMBOLS[b], ": ", c, "\n");
   }
   
   Print("Correlation Matrix: ", text);
   MessageBox(text, "Correlation Matrix");
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

int encode(double corr, int i, int j) {
   int intCorr = NormalizeDouble(MathAbs(corr), 4) * 10000;
   int code = intCorr * 10000 + i * 100 + j;
   if (corr < 0.0) code *= -1;
   return(code);
}

int decode1(int code) {
   return(code / 10000);
}

int decode2(int code) {
   int i = code / 100 % 100;
   if (i < 0) i *= -1;
   return(i);
}

int decode3(int code) {
   int i = code % 100;
   if (i < 0) i *= -1;
   return(i);
}

double average(string symbol, int size) {
   double acc = 0.0;
   
   for (int i = 0; i < size; i++) {
      double close = iClose(symbol, Period(), i);
      acc += close;
   }

   return(acc / size);
}

double correlation(string symA, string symB, int size) {
   double cov = 0.0;
   double varA = 0.0;
   double varB = 0.0;
   double aveA = average(symA, size);
   double aveB = average(symB, size);
   
   for (int i = 0; i < size; i++) {
      double cA = iClose(symA, Period(), i);
      double cB = iClose(symB, Period(), i);
      cov += (cA -  aveA) * (cB - aveB);
      varA += MathPow(cA - aveA, 2);
      varB += MathPow(cB - aveB, 2);
   }
   
   double var = MathSqrt(varA) * MathSqrt(varB);
   if (var == 0.0) var = 0.0001;
   
   return (cov / var);
}

Added experts/scripts/current_spread.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
//+------------------------------------------------------------------+
//|                                               current_spread.mq4 |
//|                      Copyright  2010, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright  2010, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

// ArraySize(SYMBOLS)
#define SIZE 35

string SYMBOLS[SIZE] = {
     "USDJPY"
   , "GBPJPY"
   , "AUDUSD"
   , "EURJPY"
   , "EURUSD"
   , "USDCHF"
   , "GBPUSD"
   , "USDCAD"
   , "NZDUSD"
   , "GBPAUD"
   , "GBPCHF"
   , "GBPCAD"
   , "EURGBP"
   , "EURCHF"
   , "USDTRY"
   , "EURTRY"
   , "TRYJPY"
   , "AUDCAD"
   , "CADJPY"
   , "EURAUD"
   , "CHFJPY"
   , "EURNZD"
   , "NZDJPY"
   , "NZDCHF"
   , "AUDJPY"
   , "ZARJPY"
   , "AUDCHF"
   , "AUDNZD"
   , "USDZAR"
   , "EURCAD"
   , "USDNOK"
   , "EURNOK"
   , "USDSEK"
   , "EURSEK"
   , "USDILS"
};

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
   string text = "";
   int buffer[SIZE];
   
   for (int i = 0; i < ArraySize(SYMBOLS); i++) {
      string symbol = SYMBOLS[i];
      int spread = MarketInfo(symbol, MODE_SPREAD);
      //text = StringConcatenate(text, symbol, ": ", spread, "\n");
      buffer[i] = 100 * spread + i;
   }
   //Print(text);
   
   ArraySort(buffer);
   text = "";
   for (int j = 0; j < SIZE; j++) {
      string sym = SYMBOLS[buffer[j] % 100];
      int spr = buffer[j] / 100;
      text = StringConcatenate(text, sym, ": ", spr, "\n");
   }
   
   Print("Current Spread: ", text);
   MessageBox(text, "Current Spread");
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

Added experts/scripts/current_volatility.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
//+------------------------------------------------------------------+
//|                                           current_volatility.mq4 |
//|                                                     Osamu Nagano |
//|                   http://www.google.com/profiles/onagano.g#about |
//+------------------------------------------------------------------+
#property copyright "Osamu Nagano"
#property link      "http://www.google.com/profiles/onagano.g#about"

extern int       ExtLookBack  = 60;

// ArraySize(SYMBOLS)
#define SIZE 15

string SYMBOLS[SIZE] = {
     "USDJPY"
   , "GBPJPY"
   , "AUDUSD"
   , "EURJPY"
   , "EURUSD"
   , "USDCHF"
   , "GBPUSD"
   , "USDCAD"
   , "NZDUSD"
   , "EURGBP"
   , "EURCHF"
   , "CADJPY"
   , "CHFJPY"
   , "NZDJPY"
   , "AUDJPY"
};

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
   int buffer[SIZE];   
   for (int i = 0; i < SIZE; i++) {
      string symbol = SYMBOLS[i];
      double stddev = iStdDev(symbol, 0, ExtLookBack, 0, MODE_SMA, PRICE_CLOSE, 0);
      double point = MarketInfo(symbol, MODE_POINT);
      if (point == 0.0) {
         MessageBox("Found zero point for " + symbol, "Current Volatility");
         return(-1);
      }
      int sdp = MathRound(stddev / point);
      Print("Presort stddev for ", symbol, ": ", sdp);
      buffer[i] = sdp * 100 + i;
   }
   ArraySort(buffer, WHOLE_ARRAY, 0, MODE_DESCEND);

   string text = "";
   for (int j = 0; j < SIZE; j++) {
      string sym = SYMBOLS[buffer[j] % 100];
      int val = buffer[j] / 100;
      text = StringConcatenate(text, sym, ": ", val, "\n");
   }
   
   Print("Current Volatility: ", text);
   MessageBox(text, "Current Volatility");
//----
   return(0);
  }
//+------------------------------------------------------------------+

Added experts/scripts/test-shellexecute.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
//+------------------------------------------------------------------+
//|                                            test-shellexecute.mq4 |
//|                                                     Osamu Nagano |
//|                   http://www.google.com/profiles/onagano.g#about |
//+------------------------------------------------------------------+
#property copyright "Osamu Nagano"
#property link      "http://www.google.com/profiles/onagano.g#about"


// http://msdn.microsoft.com/en-us/library/ms633548.aspx
#import "shell32.dll"
int ShellExecuteA(int hWnd,int lpVerb,string lpFile,string lpParameters,string lpDirectory,int nCmdShow);
#import
#define SW_SHOW             5


//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----

   if (!IsDllsAllowed()) {
      Alert("ERROR: [Allow DLL imports] NOT Checked.");return (0);
   }

   ShellExecuteA(0, 0, "C:\\Program Files\\sqlite-3_7_2\\sqlite3.exe",
                       "test.db \"insert into hoge values (444, 444)\"",
                       "C:\\Program Files\\sqlite-3_7_2", SW_SHOW);

   ShellExecuteA( 0,"open",TerminalPath()+"\\deleted",NULL,NULL,SW_SHOW);
   
//----
   return(0);
  }
//+------------------------------------------------------------------+