-
Notifications
You must be signed in to change notification settings - Fork 2
/
volatility-pivot.mq4
93 lines (80 loc) · 2.76 KB
/
volatility-pivot.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
//+------------------------------------------------------------------+
//| Volatility.Pivot.mq4 |
//+------------------------------------------------------------------+
#property copyright ""
#property link ""
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 DarkSeaGreen
//---- input parameters
extern double atr_range=100;
extern double ima_range = 10;
extern double atr_factor=3;
extern int Mode = 0;
extern double DeltaPrice = 30;
//---- buffers
double TrStop[];
double ATR[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0, DRAW_LINE,STYLE_SOLID,1);
SetIndexBuffer(0, TrStop);
SetIndexStyle(1, DRAW_NONE);
SetIndexBuffer(1, ATR);
string short_name = "!! RisenbergVolatilityCapture";
IndicatorShortName(short_name);
SetIndexLabel(1,"range base");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars = IndicatorCounted();
int limit;
int i;
double DeltaStop;
limit = Bars;
for(i = 0; i < limit; i ++) {
ATR[i] = iATR(NULL,0,atr_range,i);
}
for(i = limit - 1; i >= 0; i --) {
if (Mode == 0) {
DeltaStop = iMAOnArray(ATR,0,ima_range,0,MODE_EMA,i) * atr_factor;
//DeltaStop = iATR(NULL,0,atr_range,i) * atr_factor;
} else {
DeltaStop = DeltaPrice*Point;
}
if (Close[i] == TrStop[i + 1]) {
TrStop[i] = TrStop[i + 1];
} else {
if (Close[i+1]<TrStop[i+1] && Close[i]<TrStop[i+1]) {
TrStop[i] = MathMin(TrStop[i + 1], Close[i] + DeltaStop);
} else {
if (Close[i+1]>TrStop[i+1] && Close[i]>TrStop[i+1]) {
TrStop[i] = MathMax(TrStop[i+1], Close[i] - DeltaStop);
} else {
if (Close[i] > TrStop[i+1]) TrStop[i] = Close[i] - DeltaStop; else TrStop[i] = Close[i] + DeltaStop;
}
}
}
}
//----
return(0);
}
//+------------------------------------------------------------------+