Weighted WCCI

Author: © 2019, Alexey Viktorov
Indicators Used
Commodity channel indexIndicator of the average true range
0 Views
0 Downloads
0 Favorites
Weighted WCCI
ÿþ//+------------------------------------------------------------------+

//|                                                Weighted WCCI.mq5 |

//|                                          © 2019, Alexey Viktorov |

//|                     https://www.mql5.com/ru/users/alexeyvik/news |

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

#property copyright "© 2019, Alexey Viktorov"

#property link      "https://www.mql5.com/ru/users/alexeyvik/news"

#property version   "1.00"

#property indicator_separate_window

#property indicator_buffers 6

#property indicator_plots   3

#property indicator_type1   DRAW_LINE

#property indicator_label1  "Turbo CCI"

#property indicator_color1  clrRed

#property indicator_type2   DRAW_LINE

#property indicator_label2  "CCI"

#property indicator_color2  clrMediumOrchid

#property indicator_width2  2

#property indicator_type3   DRAW_HISTOGRAM

#property indicator_label3  "CCI"

#property indicator_color3  clrCadetBlue



input int       TCCIp       = 7;      //  Turbo CCI

input int       CCIp        = 24;     //  Fast CCI

input double    overbslevel = 200.0;  //  Max level

input double    triglevel   = 50.0;   //  Min level

input double    weight      = 1.0;    //  

//---

int handle_Turbo_CCI

   ,handle_CCI

   ,handle_ATR_7

   ,handle_ATR_49

;

/****************indicator buffers****************/

double turboBuf[];

double cciLineBuf[];

double cciHistoBuf[];

double calc_TurboCCI[];

double calc_CCI[];

double calc_ATR_7[];

double calc_ATR_49[];

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,turboBuf,INDICATOR_DATA);

   SetIndexBuffer(1,cciLineBuf,INDICATOR_DATA);

   SetIndexBuffer(2,cciHistoBuf,INDICATOR_DATA);

   SetIndexBuffer(3,calc_TurboCCI,INDICATOR_CALCULATIONS);

   SetIndexBuffer(4,calc_ATR_7,INDICATOR_CALCULATIONS);

   SetIndexBuffer(5,calc_ATR_49,INDICATOR_CALCULATIONS);

   IndicatorSetInteger(INDICATOR_LEVELS,5);

   IndicatorSetDouble(INDICATOR_LEVELVALUE,0,0.0);

   IndicatorSetDouble(INDICATOR_LEVELVALUE,1,triglevel);

   IndicatorSetDouble(INDICATOR_LEVELVALUE,2,-triglevel);

   IndicatorSetDouble(INDICATOR_LEVELVALUE,3,overbslevel);

   IndicatorSetDouble(INDICATOR_LEVELVALUE,4,-overbslevel);

   IndicatorSetInteger(INDICATOR_LEVELSTYLE,0,STYLE_DASH);

   IndicatorSetInteger(INDICATOR_LEVELSTYLE,1,STYLE_DASH);

   IndicatorSetInteger(INDICATOR_LEVELSTYLE,2,STYLE_DASH);

   IndicatorSetInteger(INDICATOR_LEVELWIDTH,3,2);

   IndicatorSetInteger(INDICATOR_LEVELWIDTH,4,2);

   IndicatorSetInteger(INDICATOR_LEVELCOLOR,0,clrPaleGreen);

   IndicatorSetInteger(INDICATOR_LEVELCOLOR,1,clrRoyalBlue);

   IndicatorSetInteger(INDICATOR_LEVELCOLOR,2,clrRoyalBlue);

   IndicatorSetInteger(INDICATOR_LEVELCOLOR,3,clrRed);

   IndicatorSetInteger(INDICATOR_LEVELCOLOR,4,clrRed);

//---

   handle_Turbo_CCI = iCCI(_Symbol, PERIOD_CURRENT, TCCIp, PRICE_TYPICAL);

   handle_CCI       = iCCI(_Symbol, PERIOD_CURRENT, CCIp, PRICE_TYPICAL);

   handle_ATR_7     = iATR(_Symbol, PERIOD_CURRENT, 7);

   handle_ATR_49    = iATR(_Symbol, PERIOD_CURRENT, 49);

   return(INIT_SUCCEEDED);

  }

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

//| 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-prev_calculated>1) // A;8 ?5@2K9 70?CA: 8=48:0B>@0, 8;8 ?>43@C65=K ?@>?CI5==K5 10@K

     {

      if(CopyBuffer(handle_Turbo_CCI,0,0,rates_total,calc_TurboCCI)<=0 || 

         CopyBuffer(handle_CCI,0,0,rates_total,calc_CCI)<=0 || 

         CopyBuffer(handle_ATR_7,0,0,rates_total,calc_ATR_7)<=0 || 

         CopyBuffer(handle_ATR_49,0,0,rates_total,calc_ATR_49)<=0

         ) return(0);

      for(int i=0; i<rates_total; i++)

        {

         FillingBuffers(i);

        }

     }

   else

     {

      if(CopyBuffer(handle_Turbo_CCI,0,0,rates_total,calc_TurboCCI)<=0 || 

         CopyBuffer(handle_CCI,0,0,rates_total,calc_CCI)<=0 || 

         CopyBuffer(handle_ATR_7,0,0,rates_total,calc_ATR_7)<=0 || 

         CopyBuffer(handle_ATR_49,0,0,rates_total,calc_ATR_49)<=0

         ) return(0);

      FillingBuffers(rates_total-1);

     }

//--- return value of prev_calculated for next call

   return(rates_total);

  }

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



void FillingBuffers(const int i)

  {

   double kw = 0.0;

   if(weight == 0)

      kw=0.0;

   else

     {

      kw=weight*calc_ATR_7[i]/calc_ATR_49[i];

      calc_TurboCCI[i]  = calc_TurboCCI[i]*kw;

      calc_CCI[i]       = calc_CCI[i]*kw;

     }

   turboBuf[i]=calc_TurboCCI[i]>overbslevel+50 ? overbslevel+50 :

               calc_TurboCCI[i]<-overbslevel-50 ? -overbslevel-50 :

               calc_TurboCCI[i];

   cciLineBuf[i]=calc_CCI[i]>overbslevel+50 ? overbslevel+50 :

                 calc_CCI[i]<-overbslevel-50 ? -overbslevel-50 :

                 calc_CCI[i];

   cciHistoBuf[i]=calc_CCI[i]>overbslevel+50 ? overbslevel+50 :

                  calc_CCI[i]<-overbslevel-50 ? -overbslevel-50 :

                  calc_CCI[i];

  }

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

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