-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMedianRenko_Ichimoku.mq5
180 lines (171 loc) · 6.77 KB
/
MedianRenko_Ichimoku.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
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
//+------------------------------------------------------------------+
//| Ichimoku.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Ichimoku Kinko Hyo"
//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_plots 4
#property indicator_type1 DRAW_LINE
#property indicator_type2 DRAW_LINE
#property indicator_type3 DRAW_FILLING
#property indicator_type4 DRAW_LINE
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 SandyBrown,Thistle
#property indicator_color4 Lime
#property indicator_label1 "Tenkan-sen"
#property indicator_label2 "Kijun-sen"
#property indicator_label3 "Senkou Span A;Senkou Span B"
#property indicator_label4 "Chikou Span"
//--- input parameters
input int InpTenkan=9; // Tenkan-sen
input int InpKijun=26; // Kijun-sen
input int InpSenkou=52; // Senkou Span B
//--- indicator buffers
double ExtTenkanBuffer[];
double ExtKijunBuffer[];
double ExtSpanABuffer[];
double ExtSpanBBuffer[];
double ExtChikouBuffer[];
//
// 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()
{
//--- indicator buffers mapping
SetIndexBuffer(0,ExtTenkanBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtKijunBuffer,INDICATOR_DATA);
SetIndexBuffer(2,ExtSpanABuffer,INDICATOR_DATA);
SetIndexBuffer(3,ExtSpanBBuffer,INDICATOR_DATA);
SetIndexBuffer(4,ExtChikouBuffer,INDICATOR_DATA);
//---
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
//--- sets first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpTenkan);
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,InpKijun);
PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,InpSenkou-1);
//--- lines shifts when drawing
PlotIndexSetInteger(2,PLOT_SHIFT,InpKijun);
PlotIndexSetInteger(3,PLOT_SHIFT,-InpKijun);
//--- change labels for DataWindow
PlotIndexSetString(0,PLOT_LABEL,"Tenkan-sen("+string(InpTenkan)+")");
PlotIndexSetString(1,PLOT_LABEL,"Kijun-sen("+string(InpKijun)+")");
PlotIndexSetString(2,PLOT_LABEL,"Senkou Span A;Senkou Span B("+string(InpSenkou)+")");
//--- initialization done
}
//+------------------------------------------------------------------+
//| get highest value for range |
//+------------------------------------------------------------------+
double Highest(const double&array[],int range,int fromIndex)
{
double res=0;
//---
res=array[fromIndex];
for(int i=fromIndex;i>fromIndex-range && i>=0;i--)
{
if(res<array[i]) res=array[i];
}
//---
return(res);
}
//+------------------------------------------------------------------+
//| get lowest value for range |
//+------------------------------------------------------------------+
double Lowest(const double&array[],int range,int fromIndex)
{
double res=0;
//---
res=array[fromIndex];
for(int i=fromIndex;i>fromIndex-range && i>=0;i--)
{
if(res>array[i]) res=array[i];
}
//---
return(res);
}
//+------------------------------------------------------------------+
//| Ichimoku Kinko Hyo |
//+------------------------------------------------------------------+
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[])
{
//
// 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();
//
//
//
int limit;
//---
if(_prev_calculated==0) limit=0;
else limit=_prev_calculated-1;
//---
for(int i=limit;i<rates_total && !IsStopped();i++)
{
ExtChikouBuffer[i]=medianRenkoIndicator.Close[i];
//--- tenkan sen
double _high=Highest(medianRenkoIndicator.High,InpTenkan,i);
double _low=Lowest(medianRenkoIndicator.Low,InpTenkan,i);
ExtTenkanBuffer[i]=(_high+_low)/2.0;
//--- kijun sen
_high=Highest(medianRenkoIndicator.High,InpKijun,i);
_low=Lowest(medianRenkoIndicator.Low,InpKijun,i);
ExtKijunBuffer[i]=(_high+_low)/2.0;
//--- senkou span a
ExtSpanABuffer[i]=(ExtTenkanBuffer[i]+ExtKijunBuffer[i])/2.0;
//--- senkou span b
_high=Highest(medianRenkoIndicator.High,InpSenkou,i);
_low=Lowest(medianRenkoIndicator.Low,InpSenkou,i);
ExtSpanBBuffer[i]=(_high+_low)/2.0;
}
//--- done
return(rates_total);
}
//+------------------------------------------------------------------+