Author: Copyright � 2011, Nikolay Kositsin
1 Views
0 Downloads
0 Favorites
XKVO
//+------------------------------------------------------------------+ 
//|                                                         XKVO.mq5 | 
//|                               Copyright © 2011, Nikolay Kositsin | 
//|                              Khabarovsk,   farria@mail.redcom.ru | 
//+------------------------------------------------------------------+ 
//| For the indicator to work, place the SmoothAlgorithms.mqh file   |
//| in the directory: MetaTrader\\MQL5\Include                       |
//+------------------------------------------------------------------+ 
#property copyright "Copyright © 2011, Nikolay Kositsin"
#property link "farria@mail.redcom.ru" 
//---- indicator version
#property version   "1.00"
//---- drawing the indicator in a separate window
#property indicator_separate_window 
//---- number of indicator buffers 4
#property indicator_buffers 4 
//---- only two plots are used
#property indicator_plots   2
//+-----------------------------------+
//|  Indicator drawing parameters     |
//+-----------------------------------+
//---- drawing the indicator as a color histogram
#property indicator_type1 DRAW_COLOR_HISTOGRAM
//---- the following colors are used in the color histogram
#property indicator_color1 Gray,LimeGreen,Green,Red,PaleVioletRed
//---- indicator line is a solid one
#property indicator_style1 STYLE_SOLID
//---- indicator line width is equal to 2
#property indicator_width1 2
//---- displaying the indicator label
#property indicator_label1 "XKVO"
//---- drawing indicator as a color line
#property indicator_type2 DRAW_COLOR_LINE
//---- the following colors are used in a color line
#property indicator_color2 Gray,Aqua,Magenta
//---- the indicator line is a dash-dotted curve
#property indicator_style2 STYLE_DASHDOTDOT
//---- the width of the indicator line is 3
#property indicator_width2 3
//---- displaying the signal line label
#property indicator_label2  "Signal Line"
//+-----------------------------------+
//|  Smoothings classes description   |
//+-----------------------------------+
#include <SmoothAlgorithms.mqh> 
//---- declaration of the CXMA class variables from the SmoothAlgorithms.mqh file
CXMA XMA1,XMA2,XMA3;
//+-----------------------------------+
//|  Declaration of enumerations      |
//+-----------------------------------+
enum Applied_price_      // Type of constant
  {
   PRICE_CLOSE_ = 1,     // Close
   PRICE_OPEN_,          // Open
   PRICE_HIGH_,          // High
   PRICE_LOW_,           // Low
   PRICE_MEDIAN_,        // Median Price (HL/2)
   PRICE_TYPICAL_,       // Typical Price (HLC/3)
   PRICE_WEIGHTED_,      // Weighted Close (HLCC/4)
   PRICE_SIMPLE_,        // Simple Price (OC/2)
   PRICE_QUARTER_,       // Quarted Price (HLOC/4) 
   PRICE_TRENDFOLLOW0_,  // TrendFollow_1 Price 
   PRICE_TRENDFOLLOW1_   // TrendFollow_2 Price 
  };
/*enum Smooth_Method - enumeration is declared in the SmoothAlgorithms.mqh file
  {
   MODE_SMA_,  // SMA
   MODE_EMA_,  // EMA
   MODE_SMMA_, // SMMA
   MODE_LWMA_, // LWMA
   MODE_JJMA,  // JJMA
   MODE_JurX,  // JurX
   MODE_ParMA, // ParMA
   MODE_T3,    // T3
   MODE_VIDYA, // VIDYA
   MODE_AMA,   // AMA
  }; */
//+-----------------------------------+
//|  Indicator input parameters       |
//+-----------------------------------+
input Smooth_Method MA_SMethod=MODE_EMA;           // Histogram smoothing method
input int Fast_XMA = 34;                           // Fast moving average period
input int Slow_XMA = 55;                           // Slow moving average period
input int SmPhase= 100;                            // Moving averages smoothing parameter
input Smooth_Method Signal_Method=MODE_EMA;        // Signal line smoothing method
input int Signal_XMA=13;                           // Signal line period 
input int Signal_Phase=100;                        // Signal line parameter
input Applied_price_ AppliedPrice=PRICE_CLOSE_;    // Applied price
input ENUM_APPLIED_VOLUME VolumeType=VOLUME_TICK;  // Volume
//---- declaration of the integer variables for the start of data calculation
int start,xkvo_start;
//---- declaration of dynamic arrays that further 
//---- will be used as indicator buffers
double XKVOBuffer[],SignBuffer[],ColorXKVOBuffer[],ColorSignBuffer[];
//+------------------------------------------------------------------+
//| The iPriceSeries function description                            |
//| Moving_Average class description                                 | 
//+------------------------------------------------------------------+ 
#include <SmoothAlgorithms.mqh> 
//+------------------------------------------------------------------+    
//| XKVO indicator initialization function                           | 
//+------------------------------------------------------------------+  
void OnInit()
  {
//---- initialization of variables of the start of data calculation
   xkvo_start=MathMax(XMA1.GetStartBars(MA_SMethod,Fast_XMA,SmPhase),XMA1.GetStartBars(MA_SMethod,Slow_XMA,SmPhase))+1;
   start=xkvo_start+XMA1.GetStartBars(Signal_Method,Signal_XMA,Signal_Phase)+1;

//---- set XKVOBuffer[] dynamic array into an indicator buffer
   SetIndexBuffer(0,XKVOBuffer,INDICATOR_DATA);
//---- performing the shift of the beginning of the indicator drawing
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,xkvo_start);
//---- create label to display in DataWindow
   PlotIndexSetString(0,PLOT_LABEL,"XKVO");
