Time_Bar_Custom

Author: Copyright © 2018, Nikolay Kositsin
0 Views
0 Downloads
0 Favorites
Time_Bar_Custom
ÿþ//+------------------------------------------------------------------+

//|                                              Time_Bar_Custom.mq5 |

//|                               Copyright © 2018, Nikolay Kositsin | 

//|                              Khabarovsk,   farria@mail.redcom.ru | 

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

#property copyright "Copyright © 2018, Nikolay Kositsin"

#property link "farria@mail.redcom.ru"

//---- =><5@ 25@A88 8=48:0B>@0

#property version   "1.10"

//---- >B@8A>2:0 8=48:0B>@0 2 3;02=>< >:=5

#property indicator_chart_window 

//---- 4;O @0AGQB0 8 >B@8A>2:8 8=48:0B>@0 8A?>;L7>20=> 420 1CD5@0

#property indicator_buffers 2

//---- 8A?>;L7>20=> 2A53> >4=> 3@0D8G5A:>5 ?>AB@>5=85

#property indicator_plots   1

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

//|  0@0<5B@K >B@8A>2:8 8=48:0B>@0              |

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

//---- 2 :0G5AB25 8=48:0B>@0 8A?>;L7>20=K 10@K 38AB>3@0<<K

#property indicator_type1   DRAW_HISTOGRAM2

//---- 2 :0G5AB25 F25B0 ;8=88 8=48:0B>@0 8A?>;L7>20= BlueViolet F25B

#property indicator_color1 clrBlueViolet

//---- ;8=8O 8=48:0B>@0 - =5?@5@K2=0O :@820O

#property indicator_style1  STYLE_SOLID

//---- B>;I8=0 ;8=88 8=48:0B>@0 @02=0 4

#property indicator_width1  4

//---- >B>1@065=85 <5B:8 8=48:0B>@0

#property indicator_label1  "Time_Bar_Custom_Open;Time_Bar_Custom_High;Time_Bar_Custom_Low;Time_Bar_Custom_Close"

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

//|  1JO2;5=85 ?5@5G8A;5=8O G0A>2 ACB>:         |

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

enum HOURS

  {

   ENUM_HOUR_0=0,   //0

   ENUM_HOUR_1,     //1

   ENUM_HOUR_2,     //2

   ENUM_HOUR_3,     //3

   ENUM_HOUR_4,     //4

   ENUM_HOUR_5,     //5

   ENUM_HOUR_6,     //6

   ENUM_HOUR_7,     //7

   ENUM_HOUR_8,     //8

   ENUM_HOUR_9,     //9

   ENUM_HOUR_10,     //10

   ENUM_HOUR_11,     //11   

   ENUM_HOUR_12,     //12

   ENUM_HOUR_13,     //13

   ENUM_HOUR_14,     //14

   ENUM_HOUR_15,     //15

   ENUM_HOUR_16,     //16

   ENUM_HOUR_17,     //17

   ENUM_HOUR_18,     //18

   ENUM_HOUR_19,     //19

   ENUM_HOUR_20,     //20

   ENUM_HOUR_21,     //21  

   ENUM_HOUR_22,     //22

   ENUM_HOUR_23      //23    

  };

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

//|  1JO2;5=85 ?5@5G8A;5=8O <8=CB G0A>2         |

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

enum MINUTS

  {

   ENUM_MINUT_0=0,   //0

   ENUM_MINUT_1,     //1

   ENUM_MINUT_2,     //2

   ENUM_MINUT_3,     //3

   ENUM_MINUT_4,     //4

   ENUM_MINUT_5,     //5

   ENUM_MINUT_6,     //6

   ENUM_MINUT_7,     //7

   ENUM_MINUT_8,     //8

   ENUM_MINUT_9,     //9

   ENUM_MINUT_10,     //10

   ENUM_MINUT_11,     //11   

   ENUM_MINUT_12,     //12

   ENUM_MINUT_13,     //13

   ENUM_MINUT_14,     //14

   ENUM_MINUT_15,     //15

   ENUM_MINUT_16,     //16

   ENUM_MINUT_17,     //17

   ENUM_MINUT_18,     //18

   ENUM_MINUT_19,     //19

   ENUM_MINUT_20,     //20

   ENUM_MINUT_21,     //21  

   ENUM_MINUT_22,     //22

   ENUM_MINUT_23,     //23

   ENUM_MINUT_24,     //24

   ENUM_MINUT_25,     //25

   ENUM_MINUT_26,     //26

   ENUM_MINUT_27,     //27

   ENUM_MINUT_28,     //28

   ENUM_MINUT_29,     //29

   ENUM_MINUT_30,     //30

   ENUM_MINUT_31,     //31  

   ENUM_MINUT_32,     //32

   ENUM_MINUT_33,     //33

   ENUM_MINUT_34,     //34

   ENUM_MINUT_35,     //35

   ENUM_MINUT_36,     //36

   ENUM_MINUT_37,     //37

   ENUM_MINUT_38,     //38

   ENUM_MINUT_39,     //39 

   ENUM_MINUT_40,     //40

   ENUM_MINUT_41,     //41  

   ENUM_MINUT_42,     //42

   ENUM_MINUT_43,     //43

   ENUM_MINUT_44,     //44

   ENUM_MINUT_45,     //45

   ENUM_MINUT_46,     //46

   ENUM_MINUT_47,     //47

   ENUM_MINUT_48,     //48

   ENUM_MINUT_49,     //49

   ENUM_MINUT_50,     //50

   ENUM_MINUT_51,     //51  

   ENUM_MINUT_52,     //52

   ENUM_MINUT_53,     //53

   ENUM_MINUT_54,     //54

   ENUM_MINUT_55,     //55

   ENUM_MINUT_56,     //56

   ENUM_MINUT_57,     //57

   ENUM_MINUT_58,     //58

   ENUM_MINUT_59      //59             

  };

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

