Author: Raul Canessa Castañeda
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
Chande
ÿþ//+------------------------------------------------------------------+

//|                                                       Chande.mq4 |

//|                                           Raul Canessa Castañeda |

//|                                   https://www.forexdominion.com/ |

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

#property copyright "Raul Canessa Castañeda"

#property link      "https://www.forexdominion.com/"

#property version   "1.00"

#property strict

#property description "Chande oscillator created for illustration purposes. "

                      "If you are interested in automating your strategies "

                      "or create a custom technical indicator, you can contact us at rcanessa@gmail.com. "

                      

                      "More information at www.forexdominion.com"

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

//| Chande indicator initialization function                         |

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

#property indicator_separate_window  //Indicator is shown in a separate window

#property indicator_buffers 2     //Number of indicator buffers 2

#property indicator_color1 Blue   //Indicator color blue

#property indicator_color2 Red   //Indicator color red



//Indicator main levels

#property indicator_level1 50         //Overbought level

#property indicator_levelcolor Gray   //Level color

#property indicator_level2 -50        //Oversold level

#property indicator_levelcolor Gray   //Level color

#property indicator_level3 0          //Zero level

#property indicator_levelcolor Gray  //Level color

#property indicator_maximum 100      //Maximum indicator level

#property indicator_minimum -100     //Minimum indicator level



input ENUM_APPLIED_PRICE  Precio_Aplicado=0;  //Price Applied in the Calculation

//Here the trader can choose between the closing price (0), opening price (1)

//maximum price (2), minimum price (3), median price (4), typical price (5) and

//weighted price (6)

extern int Periodos_Chande=20;   //Chande Oscillator Period

extern int Periodo_MA=9;        //Oscillator Moving Average Period

input ENUM_MA_METHOD Metodo_MA=MODE_SMA;     //Moving Average Calculation Method

//By default the simple moving average (SMA) is used.

//But we also include the possibility of using other moving averages, such as the SMA, EMA, etc.



//Arrays used in the indicator buffers

double Chande_[];              //Chande Oscillator Array

double MA_Chande[];            //Chande Oscillator Moving Average

double Tipo_Precio[];          //Price Type Array



int OnInit()

  {

   IndicatorBuffers(3);

   SetIndexBuffer(0,Chande_);

   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2,clrDodgerBlue);

   SetIndexBuffer(1,MA_Chande);

   SetIndexStyle(1,DRAW_LINE,STYLE_DOT,1,clrRed);

   SetIndexBuffer(2,Tipo_Precio);

   

   ObjectCreate("Label_Tecnicas", OBJ_LABEL, 0, 0, 0);  //Forexdominion tag creation

   ObjectSet("Label_Tecnicas", OBJPROP_CORNER, 0);    // Reference corner

   ObjectSet("Label_Tecnicas", OBJPROP_XDISTANCE, 20);// X Axis

   ObjectSet("Label_Tecnicas", OBJPROP_YDISTANCE, 25);// Y Axis

   ObjectSetText("Label_Tecnicas","Chande Oscillator - ForexDominion.com",14,"Arial",Blue);

   

   //Indicator name

   string Name;

   Name="Chande(CMO) (" + Periodos_Chande + ")";

   IndicatorShortName(Name);

   

   return(INIT_SUCCEEDED);

  }

int deinit()

  {

   ObjectDelete("Label_Tecnicas");

   return(0);

  }    

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

//| Chande oscillator calculation 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[])

  {

   //Calculation variables

   int i;            //Index for the calculation of the indicator

   int cant_bars;    //Variable for counting bars by the indicator

   int n=0;          //Calculation variable

   int j;            //Calculation variable

   int Pr;           //Price calculation variable

   double SumaUP;    //Sum of closing differences for bullish periods

   double SumaDOWN;  //Sum of closing differences for bearish periods  

   //Bar count

   cant_bars=prev_calculated;                   //Indicator bar count

   i=rates_total-prev_calculated-1;             //Total number of bars used in the calculation

   if(i==Bars-1)

    {

     n=i-Periodos_Chande+1;

    }

   if(i==0)

    {

     n=0;

    } 

 //Price type used in the calculation of the indicator

   for(Pr=i;Pr>=0;Pr--)

    {

    //Price used for the calculation of the Chande oscillator

     if(Precio_Aplicado==0)

      Tipo_Precio[Pr]=Close[Pr];                 //Closing price

     if(Precio_Aplicado==1)                      

      Tipo_Precio[Pr]=Open[Pr];                  //Opening price

     if(Precio_Aplicado==2)

      Tipo_Precio[Pr]=High[Pr];                  //Maximum price

     if(Precio_Aplicado==3)

      Tipo_Precio[Pr]=Low[Pr];                   //Minimum price

     if(Precio_Aplicado==4)

      Tipo_Precio[Pr]=(High[Pr]+Low[Pr])/2;       //Median price

     if(Precio_Aplicado==5)

      Tipo_Precio[Pr]=(High[Pr]+Low[Pr]+Close[Pr])/3;     //Typical price

     if(Precio_Aplicado==6)

      Tipo_Precio[Pr]=(High[Pr]+Low[Pr]+Close[Pr]+Close[Pr])/4;  //Weighted price

    }    

   //Chande oscillator calculation

   while(n>=0)

    {

     SumaUP=0.00;

     SumaDOWN=0.00;   

     for(j=n+Periodos_Chande-2;j>=n;j--)

      {

       if(Tipo_Precio[j]>Tipo_Precio[j+1])

        SumaUP=(Tipo_Precio[j]-Tipo_Precio[j+1])+SumaUP;

       if(Tipo_Precio[j]<Tipo_Precio[j+1]) 

        SumaDOWN=MathAbs((Tipo_Precio[j]-Tipo_Precio[j+1]))+SumaDOWN; 

      }

     Chande_[n]=100*(SumaUP-SumaDOWN)/(SumaUP+SumaDOWN);                 //Chande oscillator formula  

     MA_Chande[n]=iMAOnArray(Chande_,0,Periodo_MA,0,Metodo_MA,n);        //Chande Oscillator Moving Average

     n--;

    }    

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