Author: Copyright � 2010, Ilya Filatov
0 Views
0 Downloads
0 Favorites
2MoHLC_
//+------------------------------------------------------------------+ 
//|                   2 Medians of High-Low Channels      2MoHLC.mq5 | 
//|                                   Copyright © 2010, Ilya Filatov | 
//|                                               ilya-filatov@ya.ru | 
//+------------------------------------------------------------------+ 
#property copyright "Copyright © 2010, Ilya Filatov"
#property link "ilya-filatov@ya.ru"
#property description "2 Medians of High-Low Channels"
//---- indicator version number
#property version   "1.00"
//---- drawing the indicator in the main window
#property indicator_chart_window
//---- number of indicator buffers 4
#property indicator_buffers 4 
//---- one plot is used
#property indicator_plots   3
//+-----------------------------------+
//|  Indicator 1 drawing parameters   |
//+-----------------------------------+
//---- drawing the indicator as a colored cloud
#property indicator_type1   DRAW_FILLING
//---- the following colors are used for the indicator
#property indicator_color1  clrDeepSkyBlue,clrHotPink
//---- displaying the indicator label
#property indicator_label1  "2MoHLC"
//+-----------------------------------+
//|  Indicator 2 drawing parameters   |
//+-----------------------------------+
//---- drawing the indicator 2 as a line
#property indicator_type2   DRAW_LINE
//---- SlateGray color is used for the indicator signal line
#property indicator_color2  clrSlateGray
//---- the indicator 2 line is a continuous curve
#property indicator_style2  STYLE_SOLID
//---- indicator 2 line width is equal to 2
#property indicator_width2  2
//---- displaying of the indicator line label
#property indicator_label2  "HLC-M1"
//+-----------------------------------+
//|  Indicator 3 drawing parameters   |
//+-----------------------------------+
//---- drawing indicator 3 as line
#property indicator_type3   DRAW_LINE
//---- SlateGray color is used for the indicator signal line
#property indicator_color3  clrSlateGray
//---- the indicator 3 line is a continuous curve
#property indicator_style3  STYLE_SOLID
//---- indicator 3 line width is equal to 2
#property indicator_width3  2
//---- displaying of the indicator line label
#property indicator_label3  "HLC-M2"

//+-----------------------------------+
//|  Input parameters of the indicator|
//+-----------------------------------+
input int Period1=24; //Period 1
input int Period2=48; //Period 2
input int Shift=0; //Horizontal shift of the indicator in bars 
//+-----------------------------------+

//---- declaration of the integer variables for the start of data calculation
int  min_rates_total;
//---- declaration of dynamic arrays that further 
//---- will be used as indicator buffers
double Ext1Buffer[];
double Ext2Buffer[];
double Ext1_Buffer[];
double Ext2_Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
//---- Initialization of variables of the start of data calculation
   min_rates_total=MathMax(Period1,Period2);
   
//---- set dynamic array as an indicator buffer
   SetIndexBuffer(0,Ext1Buffer,INDICATOR_DATA);
//---- indexing elements in the buffer as in timeseries
   ArraySetAsSeries(Ext1Buffer,true);
   
//---- set dynamic array as an indicator buffer
   SetIndexBuffer(1,Ext2Buffer,INDICATOR_DATA);
//---- indexing elements in the buffer as in timeseries
   ArraySetAsSeries(Ext2Buffer,true);
   
//---- set dynamic array as an indicator buffer
   SetIndexBuffer(2,Ext1_Buffer,INDICATOR_DATA);
//---- indexing elements in the buffer as in timeseries
   ArraySetAsSeries(Ext1_Buffer,true);
   
//---- set dynamic array as an indicator buffer
   SetIndexBuffer(3,Ext2_Buffer,INDICATOR_DATA);
//---- indexing elements in the buffer as in timeseries
   ArraySetAsSeries(Ext2_Buffer,true);
      
//---- performing the shift of beginning of indicator drawing
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);
//---- setting the indicator values that won't be visible on a chart
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
//---- horizontal shift of the indicator
   PlotIndexSetInteger(0,PLOT_SHIFT,Shift);
   
//---- performing the shift of beginning of indicator drawing
   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,min_rates_total);
//---- setting the indicator values that won't be visible on a chart
   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE);
//---- horizontal shift of the indicator
   PlotIndexSetInteger(1,PLOT_SHIFT,Shift);
   
//---- performing the shift of beginning of indicator drawing
   PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,min_rates_total);
//---- setting the indicator values that won't be visible on a chart
   PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,EMPTY_VALUE);
//---- horizontal shift of the indicator
   PlotIndexSetInteger(2,PLOT_SHIFT,Shift);

//--- creation of the name to be displayed in a separate sub-window and in a pop up help
   IndicatorSetString(INDICATOR_SHORTNAME,"2MoHLC("+string(Period1)+","+string(Period2)+")");
//---- determination of accuracy of displaying the indicator values
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//---- end of initialization
  }
//+------------------------------------------------------------------+  
//| Custom indicator iteration function                              | 
//+------------------------------------------------------------------+  
int OnCalculate(
                const int rates_total,    // amount of history in bars at the current tick
                const int prev_calculated,// amount of history in bars at the previous tick
                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[]
                )
  {
//---- checking the number of bars to be enough for calculation
   if(rates_total<min_rates_total) return(0);

//---- declaration of variables with a floating point  
   double HH,LL;
//---- Declaration of integer variables
   int limit;

//---- Calculate the "limit" starting number for loop of bars recalculation
   if(prev_calculated>rates_total || prev_calculated<=0)// checking for the first start of calculation of an indicator
        limit=rates_total-min_rates_total-1; // starting index for calculation of all bars
   else limit=rates_total-prev_calculated;  // starting index for calculation of new bars only

//---- indexing elements in arrays as timeseries  
   ArraySetAsSeries(High,true);
   ArraySetAsSeries(Low,true);   
   
//---- main cycle of calculation of the indicator
   for(int bar=limit; bar>=0; bar--)
     {
      HH=High[ArrayMaximum(High,bar,Period1)];
      LL=Low [ArrayMinimum(Low, bar,Period1)];
      Ext1Buffer[bar]=(HH+LL)/2.0;
      Ext1_Buffer[bar]=Ext1Buffer[bar];
      //---
      HH=High[ArrayMaximum(High,bar,Period2)];
      LL=Low [ArrayMinimum(Low, bar,Period2)];
      Ext2Buffer[bar]=(HH+LL)/2.0;
      Ext2_Buffer[bar]=Ext2Buffer[bar];
     }
//----    
   return(rates_total);
  }
//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---