//| E>4=K5 ?0@0<5B@K 8=48:0B>@0                 |

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

input HOURS  BarHours=ENUM_HOUR_0;                 //@5<O CAB0=>2:8 10@0 ('0AK)

input MINUTS BarMinuts=ENUM_MINUT_0;               //@5<O CAB0=>2:8 10@0 (8=CBK)

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



//---- >1JO2;5=85 48=0<8G5A:8E <0AA82>2, :>B>@K5 1C4CB 2  40;L=59H5< 8A?>;L7>20=K 2 :0G5AB25 8=48:0B>@=KE 1CD5@>2

double ExtUpBuffer[],ExtDnBuffer[];

//---

int    min_rates_total;

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//---- 8=8F80;870F8O 3;>10;L=KE ?5@5<5==KE 

   min_rates_total=2;



//---- ?@52@0I5=85 48=0<8G5A:8E <0AA82>2 2 8=48:0B>@=K5 1CD5@K

   SetIndexBuffer(0,ExtUpBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,ExtDnBuffer,INDICATOR_DATA);

//---- >ACI5AB2;5=85 A42830 =0G0;0 >BAGQB0 >B@8A>2:8 8=48:0B>@0 1

   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);

//---- CAB0=>2:0 7=0G5=89 8=48:0B>@0, :>B>@K5 =5 1C4CB 2848<K =0 3@0D8:5

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);

//---- 70?@5B =0 >B>1@065=85 7=0G5=89 8=48:0B>@0 2 ;52>< 25@E=5< C3;C >:=0 8=48:0B>@0

   PlotIndexSetInteger(0,PLOT_SHOW_DATA,false);

//---- 8=45:A0F8O M;5<5=B>2 2 1CD5@0E :0: 2 B09<A5@8OE   

   ArraySetAsSeries(ExtUpBuffer,true);

   ArraySetAsSeries(ExtDnBuffer,true);

//---- #AB0=>2:0 D>@<0B0 B>G=>AB8 >B>1@065=8O 8=48:0B>@0

   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);

//---- 8<O 4;O >:>= 40==KE 8 ;M910 4;O AC1J>:>= 

   string short_name="Time_Bar_Custom("+string(BarHours)+":"+string(BarMinuts)+")";

   IndicatorSetString(INDICATOR_SHORTNAME,short_name);

//---- 7025@H5=85 8=8F80;870F88

   return(INIT_SUCCEEDED);

  }

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

//|  ?@>25@:0 10@0 =0 <><5=B 2@5<5=8                                 |

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

bool CheckVLinePoint(datetime bartime1,datetime bartime0)

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

  {

//----

   MqlDateTime tm0,tm1;

   TimeToStruct(bartime0,tm0);

   TimeToStruct(bartime1,tm1);

//----

   if(tm0.hour==BarHours && tm0.min==BarMinuts) return(true);

//----

   if(!BarMinuts)

     {

      if(tm0.day_of_year==tm1.day_of_year) if(tm1.hour<BarHours && tm0.hour>BarHours) return(true);

      if(tm0.day_of_year!=tm1.day_of_year) if(tm0.hour>=BarHours) return(true);

     }

//----

   if(BarMinuts)

     {

      if(tm0.hour==BarHours && tm1.min<BarMinuts && tm0.min>=BarMinuts) return(true);

      if(tm0.day_of_year==tm1.day_of_year && tm1.hour<BarHours && tm0.hour>BarHours)  return(true);

      if(tm0.day_of_year!=tm1.day_of_year) if(tm0.hour>BarHours) return(true);

     }

//----

   return(false);

  }

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

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

  {

//---- ?@>25@:0 :>;8G5AB20 10@>2 =0 4>AB0B>G=>ABL 4;O @0AGQB0

   if(rates_total<min_rates_total) return(0);



//---- >1JO2;5=8O ;>:0;L=KE ?5@5<5==KE    

   int limit;



//---- @0AGQB AB0@B>2>3> =><5@0 limit 4;O F8:;0 ?5@5AGQB0 10@>2 8 AB0@B>20O 8=8F80;870F8O ?5@5<5==KE

   if(prev_calculated>rates_total || prev_calculated<=0)// ?@>25@:0 =0 ?5@2K9 AB0@B @0AGQB0 8=48:0B>@0

     {

      limit=rates_total-min_rates_total; // AB0@B>2K9 =><5@ 4;O @0AGQB0 2A5E 10@>2

     }

   else

     {

      limit=rates_total-prev_calculated; // AB0@B>2K9 =><5@ 4;O @0AGQB0 =>2KE 10@>2

     }



//---- 8=45:A0F8O M;5<5=B>2 2 <0AA820E :0: 2 B09<A5@8OE  

   ArraySetAsSeries(open,true);

   ArraySetAsSeries(high,true);

   ArraySetAsSeries(low,true);

   ArraySetAsSeries(close,true);

   ArraySetAsSeries(time,true);



//---- >A=>2=>9 F8:; @0AGQB0 8=48:0B>@0

   for(int bar=limit; bar>=0 && !IsStopped(); bar--)

     {

      ExtUpBuffer[bar]=EMPTY_VALUE;

      ExtDnBuffer[bar]=EMPTY_VALUE;

      if(CheckVLinePoint(time[bar+1],time[bar]))

        {

         ExtUpBuffer[bar]=10*high[bar];

         ExtDnBuffer[bar]=NULL;

        }

     }

//---           

   return(rates_total);

  }

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

Comments