Author: Copyright � 2014, Nikolay Kositsin
1 Views
0 Downloads
0 Favorites
fatlmacd
//+---------------------------------------------------------------------+ 
//|                                                        FatlMacd.mq5 | 
//|                                  Copyright © 2014, Nikolay Kositsin | 
//|                                 Khabarovsk,   farria@mail.redcom.ru | 
//+---------------------------------------------------------------------+ 
//| Äëÿ ðàáîòû  èíäèêàòîðà  ñëåäóåò  ïîëîæèòü ôàéë SmoothAlgorithms.mqh |
//| â ïàïêó (äèðåêòîðèþ): êàòàëîã_äàííûõ_òåðìèíàëà\\MQL5\Include        |
//+---------------------------------------------------------------------+ 
#property copyright "Copyright © 2014, Nikolay Kositsin"
#property link "farria@mail.redcom.ru" 
//---- íîìåð âåðñèè èíäèêàòîðà
#property version   "1.00"
//---- îòðèñîâêà èíäèêàòîðà â îòäåëüíîì îêíå
#property indicator_separate_window 
//---- êîëè÷åñòâî èíäèêàòîðíûõ áóôåðîâ 2
#property indicator_buffers 2 
//---- èñïîëüçîâàíî âñåãî îäíî ãðàôè÷åñêîå ïîñòðîåíèå
#property indicator_plots   1
//+----------------------------------------------+
//| Ïàðàìåòðû îòðèñîâêè èíäèêàòîðà               |
//+----------------------------------------------+
//---- îòðèñîâêà èíäèêàòîðà â âèäå öâåòíûõ çíà÷êîâ
#property indicator_type1 DRAW_COLOR_ARROW
//---- â êà÷åñòâå öâåòîâ ÷åòûðåõöâåòíîé ãèñòîãðàììû èñïîëüçîâàíû
#property indicator_color1 clrMagenta,clrDeepPink,clrGray,clrDodgerBlue,clrOliveDrab
//---- ëèíèÿ èíäèêàòîðà - ñïëîøíàÿ
#property indicator_style1 STYLE_SOLID
//---- òîëùèíà ëèíèè èíäèêàòîðà ðàâíà 3
#property indicator_width1 3
//---- îòîáðàæåíèå ìåòêè èíäèêàòîðà
#property indicator_label1 "FatlMacd"
//+----------------------------------------------+
//| Ïàðàìåòðû îòîáðàæåíèÿ ãîðèçîíòàëüíûõ óðîâíåé |
//+----------------------------------------------+
#property indicator_level1 0
#property indicator_levelcolor clrBlue
#property indicator_levelstyle STYLE_DASHDOTDOT
//+----------------------------------------------+
//| Îïèñàíèå êëàññîâ óñðåäíåíèé                  |
//+----------------------------------------------+
#include <SmoothAlgorithms.mqh> 
//+----------------------------------------------+
//---- îáúÿâëåíèå ïåðåìåííûõ êëàññîâ CFATL, CJJMA è CMomentum èç ôàéëà JJMASeries_Cls.mqh
CXMA XMA1;
CFATL FATL1;
//+----------------------------------------------+
//| Îáúÿâëåíèå ïåðå÷èñëåíèé                      |
//+----------------------------------------------+
enum Applied_price_ //Òèï êîíñòàíòû
  {
   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_,         //Simpl Price (OC/2)
   PRICE_QUARTER_,       //Quarted Price (HLOC/4) 
   PRICE_TRENDFOLLOW0_,  //TrendFollow_1 Price 
   PRICE_TRENDFOLLOW1_,  //TrendFollow_2 Price 
   PRICE_DEMARK_         //Demark Price
  };
//+----------------------------------------------+
/*enum Smooth_Method - ïåðå÷èñëåíèå îáúÿâëåíî â ôàéëå 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
  }; */
