Custom Period Separators

Author: Yuriy Tokman (YTG)
1 Views
0 Downloads
0 Favorites
Custom Period Separators
ÿþ//+------------------------------------------------------------------+

//|                                     Custom Period Separators.mq4 |

//|                                               Yuriy Tokman (YTG) |

//|                       https://www.mql5.com/ru/users/satop/seller |

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

#property copyright "Yuriy Tokman (YTG)"

#property link      "https://www.mql5.com/ru/users/satop/seller"

#property version   "1.00"

#property strict

#property indicator_chart_window



input string Time_Separators = "09:15"; 

// 2@5<O @0745;8B5;O ('':)

input color           InpColor=clrRed;     

// &25B ;8=88 

input ENUM_LINE_STYLE InpStyle=STYLE_DASH; 

// !B8;L ;8=88 

input int             InpWidth=1;          

// ">;I8=0 ;8=88 

input bool            InpBack=false;       

// 8=8O =0 704=5< ?;0=5 



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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   

//---

   return(INIT_SUCCEEDED);

  }

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

//| Expert deinitialization function                                 |

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

void OnDeinit(const int reason)

  {

//---

   GetDell(Time_Separators);

//---   

  }

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

//| 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=rates_total-prev_calculated;

   if(prev_calculated==0)limit--;

   else  limit++;

//----

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

   {

    VLineCreate(0,Time_Separators+TimeToString(T_1440(i)),0,T_1440(i),InpColor,InpStyle,InpWidth,InpBack,false,false);       

   }  

//--- return value of prev_calculated for next call

   return(rates_total);

  }

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

datetime T_1440 (int i =0)

 {

  datetime _t_1440 =0;



  datetime tD = iTime(Symbol(),1440,iBarShift(Symbol(),1440,Time[i]));

  _t_1440 = StrToTime(TimeToStr(tD, TIME_DATE)+" "+Time_Separators);

  

  return(_t_1440);

 }

//----

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

//| !>7405B 25@B8:0;L=CN ;8=8N                                       | 

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

bool VLineCreate(const long            chart_ID=0,        // ID 3@0D8:0 

                 const string          name="VLine",      // 8<O ;8=88 

                 const int             sub_window=0,      // =><5@ ?>4>:=0 

                 datetime              time=0,            // 2@5<O ;8=88 

                 const color           clr=clrRed,        // F25B ;8=88 

                 const ENUM_LINE_STYLE style=STYLE_SOLID, // AB8;L ;8=88 

                 const int             width=1,           // B>;I8=0 ;8=88 

                 const bool            back=false,        // =0 704=5< ?;0=5 

                 const bool            selection=true,    // 2K45;8BL 4;O ?5@5<5I5=89 

                 const bool            hidden=true,       // A:@KB 2 A?8A:5 >1J5:B>2 

                 const long            z_order=0)         // ?@8>@8B5B =0 =060B85 <KHLN 

  { 

//--- 5A;8 2@5<O ;8=88 =5 7040=>, B> ?@>2>48< 55 G5@57 ?>A;54=89 10@ 

   if(ObjectFind(chart_ID,name)>-1)ObjectDelete(chart_ID,name); 

//--- A1@>A8< 7=0G5=85 >H81:8 

   ResetLastError(); 

//--- A>74048< 25@B8:0;L=CN ;8=8N 

   if(!ObjectCreate(chart_ID,name,OBJ_VLINE,sub_window,time,0)) 

     { 

      Print(__FUNCTION__, 

            ": =5 C40;>AL A>740BL 25@B8:0;L=CN ;8=8N! >4 >H81:8 = ",GetLastError()); 

      return(false); 

     } 

//--- CAB0=>28< F25B ;8=88 

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); 

//--- CAB0=>28< AB8;L >B>1@065=8O ;8=88 

   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style); 

//--- CAB0=>28< B>;I8=C ;8=88 

   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width); 

//--- >B>1@078< =0 ?5@54=5< (false) 8;8 704=5< (true) ?;0=5 

   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); 

//--- 2:;NG8< (true) 8;8 >B:;NG8< (false) @568< ?5@5<5I5=8O ;8=88 <KHLN 

//--- ?@8 A>740=88 3@0D8G5A:>3> >1J5:B0 DC=:F859 ObjectCreate, ?> C<>;G0=8N >1J5:B 

//--- =5;L7O 2K45;8BL 8 ?5@5<5I0BL. =CB@8 65 MB>3> <5B>40 ?0@0<5B@ selection 

//--- ?> C<>;G0=8N @025= true, GB> ?>72>;O5B 2K45;OBL 8 ?5@5<5I0BL MB>B >1J5:B 

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); 

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection); 

//--- A:@>5< (true) 8;8 >B>1@078< (false) 8<O 3@0D8G5A:>3> >1J5:B0 2 A?8A:5 >1J5:B>2 

   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); 

//--- CAB0=>28< ?@8>@8B5B =0 ?>;CG5=85 A>1KB8O =060B8O <KH8 =0 3@0D8:5 

   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); 

//--- CA?5H=>5 2K?>;=5=85 

   return(true); 

  } 

//----

void GetDell(string name="ytg")

  {

   string vName;

   for(int i=ObjectsTotal()-1; i>=0;i--)

     {

      vName=ObjectName(i);

      if(StringFind(vName,name)!=-1) ObjectDelete(vName);

     }

  }

//----

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