fatlmacd_v1

Author: Copyright © 2014, Nikolay Kositsin
0 Views
0 Downloads
0 Favorites
fatlmacd_v1
ÿþ//+---------------------------------------------------------------------+ 

//|                                                        FatlMacd.mq5 | 

//|                                  Copyright © 2014, Nikolay Kositsin | 

//|                                 Khabarovsk,   farria@mail.redcom.ru | 

//+---------------------------------------------------------------------+ 

//| Place the SmoothAlgorithms.mqh file                                 |

//| in the directory: terminal_data_folder\MQL5\Include                 |

//+---------------------------------------------------------------------+ 

#property copyright "Copyright © 2014, 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 is 2

#property indicator_buffers 2 

//--- one plot is used

#property indicator_plots   1

//+----------------------------------------------+

//| Indicator drawing parameters                 |

//+----------------------------------------------+

//--- drawing the indicator as colored labels

#property indicator_type1 DRAW_COLOR_ARROW

//--- colors of the four-color histogram are as follows

#property indicator_color1 clrMagenta,clrDeepPink,clrGray,clrDodgerBlue,clrOliveDrab

//--- Indicator line is a solid one

#property indicator_style1 STYLE_SOLID

//--- indicator line width is 3

#property indicator_width1 3

//--- displaying the indicator label

#property indicator_label1 "FatlMacd"

//+----------------------------------------------+

//| Parameters of displaying horizontal levels   |

//+----------------------------------------------+

#property indicator_level1 0

#property indicator_levelcolor clrBlue

#property indicator_levelstyle STYLE_DASHDOTDOT

//+----------------------------------------------+

//| Description of averaging classes             |

//+----------------------------------------------+

#include <SmoothAlgorithms.mqh> 

//+----------------------------------------------+

//--- declaration of the CFATL, CJJMA and CMomentum classes variables from the JJMASeries_Cls.mqh file

CXMA XMA1;

CFATL FATL1;

//+----------------------------------------------+

//| 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_SIMPL_,         //Simple Price (OC/2)

   PRICE_QUARTER_,       //Quarted Price (HLOC/4) 

   PRICE_TRENDFOLLOW0_,  //TrendFollow_1 Price 

   PRICE_TRENDFOLLOW1_,  //TrendFollow_2 Price 

   PRICE_DEMARK_         //Demark Price

  };

//+----------------------------------------------+

//| declaration of enumerations                  |

//+----------------------------------------------+

/*enum Smooth_Method - enumeration is declared in SmoothAlgorithms.mqh

  {

   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 XMA_Method=MODE_T3;         // Histogram smoothing method

input int XMA_Lengh = 20;                       // Period of averaging

input int XMA_Phase= 100;                       // Mas averaging parameter

//--- XMA_Phase: for JJMA it varies within the range -100 ... +100 and influences the quality of the transient period;

//--- XMA_Phase: for VIDIA it is a CMO period, for AMA it is a slow average period

input Applied_price_ AppliedPrice=PRICE_CLOSE_; // Price constant

//+----------------------------------------------+

//--- declaration of integer variables of data starting point

int min_rates_total,min_rates_1;

//--- declaration of dynamic arrays that

//--- will be used as indicator buffers

double IndBuffer[],ColorIndBuffer[];

//+------------------------------------------------------------------+    

//| Custom indicator initialization function                         | 

//+------------------------------------------------------------------+  

void OnInit()

  {

//--- initialization of variables of the start of data calculation

   min_rates_1=39;

   min_rates_total=min_rates_1+XMA1.GetStartBars(XMA_Method,XMA_Lengh,XMA_Phase);

//--- Set IndBuffer dynamic array as an indicator buffer

   SetIndexBuffer(0,IndBuffer,INDICATOR_DATA);

//--- Setting a dynamic array as a color index buffer   

   SetIndexBuffer(1,ColorIndBuffer,INDICATOR_COLOR_INDEX);

//--- shift the 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);

//--- setting up alerts for unacceptable values of external variables

   XMA1.XMALengthCheck("Fast_XMA",XMA_Phase);

//--- setting up alerts for unacceptable values of external variables

   XMA1.XMAPhaseCheck("Phase",XMA_Phase,XMA_Method);

//--- creation of the name to be displayed in a separate sub-window and in a pop up help

   IndicatorSetString(INDICATOR_SHORTNAME,"FatlMacd");

//--- determining the accuracy of the indicator values

   IndicatorSetInteger(INDICATOR_DIGITS,0);

//--- initialization end

  }

//+------------------------------------------------------------------+  

//| Custom indicator iteration function                              | 

//+------------------------------------------------------------------+  

int OnCalculate(const int rates_total,    // number of bars in history 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 if the number of bars is enough for the calculation

   if(rates_total<min_rates_total) return(0);

//--- declaration of integer variables

   int first,bar;

//--- declaration of variables with a floating point  

   double price,fatl,macd;

//--- initialization of the indicator in the OnCalculate() block

   if(prev_calculated>rates_total || prev_calculated<=0)// checking for the first start of calculation of an indicator

     {

      first=0; // starting index for calculation of all first loop bars

     }

   else        // starting number for the calculation of new bars

     {

      first=prev_calculated-1;

     }

//--- main calculation loop of the indicator

   for(bar=first; bar<rates_total && !IsStopped(); bar++)

     {

      //--- getting the entry price

      price=PriceSeries(AppliedPrice,bar,open,low,high,close);

      //--- uploading the entry price into FATLSeries() and getting fatl

      fatl=FATL1.FATLSeries(0,prev_calculated,rates_total,price,bar,false);

      //--- getting MACD

      macd=price-fatl;

      //--- uploading macd to XMASeries() for averaging

      IndBuffer[bar]=XMA1.XMASeries(min_rates_1,prev_calculated,rates_total,XMA_Method,XMA_Phase,XMA_Lengh,macd,bar,false);

      //--- changing dimension of the indicator up to integer values

      IndBuffer[bar]/=_Point;

     }

   if(prev_calculated>rates_total || prev_calculated<=0) first++;

//--- main cycle of the indicator coloring

   for(bar=first; bar<rates_total && !IsStopped(); bar++)

     {

      int clr=2;

      if(IndBuffer[bar]>0)

        {

         if(IndBuffer[bar]>IndBuffer[bar-1]) clr=4;

         if(IndBuffer[bar]<IndBuffer[bar-1]) clr=3;

        }

      if(IndBuffer[bar]<0)

        {

         if(IndBuffer[bar]<IndBuffer[bar-1]) clr=0;

         if(IndBuffer[bar]>IndBuffer[bar-1]) clr=1;

        }

      ColorIndBuffer[bar]=clr;

     }

//---     

   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 ---