ytg_TRADE_DAY

Author: Yuriy Tokman (YTG)
Price Data Components
Series array that contains the highest prices of each barSeries array that contains the lowest prices of each barSeries array that contains open prices of each barSeries array that contains close prices for each bar
2 Views
1 Downloads
0 Favorites
ytg_TRADE_DAY
ÿþ//+------------------------------------------------------------------+

//|                                                    TRADE_DAY.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   "2.00"

#property strict



#property indicator_chart_window



input color _color2 = Gainsboro;

input int _limit = 30;

input bool Sho_bars = true;



string _txt = "ytg_TRADE_DAY ";

color CL[7]={clrRed,clrRed,clrRed,clrRed,clrRed,clrLime,clrRed};

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping



//---

   return(INIT_SUCCEEDED);

  }

void OnDeinit(const int reason) {   GetDellName (_txt);

   Comment("");}

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

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

   if(limit>rates_total)limit=rates_total;  

   if(limit>_limit)limit=_limit;

   

   if(Period()<1440){

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

     {

//----

   //int counted_bars = IndicatorCounted();

   //if(counted_bars < 0)  return(-1);

   //if(counted_bars > 0)   counted_bars--;

   //int limits = Bars - counted_bars;

   //if(counted_bars==0) limits--;

      

   //if (limits<limit) return(0);

//----



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

     double   h = iHigh(Symbol(),1440,i);

     double   l = iLow(Symbol(),1440,i);

     double   o = iOpen(Symbol(),1440,i);

     double   c = iClose(Symbol(),1440,i);               

     datetime t = iTime(Symbol(),1440,i);

     datetime t_p = 11*60*60;

     datetime t_a = 1440*60;    

     string tx = TimeToStr(t,TIME_DATE );    

     int day = TimeDayOfWeek(t);//Print(day);

     TxtGraf(_txt+tx, GetDayOfWeek(day), t+t_p, h+200*Point,CL[day]);    

     

     if(Sho_bars)

      {

       TrendLineGraff(_txt+tx+" l",t,h,t,l);       

       TrendLineGraff(_txt+tx+" k",t+t_a,h,t+t_a,l);            

       TrendLineGraff(_txt+tx+" h",t,h,t+t_a,h);       

       TrendLineGraff(_txt+tx+" w",t,l,t+t_a,l);       

       //RICE_ARROW(_txt+tx+" l1",t+(t-t+t_a)/2-60*60*2,h,_color2,1);

       //TxtGraf(_txt+tx+"q", DoubleToString(h,Digits),t,h,CL[day-1]);

       TextCreate(0,_txt+tx+"q",0,t+Period()*60,h,DoubleToString(h,Digits),"Arial",8,CL[day],0.0,ANCHOR_LEFT_LOWER);              

       //RICE_ARROW(_txt+tx+" l2",t+(t-t+t_a)/2-60*60*2,l,_color2,1);

       TextCreate(0,_txt+tx+"w",0,t+Period()*60,l,DoubleToString(l,Digits),"Arial",8,CL[day],0.0,ANCHOR_LEFT_UPPER);             

       double p_1 = l;

       double p_2 = h;     

       if(o>c){p_1=h;p_2=l;}     

       TrendLineGraff(_txt+tx+" z",t,o,t+t_a,c);

       if(o>c)

       RectangleCreate(0,_txt+tx+"e",0,t,o,t+t_a,c,clrSalmon);

       if(o<c)

       RectangleCreate(0,_txt+tx+"r",0,t,o,t+t_a,c,clrLightCyan);       

      }          

   }}  

//----

   return(rates_total);

  }

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

//| $C=:F8O >B>1@065=8O B5:AB0                                       |

//| 02B>@: .@89 ">:<0=L                                              |

//| e-mail: yuriytokman@gmail.com                                    |

//| ICQ#    481-971-287                                              |

