VWAP_Classic_m

Author: Roman
Price Data Components
Series array that contains open time of each bar
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
VWAP_Classic_m
ÿþ//+------------------------------------------------------------------+

//|                                                 VWAP_Classic.mq4 |

//|                                                                  |

//|                                                                  |

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

#property strict

#property version     "1.0"

#property copyright   "Roman"

#property link        "romankiverin@yandex.ru"



#property description "If you like the indicator, you can thank the author"

#property description "Webmoney: Z330494414179, R222585888867" 

#property description " " 

#property description "Thank you very much."



#property indicator_chart_window

#property indicator_buffers 26



#property indicator_color1 Red

#property indicator_color2 Yellow



#property indicator_color3 Blue

#property indicator_color4 Blue

#property indicator_color5 Blue

#property indicator_color6 Blue

#property indicator_color7 Blue

#property indicator_color8 Blue

#property indicator_color9 Blue

#property indicator_color10 Blue



#property indicator_color11 Tomato

#property indicator_color12 Tomato

#property indicator_color13 Tomato

#property indicator_color14 Tomato

#property indicator_color15 Tomato

#property indicator_color16 Tomato

#property indicator_color17 Tomato

#property indicator_color18 Tomato



#property indicator_width1 3

#property indicator_width2 2



#property indicator_width3 1

#property indicator_width4 1

#property indicator_width5 1

#property indicator_width6 1

#property indicator_width7 1

#property indicator_width8 1

#property indicator_width9 1

#property indicator_width10 1



#property indicator_width11 1

#property indicator_width12 1

#property indicator_width13 1

#property indicator_width14 1

#property indicator_width15 1

#property indicator_width16 1

#property indicator_width17 1

#property indicator_width18 1



extern int Shift_in_Minutes = 30;//Shift in Minutes

extern int Count_Of_Plot=4000;//Value Draw Bars



extern bool Break_Day=true;//Break Day Line

extern bool Break_Week=true;//Break Week Line



extern bool Show_Day=true;//Show Days

extern bool Show_Week=true;//Show Weeks



extern bool Show_DayDiv=true;//Show Days StDiv

extern bool Show_WeekDiv=true;//Show Weeks StDiv



extern string Key_Show_Day="Q";//Key Show Day

extern string Key_Show_Week="W";//Key Show Week



extern string Key_Show_DayDiv="E";//Key Show Day StDiv

extern string Key_Show_WeekDiv="R";//Key Show Week StDiv

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

//|                                                                  |

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

void OnChartEvent(const int id,

                  const long &lparam,

                  const double &dparam,

                  const string &sparam)

  {

   if(id==CHARTEVENT_KEYDOWN)

     {

      if((int)lparam==StringGetChar(Key_Show_Day,0))

        {

         Show_Day=!Show_Day;

         Draw(Count_Of_Plot);

         ChartRedraw();

        }



      if((int)lparam==StringGetChar(Key_Show_Week,0))

        {

        Show_Week=!Show_Week;

         Draw(Count_Of_Plot);

         ChartRedraw();

        }



      if((int)lparam==StringGetChar(Key_Show_DayDiv,0))

        {

         Show_DayDiv=!Show_DayDiv;

         Draw(Count_Of_Plot);

         ChartRedraw();

        }



      if((int)lparam==StringGetChar(Key_Show_WeekDiv,0))

        {

         Show_WeekDiv=!Show_WeekDiv;

         Draw(Count_Of_Plot);

         ChartRedraw();

        }

     }

  }

double Day_[],Day_Vol[],Day_Typ[],Day_Avr[],Day_Num[],Day_Up1[],Day_Up2[],Day_Up4[],Day_Up8[],

Week_[],Week_Vol[],Week_Typ[],Week_Avr[],Week_Num[],Day_Dn1[],Day_Dn2[],Day_Dn4[],Day_Dn8[],

Week_Up1[],Week_Up2[],Week_Up4[],Week_Up8[],Week_Dn1[],Week_Dn2[],Week_Dn4[],Week_Dn8[];

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

//| Custom indicator initialization function                         |

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

