Indicators Used
Accumulation/Distribution indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
6 Views
0 Downloads
0 Favorites
CHO_4CZ
//+----------------------------------------------------------------------------+
//|               CHO_4CZ                           Custom CHO_4CZ.mq4         |
//|                      Copyright © 2004, MetaQuotes Software Corp.           |
//|       mod. from ASilver CHO534     http://www.metaquotes.net/ik            |
//| mod. from MACD_4CZ    4colors  up/dn over/under zero;    www.forexTSD.com  |
//|            CHO_4CZ    4colors  up/dn over/under zero;  eXaR, 06/2011       |
//+----------------------------------------------------------------------------+
#property  copyright "Copyright © 2004, MetaQuotes Software Corp."
#property  link      "http://www.metaquotes.net/" 

//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 5
#property  indicator_color1  Lime
#property  indicator_color2  Maroon
#property  indicator_color3  Red
#property  indicator_color4  DarkGreen
#property  indicator_color5  Silver
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2
#property indicator_width4 2
#property indicator_width5 2
#property indicator_level1 2000
#property indicator_level2 4000
#property indicator_level3 8000
#property indicator_level4 0
#property indicator_level5 -8000
#property indicator_level6 -2000
#property indicator_level7 -4000
#property indicator_levelcolor SlateGray
#property indicator_levelstyle 2

//---- indicator parameters
extern int       SlowPeriod=10;
extern int       FastPeriod=3;
extern int       TypeSmooth=1;// 0 - SMA, 1 - EMA
//---- indicator buffers
double green_buffer[];
double DarkGreen_buffer[];
double red_buffer[];
double Maroon_buffer[];
double CHO[];
double AD[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {

//---- drawing settings
   IndicatorBuffers(6);
   SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID);
   SetIndexBuffer(0,green_buffer);
//----
   SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID);
   SetIndexBuffer(1,DarkGreen_buffer);
//----
   SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID);
   SetIndexBuffer(2,red_buffer);
//----
   SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID);
   SetIndexBuffer(3,Maroon_buffer);

   SetIndexStyle(4,DRAW_LINE,STYLE_SOLID);
   SetIndexBuffer(4,CHO);
//----
   SetIndexStyle(5,DRAW_NONE);
   SetIndexBuffer(5,AD);

   IndicatorDigits(Digits+1);
//---- name for DataWindow and indicator subwindow label
   string name,smoothString;
   if(TypeSmooth<0 || TypeSmooth>1) TypeSmooth=0;
   if(TypeSmooth==0) smoothString="SMA"; else smoothString="EMA";
   name="Chaikin Oscillator("+SlowPeriod+","+FastPeriod+","+smoothString+")";

   IndicatorShortName(name);
   SetIndexLabel(0,name);
   SetIndexLabel(1,name);
   SetIndexLabel(2,name);
   SetIndexLabel(3,name);
   SetIndexLabel(4,name);
   SetIndexLabel(5,name);
   SetIndexLabel(6,name);

//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Chaikin Oscillator                                               |
//+------------------------------------------------------------------+
int start()
  {
   int i;
   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars;
   if(counted_bars==0) limit-=1+1;

   for(i=limit;i>=0;i--)
     {
      AD[i]=iAD(NULL,0,i);
     }
   for(i=limit;i>=0;i--)
     {
      CHO[i]=iMAOnArray(AD,0,FastPeriod,0,TypeSmooth,i)-iMAOnArray(AD,0,SlowPeriod,0,TypeSmooth,i);
     }

//-----------ðàñêðàñêà--------------//
   for(i=limit;i>=0;i--)
     {
      green_buffer[i]=0;
      DarkGreen_buffer[i]=0;
      red_buffer[i]=0;
      Maroon_buffer[i]=0;
      if(CHO[i]>0)
        {
         if(CHO[i]>=CHO[i+1])
           {
            green_buffer[i]=CHO[i];
            DarkGreen_buffer[i]=0;
           }
         else
           {
            DarkGreen_buffer[i]=CHO[i];
            green_buffer[i]=0;
           }
        }
      else
        {
         if(CHO[i]<CHO[i+1])
           {
            red_buffer[i]=CHO[i];
            Maroon_buffer[i]=0;
           }
         else
           {
            Maroon_buffer[i]=CHO[i];
            red_buffer[i]=0;
           }
        }

     } //end for      
//---- done
   return(0);
  }
//+------------------------------------------------------------------+

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