//+----------------------------------------------+
//| Âõîäíûå ïàðàìåòðû èíäèêàòîðà                 |
//+----------------------------------------------+
input Smooth_Method XMA_Method=MODE_T3; // Ìåòîä óñðåäíåíèÿ ãèñòîãðàììû
input int XMA_Lengh = 20; // Ïåðèîä óñðåäíåíèÿ
input int XMA_Phase= 100; // Ïàðàìåòð óñðåäíåíèÿ ñêîëüçÿùèõ ñðåäíèé
//--- äëÿ JJMA èçìåíÿþùèéñÿ â ïðåäåëàõ -100 ... +100, âëèÿåò íà êà÷åñòâî ïåðåõîäíîãî ïðîöåññà;
//--- äëÿ VIDIA ýòî ïåðèîä CMO, äëÿ AMA ýòî ïåðèîä ìåäëåííîé ñêîëüçÿùåé
input Applied_price_ AppliedPrice=PRICE_CLOSE_; // Öåíîâàÿ êîíñòàíòà
//+----------------------------------------------+
//---- îáúÿâëåíèå öåëî÷èñëåííûõ ïåðåìåííûõ íà÷àëà îòñ÷åòà äàííûõ
int min_rates_total,min_rates_1;
//---- îáúÿâëåíèå äèíàìè÷åñêèõ ìàññèâîâ, êîòîðûå áóäóò â 
//---- äàëüíåéøåì èñïîëüçîâàíû â êà÷åñòâå èíäèêàòîðíûõ áóôåðîâ
double IndBuffer[],ColorIndBuffer[];
//+------------------------------------------------------------------+    
//| Custom indicator initialization function                         | 
//+------------------------------------------------------------------+  
void OnInit()
  {
//---- èíèöèàëèçàöèÿ ïåðåìåííûõ íà÷àëà îòñ÷åòà äàííûõ
   min_rates_1=39;
   min_rates_total=min_rates_1+XMA1.GetStartBars(XMA_Method,XMA_Lengh,XMA_Phase);
//---- ïðåâðàùåíèå äèíàìè÷åñêîãî ìàññèâà IndBuffer â èíäèêàòîðíûé áóôåð
   SetIndexBuffer(0,IndBuffer,INDICATOR_DATA);
//---- ïðåâðàùåíèå äèíàìè÷åñêîãî ìàññèâà â öâåòîâîé, èíäåêñíûé áóôåð   
   SetIndexBuffer(1,ColorIndBuffer,INDICATOR_COLOR_INDEX);
//---- îñóùåñòâëåíèå ñäâèãà íà÷àëà îòñ÷åòà îòðèñîâêè èíäèêàòîðà
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);
//---- óñòàíîâêà çíà÷åíèé èíäèêàòîðà, êîòîðûå íå áóäóò âèäèìû íà ãðàôèêå
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
//---- óñòàíîâêà àëåðòîâ íà íåäîïóñòèìûå çíà÷åíèÿ âíåøíèõ ïåðåìåííûõ
   XMA1.XMALengthCheck("Fast_XMA",XMA_Phase);
//---- óñòàíîâêà àëåðòîâ íà íåäîïóñòèìûå çíà÷åíèÿ âíåøíèõ ïåðåìåííûõ
   XMA1.XMAPhaseCheck("Phase",XMA_Phase,XMA_Method);
//--- ñîçäàíèå èìåíè äëÿ îòîáðàæåíèÿ â îòäåëüíîì ïîäîêíå è âî âñïëûâàþùåé ïîäñêàçêå
   IndicatorSetString(INDICATOR_SHORTNAME,"FatlMacd");
//--- îïðåäåëåíèå òî÷íîñòè îòîáðàæåíèÿ çíà÷åíèé èíäèêàòîðà
   IndicatorSetInteger(INDICATOR_DIGITS,0);
//---- çàâåðøåíèå èíèöèàëèçàöèè
  }
//+------------------------------------------------------------------+  
//| Custom indicator iteration function                              | 
//+------------------------------------------------------------------+  
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[])
  {
//---- ïðîâåðêà êîëè÷åñòâà áàðîâ íà äîñòàòî÷íîñòü äëÿ ðàñ÷åòà
   if(rates_total<min_rates_total) return(0);
//---- îáúÿâëåíèå öåëî÷èñëåííûõ ïåðåìåííûõ
   int first,bar;
//---- îáúÿâëåíèå ïåðåìåííûõ ñ ïëàâàþùåé òî÷êîé  
   double price,fatl,macd;
//---- èíèöèàëèçàöèÿ èíäèêàòîðà â áëîêå OnCalculate()
   if(prev_calculated>rates_total || prev_calculated<=0)// ïðîâåðêà íà ïåðâûé ñòàðò ðàñ÷åòà èíäèêàòîðà
     {
      first=0; // ñòàðòîâûé íîìåð äëÿ ðàñ÷åòà âñåõ áàðîâ ïåðâîãî öèêëà
     }
   else // ñòàðòîâûé íîìåð äëÿ ðàñ÷åòà íîâûõ áàðîâ
     {
      first=prev_calculated-1;
     }
//---- îñíîâíîé öèêë ðàñ÷åòà èíäèêàòîðà
   for(bar=first; bar<rates_total && !IsStopped(); bar++)
     {
      //---- ïîëó÷àåì âõîäíóþ öåíó price
      price=PriceSeries(AppliedPrice,bar,open,low,high,close);
      //---- ãðóçèì âõîäíóþ öåíó price â FATLSeries() è ïîëó÷àåì fatl
      fatl=FATL1.FATLSeries(0,prev_calculated,rates_total,price,bar,false);
      //---- ïîëó÷èì MACD
      macd=price-fatl;
      //---- ãðóçèì macd â XMASeries() äëÿ óñðåäíåíèÿ
      IndBuffer[bar]=XMA1.XMASeries(min_rates_1,prev_calculated,rates_total,XMA_Method,XMA_Phase,XMA_Lengh,macd,bar,false);
      //---- ìåíÿåì ðàçìåðíîñòü èíäèêàòîðà äî öåëûõ çíà÷åíèé
      IndBuffer[bar]/=_Point;
     }
//----
   if(prev_calculated>rates_total || prev_calculated<=0) first++;
//---- îñíîâíîé öèêë ðàñêðàñêè èíäèêàòîðà
   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 ---