int init()

  {

   SetIndexBuffer(0,Week_);

   SetIndexStyle(0,DRAW_LINE);



   SetIndexBuffer(1,Day_);

   SetIndexStyle(1,DRAW_LINE);



   SetIndexBuffer(2,Week_Up1);

   SetIndexStyle(2,DRAW_LINE);



   SetIndexBuffer(3,Week_Up2);

   SetIndexStyle(3,DRAW_LINE);



   SetIndexBuffer(4,Week_Up4);

   SetIndexStyle(4,DRAW_LINE);



   SetIndexBuffer(5,Week_Up8);

   SetIndexStyle(5,DRAW_LINE);



   SetIndexBuffer(6,Week_Dn1);

   SetIndexStyle(6,DRAW_LINE);



   SetIndexBuffer(7,Week_Dn2);

   SetIndexStyle(7,DRAW_LINE);



   SetIndexBuffer(8,Week_Dn4);

   SetIndexStyle(8,DRAW_LINE);



   SetIndexBuffer(9,Week_Dn8);

   SetIndexStyle(9,DRAW_LINE);



   SetIndexBuffer(10,Day_Up1);

   SetIndexStyle(10,DRAW_LINE);



   SetIndexBuffer(11,Day_Up2);

   SetIndexStyle(11,DRAW_LINE);



   SetIndexBuffer(12,Day_Up4);

   SetIndexStyle(12,DRAW_LINE);



   SetIndexBuffer(13,Day_Up8);

   SetIndexStyle(13,DRAW_LINE);



   SetIndexBuffer(14,Day_Dn1);

   SetIndexStyle(14,DRAW_LINE);



   SetIndexBuffer(15,Day_Dn2);

   SetIndexStyle(15,DRAW_LINE);



   SetIndexBuffer(16,Day_Dn4);

   SetIndexStyle(16,DRAW_LINE);



   SetIndexBuffer(17,Day_Dn8);

   SetIndexStyle(17,DRAW_LINE);



   SetIndexBuffer(18,Week_Vol);

   SetIndexStyle(18,DRAW_NONE);



   SetIndexBuffer(19,Day_Vol);

   SetIndexStyle(19,DRAW_NONE);



   SetIndexBuffer(20,Week_Typ);

   SetIndexStyle(20,DRAW_NONE);



   SetIndexBuffer(21,Day_Typ);

   SetIndexStyle(21,DRAW_NONE);



   SetIndexBuffer(22,Day_Num);

   SetIndexStyle(22,DRAW_NONE);



   SetIndexBuffer(23,Day_Avr);

   SetIndexStyle(23,DRAW_NONE);



   SetIndexBuffer(24,Week_Num);

   SetIndexStyle(24,DRAW_NONE);



   SetIndexBuffer(25,Week_Avr);

   SetIndexStyle(25,DRAW_NONE);



   SetIndexEmptyValue(0,-1);

   SetIndexEmptyValue(1,-1);



   return(0);

  }

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

//|                                                                  |

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

