Elliot oscillator simple

Author: © mladen, 2018
Price Data Components
0 Views
0 Downloads
0 Favorites
Elliot oscillator simple
ÿþ//+------------------------------------------------------------------

#property copyright   "© mladen, 2018"

#property link        "mladenfx@gmail.com"

#property version     "1.00"

#property description "Elliot oscillator"

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

#property indicator_separate_window

#property indicator_buffers 4

#property indicator_plots   2



#property indicator_label1  "Elliot oscillator fill"

#property indicator_type1   DRAW_FILLING

#property indicator_color1  C'209,243,209',C'255,230,183'

#property indicator_label2  "Elliot oscillator"

#property indicator_type2   DRAW_COLOR_LINE

#property indicator_color2  clrSilver,clrLimeGreen,clrOrange

#property indicator_width2  2

//

//---

//

input int                FastPeriod      = 5;              // Fast period

input int                SlowPeriod      = 34;             // Slow period

input ENUM_APPLIED_PRICE Price           = PRICE_MEDIAN;   // Price



double val[],valc[],fill1[],fill2[];



//------------------------------------------------------------------

//

//------------------------------------------------------------------

//

//

//

//

//



int OnInit()

{

   SetIndexBuffer(0,fill1  ,INDICATOR_DATA);

   SetIndexBuffer(1,fill2  ,INDICATOR_DATA);

   SetIndexBuffer(2,val    ,INDICATOR_DATA);

   SetIndexBuffer(3,valc   ,INDICATOR_COLOR_INDEX);

   IndicatorSetString(INDICATOR_SHORTNAME,"Elliot oscillator ("+(string)FastPeriod+","+(string)SlowPeriod+")");

   return(0);

}



//------------------------------------------------------------------

//

//------------------------------------------------------------------

//

//

//

//

//



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 (Bars(_Symbol,_Period)<rates_total) return(-1);

   int i=(int)MathMax(prev_calculated-1,0); for (; i<rates_total && !_StopFlag; i++)

   {

      double price = getPrice(Price,open,close,high,low,i,rates_total);

            val[i]     = iSma(price,FastPeriod,i,rates_total,0)-iSma(price,SlowPeriod,i,rates_total,1);

            fill1[i] = val[i];

            fill2[i] = 0;

   }

   return(i);

}





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

//| Custom functions                                                 |

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

#define _maInstances 2

#define _maWorkBufferx1 1*_maInstances

//

//---

//

double workSma[][_maWorkBufferx1];

double iSma(double price, int period, int r, int _bars, int instanceNo=0)

{

   if (ArrayRange(workSma,0)!= _bars) ArrayResize(workSma,_bars); int k=1;



   workSma[r][instanceNo+0] = price;

   double avg = price; for(; k<period && (r-k)>=0; k++) avg += workSma[r-k][instanceNo+0];  avg /= (double)k;

   return(avg);

}



//

//---

//

double getPrice(ENUM_APPLIED_PRICE tprice,const double &open[],const double &close[],const double &high[],const double &low[],int i,int _bars)

  {

   switch(tprice)

     {

      case PRICE_CLOSE:     return(close[i]);

      case PRICE_OPEN:      return(open[i]);

      case PRICE_HIGH:      return(high[i]);

      case PRICE_LOW:       return(low[i]);

      case PRICE_MEDIAN:    return((high[i]+low[i])/2.0);

      case PRICE_TYPICAL:   return((high[i]+low[i]+close[i])/3.0);

      case PRICE_WEIGHTED:  return((high[i]+low[i]+close[i]+close[i])/4.0);

     }

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