//| Skype:  yuriy.g.t                                                |

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

 void TxtGraf(string labebe, string txt, datetime time1, double price1, color colir)

  {

   if (ObjectFind(labebe)!=-1) ObjectDelete(labebe);

   ObjectCreate(labebe, OBJ_TEXT, 0, time1, price1);

   ObjectSetText(labebe, txt, 10, "Times New Roman", colir); 

   ObjectSet(labebe, OBJPROP_BACK, true);     

  }

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

//| $C=:F8O 2>72@0I05B 45=L =545;8 4;O C:070==>9 40BK.               |

//| 02B>@: .@89 ">:<0=L                                              |

//| e-mail: yuriytokman@gmail.com                                    |

//| ICQ#    481-971-287                                              |

//| Skype:  yuriy.g.t                                                |

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

string GetDayOfWeek(int Day_Week) {

  switch (Day_Week ) {

    case 0  : return("7.Sunday");

    case 1  : return("1.Monday");

    case 2  : return("2.Tuesday");

    case 3  : return("3.Wednesday");

    case 4  : return("4.Thursday");

    case 5  : return("5.Friday");

    case 6  : return("6.Saturday");    

    default : return("Unknown Operation");

  }

}

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

//| $C=:F8O C40;O5B >1J5:BK                                          |

//| 02B>@: .@89 ">:<0=L                                              |

//| e-mail: yuriytokman@gmail.com                                    |

//| ICQ#    481-971-287                                              |

//| Skype:  yuriy.g.t                                                |

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

 void GetDellName (string name_n = "ytg_")

  {

   string vName;

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

    {

     vName = ObjectName(i);

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

    }  

  }

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

//| $C=:F8O >B>1@065=8O B@5=4>2>9 ;8=88                              |

//| 02B>@: .@89 ">:<0=L                                              |

//| e-mail: yuriytokman@gmail.com                                    |

//| ICQ#    481-971-287                                              |

//| Skype:  yuriy.g.t                                                |

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

 void TrendLineGraff(string labebe,datetime time1,double price1,datetime time2,double price2)

  {

   if (ObjectFind(labebe)!=-1) ObjectDelete(labebe);

   ObjectCreate(labebe, OBJ_TREND, 0,time1,price1,time2,price2);

   ObjectSet(labebe, OBJPROP_COLOR, _color2);

   ObjectSet(labebe, OBJPROP_STYLE,0);

   ObjectSet(labebe, OBJPROP_RAY,0);

   ObjectSet(labebe, OBJPROP_BACK, true);

  }

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

//| $C=:F8O >B>1@065=8O F5=>2>9 <5B:8                                |

//| 02B>@: .@89 ">:<0=L                                              |

//| e-mail: yuriytokman@gmail.com                                    |

//| ICQ#    481-971-287                                              |

//| Skype:  yuriy.g.t                                                |

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

 void RICE_ARROW(string label,datetime time1,double price1,color colir,int WIDTH )

  {

   if (ObjectFind(label)!=-1) ObjectDelete(label);

   ObjectCreate(label,OBJ_ARROW, 0,time1,price1);

   ObjectSet(label,OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE);

   ObjectSet(label, OBJPROP_COLOR, colir);

   ObjectSet(label, OBJPROP_WIDTH,WIDTH);

   ObjectSet(label, OBJPROP_BACK, false);

  }

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

