-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMedianRenko_volumes.mq5
141 lines (130 loc) · 5.17 KB
/
MedianRenko_volumes.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
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
//+------------------------------------------------------------------+
//| Volumes.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots 1
#property indicator_type1 DRAW_COLOR_HISTOGRAM
#property indicator_color1 Green,Red
#property indicator_style1 0
#property indicator_width1 1
#property indicator_minimum 0.0
//--- input data
input ENUM_APPLIED_VOLUME InpVolumeType=VOLUME_TICK; // Volumes
//---- indicator buffers
double ExtVolumesBuffer[];
double ExtColorsBuffer[];
//
// Initialize MedianRenko indicator for data processing
// according to settings of the MedianRenko indicator already on chart
//
#include <AZ-INVEST/SDK/MedianRenkoIndicator.mqh>
MedianRenkoIndicator medianRenkoIndicator;
//
//
//
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//---- buffers
SetIndexBuffer(0,ExtVolumesBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtColorsBuffer,INDICATOR_COLOR_INDEX);
//---- name for DataWindow and indicator subwindow label
IndicatorSetString(INDICATOR_SHORTNAME,"Volumes");
//---- indicator digits
IndicatorSetInteger(INDICATOR_DIGITS,0);
medianRenkoIndicator.SetGetVolumesFlag();
//----
}
//+------------------------------------------------------------------+
//| Volumes |
//+------------------------------------------------------------------+
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[])
{
//---check for rates total
if(rates_total<2)
return(0);
//
// Process data through MedianRenko indicator
//
if(!medianRenkoIndicator.OnCalculate(rates_total,prev_calculated,time))
return(0);
//
// Make the following modifications in the code below:
//
// medianRenkoIndicator.GetPrevCalculated() should be used instead of prev_calculated
//
// medianRenkoIndicator.Open[] should be used instead of open[]
// medianRenkoIndicator.Low[] should be used instead of low[]
// medianRenkoIndicator.High[] should be used instead of high[]
// medianRenkoIndicator.Close[] should be used instead of close[]
//
// medianRenkoIndicator.IsNewBar (true/false) informs you if a renko brick completed
//
// medianRenkoIndicator.Time[] shold be used instead of Time[] for checking the renko bar time.
// (!) medianRenkoIndicator.SetGetTimeFlag() must be called in OnInit() for medianRenkoIndicator.Time[] to be used
//
// medianRenkoIndicator.Tick_volume[] should be used instead of TickVolume[]
// medianRenkoIndicator.Real_volume[] should be used instead of Volume[]
// (!) medianRenkoIndicator.SetGetVolumesFlag() must be called in OnInit() for Tick_volume[] & Real_volume[] to be used
//
// medianRenkoIndicator.Price[] should be used instead of Price[]
// (!) medianRenkoIndicator.SetUseAppliedPriceFlag(ENUM_APPLIED_PRICE _applied_price) must be called in OnInit() for medianRenkoIndicator.Price[] to be used
//
int _prev_calculated = medianRenkoIndicator.GetPrevCalculated();
//
//
//
//--- starting work
int start=_prev_calculated-1;
//--- correct position
if(start<1) start=1;
//--- main cycle
if(InpVolumeType==VOLUME_TICK)
CalculateVolume(start,rates_total,medianRenkoIndicator.Tick_volume);
else
CalculateVolume(start,rates_total,medianRenkoIndicator.Real_volume);
//--- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CalculateVolume(const int nPosition,
const int nRatesCount,
const long &SrcBuffer[])
{
ExtVolumesBuffer[0]=(double)SrcBuffer[0];
ExtColorsBuffer[0]=0.0;
//---
for(int i=nPosition;i<nRatesCount && !IsStopped();i++)
{
//--- get some data from src buffer
double dCurrVolume=(double)SrcBuffer[i];
double dPrevVolume=(double)SrcBuffer[i-1];
//--- calculate indicator
ExtVolumesBuffer[i]=dCurrVolume;
if(dCurrVolume>dPrevVolume)
ExtColorsBuffer[i]=0.0;
else
ExtColorsBuffer[i]=1.0;
}
//---
}
//+------------------------------------------------------------------+