-
Notifications
You must be signed in to change notification settings - Fork 2
/
vr_moving_average.mq4
82 lines (78 loc) · 3.19 KB
/
vr_moving_average.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
//+------------------------------------------------------------------+
//| VR Moving Average.mq4 |
//| Copyright 2015, Trading-go Project. |
//| http://trading-go.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, Trading-go Project."
#property link "http://trading-go.ru"
#property version "15.12" // 14.12.2015
#property strict
#property indicator_chart_window
#property indicator_buffers 3
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
input int period = 20; // Period
input ENUM_MA_METHOD method = MODE_EMA; // Method
input ENUM_APPLIED_PRICE Price = PRICE_CLOSE; // Price
input int width = 2; // Width
input color UpLine = clrBlue; // Up Line
input color DwLine = clrRed; // Dw Line
double ExtUpBuffer[];
double ExtDnBuffer[];
double ExtBuffer[];
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int OnInit()
{
Comment("");
SetIndexStyle(0,DRAW_LINE,0,width,UpLine);
SetIndexStyle(1,DRAW_LINE,0,width,DwLine);
SetIndexStyle(2,DRAW_NONE);
SetIndexBuffer(0,ExtUpBuffer);
SetIndexBuffer(1,ExtDnBuffer);
SetIndexBuffer(2,ExtBuffer);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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[])
{
if(rates_total<period-1 || period<2)
return(0);
int limit=0;
if(prev_calculated==0) // ïðîâåðêà íà ïåðâûé ñòàðò
limit=rates_total-1;
else
limit=rates_total-prev_calculated+1;
for(int i=0;i<limit;i++)
ExtBuffer[i]=iMA(NULL,0,period,0,method,Price,i);
for(int i=0;i<limit-1;i++)
{
if(ExtBuffer[i+1]>ExtBuffer[i])
{
ExtDnBuffer[i]=ExtBuffer[i];
ExtDnBuffer[i+1]=ExtBuffer[i+1];
}
else
{
ExtUpBuffer[i]=ExtBuffer[i];
ExtUpBuffer[i+1]=ExtBuffer[i+1];
}
}
return(rates_total);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+