//| !>7405B >1J5:B ""5:AB"                                           | 

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

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

                const string            name="Text",              // 8<O >1J5:B0 

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

                datetime                time=0,                   // 2@5<O B>G:8 ?@82O7:8 

                double                  price=0,                  // F5=0 B>G:8 ?@82O7:8 

                const string            text="Text",              // A0< B5:AB 

                const string            font="Arial",             // H@8DB 

                const int               font_size=10,             // @07<5@ H@8DB0 

                const color             clr=clrRed,               // F25B 

                const double            angle=0.0,                // =0:;>= B5:AB0 

                const ENUM_ANCHOR_POINT anchor=ANCHOR_LEFT, // A?>A>1 ?@82O7:8 

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

                const bool              selection=false,          // 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 

  { 

//---

   if (ObjectFind(chart_ID,name)!=-1) ObjectDelete(chart_ID,name); 

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

   ResetLastError(); 

//--- A>74048< >1J5:B ""5:AB" 

   if(!ObjectCreate(chart_ID,name,OBJ_TEXT,sub_window,time,price)) 

     { 

      Print(__FUNCTION__, 

            ": =5 C40;>AL A>740BL >1J5:B \""5:AB\"! >4 >H81:8 = ",GetLastError()); 

      return(false); 

     } 

//--- CAB0=>28< B5:AB 

   ObjectSetString(chart_ID,name,OBJPROP_TEXT,text); 

//--- CAB0=>28< H@8DB B5:AB0 

   ObjectSetString(chart_ID,name,OBJPROP_FONT,font); 

//--- CAB0=>28< @07<5@ H@8DB0 

   ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size); 

//--- CAB0=>28< C3>; =0:;>=0 B5:AB0 

   ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle); 

//--- CAB0=>28< A?>A>1 ?@82O7:8 

   ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor); 

//--- CAB0=>28< F25B 

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); 

//--- >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 >1J5:B0 <KHLN 

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

  } 

//----

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

//| C>7405B ?@O<>C3>;L=8: ?> 7040==K< :>>@48=0B0<                    | 

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

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

                     const string          name="Rectangle",  // 8<O ?@O<>C3>;L=8:0 

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

                     datetime              time1=0,           // 2@5<O ?5@2>9 B>G:8 

                     double                price1=0,          // F5=0 ?5@2>9 B>G:8 

                     datetime              time2=0,           // 2@5<O 2B>@>9 B>G:8 

                     double                price2=0,          // F5=0 2B>@>9 B>G:8 

                     const color           clr=clrRed,        // F25B ?@O<>C3>;L=8:0 

                     const ENUM_LINE_STYLE style=STYLE_SOLID, // AB8;L ;8=89 ?@O<>C3>;L=8:0 

                     const int             width=1,           // B>;I8=0 ;8=89 ?@O<>C3>;L=8:0 

                     const bool            fill=true,        // 70;82:0 ?@O<>C3>;L=8:0 F25B>< 

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

                     const bool            selection=false,    // 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 

  { 

//--- CAB0=>28< :>>@48=0BK B>G5: ?@82O7:8, 5A;8 >=8 =5 7040=K 

   if (ObjectFind(chart_ID,name)!=-1) ObjectDelete(chart_ID,name); 

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

   ResetLastError(); 

//--- A>74048< ?@O<>C3>;L=8: ?> 7040==K< :>>@48=0B0< 

   if(!ObjectCreate(chart_ID,name,OBJ_RECTANGLE,sub_window,time1,price1,time2,price2)) 

     { 

      Print(__FUNCTION__, 

            ": =5 C40;>AL A>740BL ?@O<>C3>;L=8:! >4 >H81:8 = ",GetLastError()); 

      return(false); 

     } 

//--- CAB0=>28< F25B ?@O<>C3>;L=8:0 

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); 

//--- CAB0=>28< AB8;L ;8=89 ?@O<>C3>;L=8:0 

   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style); 

//--- CAB0=>28< B>;I8=C ;8=89 ?@O<>C3>;L=8:0 

   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width); 

//--- 2:;NG8< (true) 8;8 >B:;NG8< (false) @568< 70;82:8 ?@O<>C3>;L=8:0 

   ObjectSetInteger(chart_ID,name,OBJPROP_FILL,fill); 

//--- >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< 2K45;5=8O ?@O<>C3>;L=8:0 4;O ?5@5<5I5=89 

//--- ?@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); 

  } 

//----

Comments