CCI_smoothed

Author: Yuriy Tokman (YTG)
Indicators Used
Commodity channel indexMoving average indicator
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
CCI_smoothed
//+------------------------------------------------------------------+
//|                                                 CCI_smoothed.mq4 |
//|                                               Yuriy Tokman (YTG) |
//|                                               http://ytg.com.ua/ |
//+------------------------------------------------------------------+
#property copyright "Yuriy Tokman (YTG)"
#property link      "http://ytg.com.ua/"
#property version   "1.00"
#property strict
#property indicator_separate_window

#property indicator_buffers 2
#property indicator_color2 clrDarkViolet
#property indicator_level1    -100.0
#property indicator_level2     100.0
#property indicator_levelcolor clrSilver
#property indicator_levelstyle STYLE_DOT


input int                CCI_Period   = 14;
input ENUM_APPLIED_PRICE CCI_Price    = 0;
input int                Period_Smoothed=9;
input ENUM_MA_METHOD     MA_Method=0;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
string name="";
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   name="CCI_smoothed";
   IndicatorShortName(name);

   SetIndexStyle(0,DRAW_NONE);
   SetIndexBuffer(0,ExtMapBuffer1);

   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexLabel(1,name);
   SetIndexDrawBegin(1,CCI_Period+Period_Smoothed);
//---
   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[])
  {
//---
   int limit=rates_total /*- CCI_Period*/-prev_calculated;
   if(prev_calculated==0)limit--;
   else  limit++;
   double ma=0;
   for( int i=0; i<limit && !IsStopped(); i++) ExtMapBuffer1[i] = iCCI(NULL, 0, CCI_Period, CCI_Price,i);
   for( int i=0; i<limit && !IsStopped(); i++)
      ExtMapBuffer2[i]=iMAOnArray(ExtMapBuffer1,0,Period_Smoothed,0,MA_Method,i);
//--- return value of prev_calculated for next call
   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 ---