-
Notifications
You must be signed in to change notification settings - Fork 0
/
williams-and-range-escaping.mq5
68 lines (62 loc) · 2.53 KB
/
williams-and-range-escaping.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
//+------------------------------------------------------------------+
//| williams-and-range-escaping.mq5 |
//| Lonv'ha KPETO |
//| https://ultron-systems.com |
//+------------------------------------------------------------------+
#include <Trade\Trade.mqh>
#include "ranging.mqh";
#include "utils.mqh";
#include "timer.mqh";
input int rangeSize = 5;
input int willamsPeriod = 14;
CTrade _trade;
CRangingMarket _ranging;
CNewBar _bar;
int williamsHandle;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit() {
_ranging.setNumCandles(rangeSize);
_ranging.setUseCurrentTick(false);
williamsHandle = iWPR(_Symbol, PERIOD_CURRENT, willamsPeriod);
if (williamsHandle == INVALID_HANDLE) {
PrintFormat("Error when initilizing Williams %R indicator");
return (INIT_FAILED);
}
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick(){
//scalp_profits();
//if ( !_ranging.isRanging(_Symbol, PERIOD_CURRENT) ) {
//PrintFormat("Market is trending");
double williams = lastBarWilliams(williamsHandle, false);
//PrintFormat("Williams => %f", williams);
if (MathAbs(williams) < 50) {
if (PositionsTotal() == 0
&& !_ranging.isRanging(_Symbol, PERIOD_H1)
&& !_ranging.isRanging(_Symbol, PERIOD_M5)
&& !_ranging.isRanging(_Symbol, PERIOD_M1)
&& !_ranging.isRanging(_Symbol, PERIOD_CURRENT)
) {
double sl = _ranging.getLow();
_trade.Buy(0.001, _Symbol, 0.0, sl, LongTakeProfit(sl, 0.5));
}
}
if (MathAbs(williams) > 50) {
if (PositionsTotal() == 0
&& !_ranging.isRanging(_Symbol, PERIOD_H1)
&& !_ranging.isRanging(_Symbol, PERIOD_M5)
&& !_ranging.isRanging(_Symbol, PERIOD_M1)
&& !_ranging.isRanging(_Symbol, PERIOD_CURRENT)
) {
double sl = _ranging.getHigh();
_trade.Sell(0.001, _Symbol, 0.0, sl, ShortTakeProfit(sl, 0.5));
}
}
//}
}
//+------------------------------------------------------------------+