1 //+------------------------------------------------------------------+
\r
2 //| Market_Outlook.mq4 |
\r
3 //| Copyright © 2011, Zarko Asenov |
\r
4 //| http://jaltoh.6x.to |
\r
5 //+------------------------------------------------------------------+
\r
6 #property copyright "Copyright © 2011, Zarko Asenov"
\r
7 #property link "http://jaltoh.6x.to"
\r
9 #property indicator_chart_window
\r
10 #property indicator_buffers 6
\r
11 #property indicator_color1 Goldenrod
\r
12 #property indicator_color2 Goldenrod
\r
13 #property indicator_color3 Lime
\r
14 #property indicator_color4 Lime
\r
15 #property indicator_color5 MediumSlateBlue
\r
16 #property indicator_color6 DarkOrange
\r
17 #property indicator_width1 3
\r
18 #property indicator_width2 3
\r
19 #property indicator_width3 4
\r
20 #property indicator_width4 4
\r
21 #property indicator_width5 5
\r
22 #property indicator_width6 5
\r
23 #property indicator_style1 STYLE_SOLID
\r
24 #property indicator_style2 STYLE_SOLID
\r
25 #property indicator_style3 STYLE_SOLID
\r
26 #property indicator_style4 STYLE_SOLID
\r
27 #property indicator_style5 STYLE_SOLID
\r
28 #property indicator_style6 STYLE_SOLID
\r
31 //--- input parameters
\r
32 extern int Maximum_Resolution = PERIOD_M1;
\r
34 extern int Time_Frame = PERIOD_H1;
\r
36 extern int Time_Frame = 0;
\r
37 >>>>>>> d1f8eca3054a866379156d71012f6feb4bddbde9
38 extern int Bars_Computed = 10;
\r
39 extern double Time_Weight = 2.0;
\r
40 extern bool Rough_Estimates = false;
\r
41 extern string _ = ""; // separator
\r
42 extern int Price_Mode = PRICE_CLOSE;
\r
43 extern int Hint_Price_Close = PRICE_CLOSE;
\r
44 extern int Hint_Price_High = PRICE_HIGH;
\r
45 extern int Hint_Price_Low = PRICE_LOW;
\r
46 extern int Hint_Price_Median = PRICE_MEDIAN;
\r
47 extern int Hint_Price_Typical = PRICE_TYPICAL;
\r
48 extern int Hint_Price_Weighted = PRICE_WEIGHTED;
\r
51 int max_resolution_secs;
\r
52 int sub_periods_count;
\r
55 double display_time_ratio;
\r
60 double avg_hi_weighted[];
\r
61 double avg_lo_weighted[];
\r
63 double avg_weighted[];
\r
65 //+------------------------------------------------------------------+
\r
66 //| Custom indicator initialization function |
\r
67 //+------------------------------------------------------------------+
\r
72 if (Time_Frame == 0) time_frame = Period();
\r
73 else time_frame = Time_Frame;
\r
75 if (Maximum_Resolution == 0) Maximum_Resolution = PERIOD_M1;
\r
77 if (Time_Weight == 0.0) time_factor = 1.0 + 1.0 * Maximum_Resolution / time_frame;
\r
78 else time_factor = Time_Weight;
\r
80 max_resolution_secs = Maximum_Resolution * 60;
\r
81 sub_periods_count = time_frame / Maximum_Resolution;
\r
83 stop_level = MarketInfo(Symbol(), MODE_STOPLEVEL);
\r
84 display_time_ratio = 1.0 * time_frame / Period();
\r
86 SetIndexBuffer(0, avg_hi);
\r
87 SetIndexBuffer(1, avg_lo);
\r
88 SetIndexBuffer(2, avg_hi_weighted);
\r
89 SetIndexBuffer(3, avg_lo_weighted);
\r
90 SetIndexBuffer(4, avg_price);
\r
91 SetIndexBuffer(5, avg_weighted);
\r
93 SetIndexStyle(0, DRAW_HISTOGRAM);
\r
94 SetIndexStyle(1, DRAW_HISTOGRAM);
\r
95 SetIndexStyle(2, DRAW_HISTOGRAM);
\r
96 SetIndexStyle(3, DRAW_HISTOGRAM);
\r
97 SetIndexStyle(4, DRAW_HISTOGRAM);
\r
98 SetIndexStyle(5, DRAW_HISTOGRAM);
\r
100 SetIndexLabel(0, "Average High Price");
\r
101 SetIndexLabel(1, "Average Low Price");
\r
102 SetIndexLabel(2, "Average Weighted High Price");
\r
103 SetIndexLabel(3, "Average Weighted Low Price");
\r
104 SetIndexLabel(4, "Average Price");
\r
105 SetIndexLabel(5, "Average Weighted Price");
\r
109 //+------------------------------------------------------------------+
\r
110 //| Custom indicator deinitialization function |
\r
111 //+------------------------------------------------------------------+
\r
129 switch (price_mode) {
\r
140 price = (hi + lo) / 2.0;
\r
142 case PRICE_TYPICAL:
\r
143 price = (hi + lo + close) / 3.0;
\r
145 case PRICE_WEIGHTED:
\r
146 price = (hi + lo + close + close) / 4.0;
\r
150 Print("Invalid price mode: " + Price_Mode);
\r
158 datetime start_time,
\r
162 double &high_weight,
\r
163 double &low_weight,
\r
167 int sub_period_start;
\r
168 int sub_period_end;
\r
170 sub_period_start = iBarShift(Symbol(), Maximum_Resolution, start_time);
\r
171 sub_period_end = iBarShift(Symbol(), Maximum_Resolution, end_time);
\r
174 for (int ix = sub_period_start; ix >= sub_period_end; ix--) {
\r
176 double sub_high = iHigh(Symbol(), Maximum_Resolution, ix);
\r
177 double sub_low = iLow(Symbol(), Maximum_Resolution, ix);
\r
178 double sub_close = iClose(Symbol(), Maximum_Resolution, ix);
\r
180 high = (pos_ctr * high + sub_high) / (pos_ctr + 1.0);
\r
181 low = (pos_ctr * low + sub_low) / (pos_ctr + 1.0);
\r
182 high_weight = (pos_ctr * high_weight + time_factor * sub_high) / (pos_ctr + time_factor);
\r
183 low_weight = (pos_ctr * low_weight + time_factor * sub_low) / (pos_ctr + time_factor);
\r
185 double price = get_price(
\r
191 weighted = (pos_ctr * weighted + time_factor * price) / (pos_ctr + time_factor);
\r
192 flat = (pos_ctr * flat + price) / (pos_ctr + 1.0);
\r
204 " ( " + DoubleToStr( (price1 - price2) / Point, 0) + " ) "
\r
208 //+------------------------------------------------------------------+
\r
209 //| Custom indicator iteration function |
\r
210 //+------------------------------------------------------------------+
\r
214 int draw_bars = Bars - IndicatorCounted() - 1;
\r
215 if (draw_bars < 0) return (0);
\r
219 int compute_start_bar;
\r
220 if (draw_bars == 0) compute_start_bar = 0;
\r
221 else compute_start_bar = draw_bars / display_time_ratio;
\r
223 for (int ix = compute_start_bar; ix >= 0; ix--) {
\r
224 if (ix < Bars_Computed) {
\r
225 double current_avg_hi;
\r
226 double current_avg_lo;
\r
227 double current_avg_hi_weigh;
\r
228 double current_avg_lo_weigh;
\r
229 double current_avg_flat;
\r
230 double current_avg_weighted;
\r
232 datetime open_time = iTime(Symbol(), time_frame, ix);
\r
233 datetime close_time;
\r
236 close_time = iTime(Symbol(), time_frame, ix - 1) - max_resolution_secs;
\r
238 close_time = TimeCurrent();
\r
245 current_avg_hi_weigh,
\r
246 current_avg_lo_weigh,
\r
248 current_avg_weighted);
\r
250 } else if (Rough_Estimates == true) {
\r
253 current_avg_hi = High[ix];
\r
254 current_avg_lo = Low[ix];
\r
255 current_avg_hi_weigh = (High[ix] + High[ix] + High[ix + 1]) / 3.0;
\r
256 current_avg_lo_weigh = (Low[ix] + Low[ix] + Low[ix + 1]) / 3.0;
\r
257 current_avg_weighted = get_price(PRICE_WEIGHTED, Close[ix], avg_hi_weighted[ix], avg_lo_weighted[ix]);
\r
258 current_avg_flat = get_price(PRICE_MEDIAN, Close[ix], avg_hi[ix], avg_lo[ix]);
\r
263 for (int display_ix = ix * display_time_ratio;
\r
264 display_ix < (ix + 1) * display_time_ratio;
\r
266 avg_hi[display_ix] = current_avg_hi;
\r
267 avg_lo[display_ix] = current_avg_lo;
\r
268 avg_hi_weighted[display_ix] = current_avg_hi_weigh;
\r
269 avg_lo_weighted[display_ix] = current_avg_lo_weigh;
\r
270 avg_weighted[display_ix] = current_avg_flat;
\r
271 avg_price[display_ix] = current_avg_weighted;
\r
276 double spread = MarketInfo(Symbol(), MODE_SPREAD);
\r
277 double mid_price = (High[0] + Low[0]) / 2.0;
\r
278 double typical_price = (High[0] + Low[0] + Close[0]) / 3.0;
\r
279 double weighted_price = (High[0] + Low[0] + Close[0] + Close[0]) / 4.0;
\r
281 double minutes_left = ( time_frame * 60.0 - (TimeCurrent() - iTime(Symbol(), time_frame, 0)) ) / 60.0;
\r
286 "Symbol: " + Symbol() + " " +
\r
287 "Calculated period: " + time_frame + " min\n" +
\r
288 "Spread: " + DoubleToStr(spread, 0) + " " +
\r
289 "Min Stop: " + DoubleToStr(stop_level, 0) + "\n" +
\r
290 "Bar in T-" + DoubleToStr(minutes_left, 2) + " min\n" +
\r
291 "Time weight: " + DoubleToStr(time_factor, 2) + " " +
\r
292 "Subperiod: " + Maximum_Resolution + " min\n\n" +
\r
294 "Midprice HL: " + DoubleToStr(mid_price, Digits) + get_diff_string(Close[0], mid_price) + "\n" +
\r
295 "Typical HLC: " + DoubleToStr(typical_price, Digits) + get_diff_string(Close[0], typical_price) + "\n" +
\r
296 "Weighted HLCC: " + DoubleToStr(weighted_price, Digits) + get_diff_string(Close[0], weighted_price) + "\n\n" +
\r
298 "Average Price: " + DoubleToStr(avg_price[ix], Digits) + get_diff_string(Close[0], avg_price[ix]) + "\n" +
\r
299 "Average Weighted: " + DoubleToStr(avg_weighted[ix], Digits) + get_diff_string(Close[0], avg_weighted[ix]) + "\n" +
\r
300 "Average High: " + DoubleToStr(avg_hi[ix], Digits) + get_diff_string(Close[0], avg_hi[ix]) + "\n" +
\r
301 "Average Low: " + DoubleToStr(avg_lo[ix], Digits) + get_diff_string(Close[0], avg_lo[ix]) + "\n\n"
\r
306 //+------------------------------------------------------------------+