//---- setting the indicator values that won't be visible on a chart
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
//---- set dynamic array as a color index buffer   
   SetIndexBuffer(1,ColorXKVOBuffer,INDICATOR_COLOR_INDEX);
//---- performing the shift of the beginning of the indicator drawing
   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,xkvo_start+1);
//---- set SignBuffer[] dynamic array as an indicator buffer
   SetIndexBuffer(2,SignBuffer,INDICATOR_DATA);
//---- performing the shift of the beginning of the indicator drawing
   PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,start);
//---- create label to display in DataWindow
   PlotIndexSetString(2,PLOT_LABEL,"Signal XKVO");
//---- setting the indicator values that won't be visible on a chart
   PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,EMPTY_VALUE);
//---- set ColorSignBuffer[] dynamic array as a color index buffer   
   SetIndexBuffer(3,ColorSignBuffer,INDICATOR_COLOR_INDEX);
//---- performing the shift of the beginning of the indicator drawing
   PlotIndexSetInteger(3,PLOT_DRAW_BEGIN,start+1);
//---- setting up alerts for invalid values of external variables
   XMA1.XMALengthCheck("Fast_XMA", Fast_XMA);
   XMA1.XMALengthCheck("Slow_XMA", Slow_XMA);
   XMA1.XMALengthCheck("Signal_XMA", Signal_XMA);
//---- setting up alerts for invalid values of external variables
   XMA1.XMAPhaseCheck("Phase", SmPhase, MA_SMethod);
   XMA1.XMAPhaseCheck("Signal_Phase", Signal_Phase, Signal_Method);
//---- initializations of a variable for the indicator short name
   string shortname;
   string Smooth1=XMA1.GetString_MA_Method(MA_SMethod);
   string Smooth2=XMA1.GetString_MA_Method(Signal_Method);
   StringConcatenate(shortname,
                     "XKVO( ",Fast_XMA,", ",Slow_XMA,", ",Signal_XMA,", ",Smooth1,", ",Smooth2," )");
//---- creating a name for displaying in a separate sub-window and in a tooltip
   IndicatorSetString(INDICATOR_SHORTNAME,shortname);
//---- determination of accuracy of displaying the indicator values
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
//---- initialization end
  }
//+------------------------------------------------------------------+  
//| XKVO iteration function                                          | 
//+------------------------------------------------------------------+  
int OnCalculate(const int rates_total,    // number of bars in history at the current tick
                const int prev_calculated,// number of bars calculated at previous call
                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 the calculation
   if(rates_total<start) return(0);
//---- declaration of integer variables
   int first1,first2,first3,bar;
//---- declaration of variables with a floating point  
   double tpc,tpp,var=0.0,vol,fast_xma,slow_xma,xkvo,sign_xkvo;
//---- initialization of the indicator in the OnCalculate() block
   if(prev_calculated>rates_total || prev_calculated<=0)// checking for the first start of the indicator calculation
     {
      first1=1;            // starting index for calculation of all first loop bars
      first2=xkvo_start+2; // starting index for calculation of all second loop bars
      first3=start+2;      // starting index for calculation of all third loop bars
     }
   else // starting index for calculation of new bars
     {
      first1=prev_calculated-1;
      first2=first1;
      first3=first1;
     }
//---- main indicator calculation loop
   for(bar=first1; bar<rates_total; bar++)
     {
      tpc = (low[bar] + close[bar] + close[bar])/3;
      tpp = (high[bar-1] + low[bar-1] + close[bar-1])/3;
      if(VolumeType==VOLUME_TICK) vol=double(tick_volume[bar]);
      else                        vol=double(volume[bar]);

      if(tpc>tpp) var = vol;
      if(tpc<tpp) var = -vol;
      if(tpc==tpp) var=0.0;

      fast_xma = XMA1.XMASeries(1, prev_calculated, rates_total, MA_SMethod, SmPhase, Fast_XMA, var, bar, false);
      slow_xma = XMA2.XMASeries(1, prev_calculated, rates_total, MA_SMethod, SmPhase, Slow_XMA, var, bar, false);

      xkvo=fast_xma-slow_xma;
      sign_xkvo=XMA3.XMASeries(xkvo_start,prev_calculated,rates_total,Signal_Method,Signal_Phase,Signal_XMA,xkvo,bar,false);

      //---- loading the obtained values in the indicator buffers      
      XKVOBuffer[bar]= xkvo;
      SignBuffer[bar]= sign_xkvo;
     }
//---- main loop of the XKVO indicator coloring
   for(bar=first2; bar<rates_total; bar++)
     {
      ColorXKVOBuffer[bar]=0;

      if(XKVOBuffer[bar]>0)
        {
         if(XKVOBuffer[bar]>XKVOBuffer[bar-1]) ColorXKVOBuffer[bar]=1;
         if(XKVOBuffer[bar]<XKVOBuffer[bar-1]) ColorXKVOBuffer[bar]=2;
        }

      if(XKVOBuffer[bar]<0)
        {
         if(XKVOBuffer[bar]<XKVOBuffer[bar-1]) ColorXKVOBuffer[bar]=3;
         if(XKVOBuffer[bar]>XKVOBuffer[bar-1]) ColorXKVOBuffer[bar]=4;
        }
     }
//---- main loop of the signal line coloring
   for(bar=first3; bar<rates_total; bar++)
     {
      ColorSignBuffer[bar]=0;
      if(XKVOBuffer[bar]>SignBuffer[bar-1]) ColorSignBuffer[bar]=1;
      if(XKVOBuffer[bar]<SignBuffer[bar-1]) ColorSignBuffer[bar]=2;
     }
//----     
   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 ---