void Draw(int limit)

  {

   int i,k;

   double b,d;

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

     {

      if(Show_Day)

        {

         if(TimeDay(iTime(NULL,NULL,i)+Shift_in_Minutes*60)==TimeDay(iTime(NULL,NULL,i+1)+Shift_in_Minutes*60))

           {

            Day_Vol[i]= Day_Vol[i+1]+Volume[i];

            Day_Typ[i]= Day_Typ[i+1]+(High[i]+Low[i]+Close[i]) * Volume[i]/3;

            Day_[i]=Day_Typ[i]/Day_Vol[i];

            Day_Num[i] = Day_Num[i+1] + 1;

            Day_Avr[i] = Day_Avr[i+1] + Day_[i];



            if(Show_DayDiv)

              {

               d=0; b=Day_Avr[i]/Day_Num[i];



               for(k=i; k<i+(int)Day_Num[i]; k++) d=d+MathPow(Day_[k]!=-1? Day_[k]-b : Day_Typ[k]/Day_Vol[k]-b,2);



               d=MathSqrt(d/Day_Num[i]);



               Day_Up1[i] = Day_[i] + d;

               Day_Up2[i] = Day_[i] + 2*d;

               Day_Up4[i] = Day_[i] + 4*d;

               Day_Up8[i] = Day_[i] + 8*d;

               Day_Dn1[i] = Day_[i] - d;

               Day_Dn2[i] = Day_[i] - 2*d;

               Day_Dn4[i] = Day_[i] - 4*d;

               Day_Dn8[i] = Day_[i] - 8*d;

              }

            else

              {

               Day_Up2[i] = 2147483647.0;

               Day_Up4[i] = 2147483647.0;

               Day_Up8[i] = 2147483647.0;

               Day_Dn1[i] = 2147483647.0;

               Day_Dn2[i] = 2147483647.0;

               Day_Dn4[i] = 2147483647.0;

               Day_Dn8[i] = 2147483647.0;

              }

           }

         else

           {

            Day_Vol[i]=Volume[i]>0 ? Volume[i]:1.0;

            Day_Typ[i] = (High[i] + Low[i] + Close[i]) * Day_Vol[i] / 3;

            Day_Num[i] = 1.0;

            Day_Avr[i] = (High[i] + Low[i] + Close[i]) / 3;

            if(!Break_Day)

              {

               Day_[i]=Day_Typ[i]/Day_Vol[i];

               if(Show_DayDiv)

                 {

                  Day_Up1[i] = Day_[i];

                  Day_Up2[i] = Day_[i];

                  Day_Up4[i] = Day_[i];

                  Day_Up8[i] = Day_[i];

                  Day_Dn1[i] = Day_[i];

                  Day_Dn2[i] = Day_[i];

                  Day_Dn4[i] = Day_[i];

                  Day_Dn8[i] = Day_[i];

                 }

               else

                 {

                  Day_Up2[i] = 2147483647.0;

                  Day_Up4[i] = 2147483647.0;

                  Day_Up8[i] = 2147483647.0;

                  Day_Dn1[i] = 2147483647.0;

                  Day_Dn2[i] = 2147483647.0;

                  Day_Dn4[i] = 2147483647.0;

                  Day_Dn8[i] = 2147483647.0;

                 }

              }

           }

        }

      else

        {

         Day_[i]=-1;

         Day_Up1[i] = 2147483647.0;

         Day_Up2[i] = 2147483647.0;

         Day_Up4[i] = 2147483647.0;

         Day_Up8[i] = 2147483647.0;

         Day_Dn1[i] = 2147483647.0;

         Day_Dn2[i] = 2147483647.0;

         Day_Dn4[i] = 2147483647.0;

         Day_Dn8[i] = 2147483647.0;

        }



      if(Show_Week)

        {

         if(TimeDayOfWeek(iTime(NULL,NULL,i)+Shift_in_Minutes*60)>=TimeDayOfWeek(iTime(NULL,NULL,i+1)+Shift_in_Minutes*60))

           {

            Week_Vol[i]= Week_Vol[i+1]+Volume[i];

            Week_Typ[i]= Week_Typ[i+1]+(High[i]+Low[i]+Close[i]) * Volume[i]/3;

            Week_[i]=Week_Typ[i]/Week_Vol[i];

            Week_Num[i] = Week_Num[i+1] + 1;

            Week_Avr[i] = Week_Avr[i+1] + Week_[i];



            if(Show_WeekDiv)

              {

               d=0; b=Week_Avr[i]/Week_Num[i];



               for(k=i; k<i+(int)Week_Num[i]; k++) d=d+MathPow(Week_[k]!=-1? Week_[k]-b : Week_Typ[k]/Week_Vol[k]-b,2);



               d=MathSqrt(d/Week_Num[i]);



               Week_Up1[i] = Week_[i] + d;

               Week_Up2[i] = Week_[i] + 2*d;

               Week_Up4[i] = Week_[i] + 4*d;

               Week_Up8[i] = Week_[i] + 8*d;

               Week_Dn1[i] = Week_[i] - d;

               Week_Dn2[i] = Week_[i] - 2*d;

               Week_Dn4[i] = Week_[i] - 4*d;

               Week_Dn8[i] = Week_[i] - 8*d;

              }

            else

              {

               Week_Up1[i] = 2147483647.0;

               Week_Up2[i] = 2147483647.0;

               Week_Up4[i] = 2147483647.0;

               Week_Up8[i] = 2147483647.0;

               Week_Dn1[i] = 2147483647.0;

               Week_Dn2[i] = 2147483647.0;

               Week_Dn4[i] = 2147483647.0;

               Week_Dn8[i] = 2147483647.0;

              }

           }

         else

           {

            Week_Vol[i]=Volume[i]>0 ? Volume[i]:1.0;

            Week_Typ[i] = (High[i] + Low[i] + Close[i]) * Week_Vol[i] / 3;

            Week_Num[i] = 1.0;

            Week_Avr[i] = (High[i] + Low[i] + Close[i]) / 3;

            if(!Break_Week)

              {

               Week_[i]=Week_Typ[i]/Week_Vol[i];

               if(Show_WeekDiv)

                 {

                  Week_Up1[i] = Week_[i];

                  Week_Up2[i] = Week_[i];

                  Week_Up4[i] = Week_[i];

                  Week_Up8[i] = Week_[i];

                  Week_Dn1[i] = Week_[i];

                  Week_Dn2[i] = Week_[i];

                  Week_Dn4[i] = Week_[i];

                  Week_Dn8[i] = Week_[i];

                 }

               else

                 {

                  Week_Up1[i] = 2147483647.0;

                  Week_Up2[i] = 2147483647.0;

                  Week_Up4[i] = 2147483647.0;

                  Week_Up8[i] = 2147483647.0;

                  Week_Dn1[i] = 2147483647.0;

                  Week_Dn2[i] = 2147483647.0;

                  Week_Dn4[i] = 2147483647.0;

                  Week_Dn8[i] = 2147483647.0;

                 }

              }

           }

        }

      else

        {

         Week_[i]=-1;

         Week_Up1[i] = 2147483647.0;

         Week_Up2[i] = 2147483647.0;

         Week_Up4[i] = 2147483647.0;

         Week_Up8[i] = 2147483647.0;

         Week_Dn1[i] = 2147483647.0;

         Week_Dn2[i] = 2147483647.0;

         Week_Dn4[i] = 2147483647.0;

         Week_Dn8[i] = 2147483647.0;

        }

     }

  }

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

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



   limit=rates_total-prev_calculated;



   limit=prev_calculated>0 ? limit++: limit-=2;



   limit=limit>Count_Of_Plot? Count_Of_Plot: limit;



   Draw(limit);



   return(rates_total);

  }

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

Comments