Author: Copyright 2015, Daisuke
Price Data Components
Series array that contains the lowest prices of each barSeries array that contains the highest prices of each bar
0 Views
0 Downloads
0 Favorites
temasro
ÿþ//+------------------------------------------------------------------+

//| Widener's S/R oscillator with TEMA                               |

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

#property copyright "Copyright 2015,  Daisuke"

#property link      "http://mt4program.blogspot.jp/"

#property version   "1.00"

#property strict



#include <Arrays/ArrayDouble.mqh>



#property indicator_separate_window

#property indicator_minimum    0

#property indicator_maximum    100

#property indicator_buffers 6

#property indicator_plots   2



#property indicator_label1  "Support"

#property indicator_type1   DRAW_LINE

#property indicator_color1  clrAqua

#property indicator_style1  STYLE_SOLID

#property indicator_width1  1



#property indicator_label2  "Resistance"

#property indicator_type2   DRAW_LINE

#property indicator_color2  clrIndianRed

#property indicator_style2  STYLE_SOLID

#property indicator_width2  1



#property indicator_type3   DRAW_NONE

#property indicator_type4   DRAW_NONE

#property indicator_type5   DRAW_NONE

#property indicator_type6   DRAW_NONE



input int Period=6;  //WSRO Period

input int HLPeriod=9; //WSRO High Low Period

input double Alfa=0.1; // TEMA Alfa

input ENUM_APPLIED_PRICE MaPrice=PRICE_CLOSE; // TEMA target price



double tema[];

// EMA

double ema1[];

// EMA EMA

double ema2[];

// EMA EMA EMA

double ema3[];

double wsoBuffer[];

double wroBuffer[];



//S1-Sn

CArrayDouble supports;

//R1-Rn

CArrayDouble resistances;

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

//| Initialize                                                       |

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

int OnInit()

  {

   if( HLPeriod % 2 == 0 || HLPeriod < 5) return (INIT_PARAMETERS_INCORRECT);

   if( Period < 3 ) return (INIT_PARAMETERS_INCORRECT);



   SetIndexBuffer(0,wsoBuffer);

   SetIndexBuffer(1,wroBuffer);

   SetIndexBuffer(2,tema);

   SetIndexBuffer(3,ema1);

   SetIndexBuffer(4,ema2);

   SetIndexBuffer(5,ema3);



   SetIndexDrawBegin(0,HLPeriod+1);

   SetIndexDrawBegin(1,HLPeriod+1);



   supports.Clear();

   supports.Resize(Period);

   resistances.Clear();

   resistances.Resize(Period);



   string short_name="T_WSRO( "+IntegerToString(Period)+" , "+IntegerToString(HLPeriod)+" )";

   IndicatorShortName(short_name);



   return(INIT_SUCCEEDED);

  }

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

//| Caliculate                                                       |

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

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[])

  {

   static datetime lastCalculate=0;



   for(int i=(rates_total-prev_calculated-1); i>=0; i--)

     {

      double price=GetPrice(open[i],close[i],high[i],low[i],MaPrice);

      if(i==(rates_total-1))

        {

         ema1[i] = price;

         ema2[i] = price;

         ema3[i] = price;

         tema[i] = price;

        }



      if(i>=rates_total-Period-2)

        {

         wsoBuffer[i] = 0;

         wroBuffer[i] = 0;

         continue;

        }

      ema1[i] = Alfa * price + ( 1 - Alfa ) * ema1[i + 1];

      ema2[i] = Alfa * ema1[i] + ( 1 - Alfa ) * ema2[i + 1];

      ema3[i] = Alfa * ema2[i] + ( 1 - Alfa ) * ema3[i + 1];

      tema[i] = ema1[i] * 3 - ema2[i] * 3 + ema3[i];



      if(lastCalculate!=time[i])

        {

         lastCalculate=time[i];

         int centerIndex=i+1+(HLPeriod-1)/2;

         //supports

         //if Low( four days back ) = Min(lows of previous nine days) then SL=Low(four days back)

         if(iLowest(NULL,PERIOD_CURRENT,MODE_LOW,HLPeriod,i+1)==centerIndex)

           {

            if(supports.Total()>=Period)

              {

               supports.Delete(supports.Total()-1);

              }

            supports.Insert(iLow(NULL,PERIOD_CURRENT,centerIndex),0);

           }

         //regist

         //if High( four days back ) = Max(high of previous nine days) then RL=High(four days back)

         if(iHighest(NULL,PERIOD_CURRENT,MODE_HIGH,HLPeriod,i+1)==centerIndex)

           {

            if(resistances.Total()>=Period)

              {

               resistances.Delete(resistances.Total()-1);

              }

            resistances.Insert(iHigh(NULL,PERIOD_CURRENT,centerIndex),0);

           }

        }



      double closeDiv=tema[i];

      //wso 1 - ((int)S1/C + (int)S2/C +(int)S3/C +(int)S4/C +(int)S5/C +(int)S6/C) / 6

      if(closeDiv!=0 && supports.Total()==Period)

        {

         double wso = 0;

         for( int j = 0; j < supports.Total(); j++ )

           {

            wso+=(int)(supports.At(j)/closeDiv);

           }

         wsoBuffer[i]=(1-wso/supports.Total())*100;

        }

      else

        {

         wsoBuffer[i]=0;

        }



      if(closeDiv!=0 && resistances.Total()==Period)

        {

         //wro 1 - ((int)R1/C + (int)R2/C +(int)R3/C +(int)R4/C +(int)R5/C +(int)R6/C) / 6

         double wro = 0;

         for( int j = 0; j < resistances.Total(); j++ )

           {

            wro+=(int)(resistances.At(j)/closeDiv);

           }

         wroBuffer[i]=(1-wro/resistances.Total())*100;

        }

      else

        {

         wroBuffer[i]=0;

        }

     }



   return(rates_total - 1);

  }

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

//| Caliculate Price Value                                           |

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

double GetPrice(double open,

                double close,

                double high,

                double low,

                ENUM_APPLIED_PRICE maPrice)

  {

   double price=0;



   switch(maPrice)

     {

      case PRICE_CLOSE:

         price=close;

         break;

      case PRICE_OPEN:

         price=open;

         break;

      case PRICE_HIGH:

         price=high;

         break;

      case PRICE_LOW:

         price=low;

         break;

      case PRICE_MEDIAN:

         price=(high+low)/2;

         break;

      case PRICE_TYPICAL:

         price=(high+low+close)/3;

         break;

      case PRICE_WEIGHTED:

         price=(high+low+close+close)/4;

         break;

     }

   return price;

  }

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

Comments