WeekDayOnDropped

Author: Copyright 2018, A.Voronin
1 Views
0 Downloads
0 Favorites
WeekDayOnDropped
ÿþ//+------------------------------------------------------------------+

//|                                             WeekDayOnDropped.mq4 |

//|                                      Copyright © 2018, A.Voronin |

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

#property copyright   "Copyright 2018, A.Voronin"

#property description "!:@8?B ?>:07K205B 4=8 =545;8." 

#property show_inputs

#property strict

//--- 2E>4=K5 ?0@0<5B@K A:@8?B0 

input string            InpFont="Arial";   // (@8DB 

input int               InpFontSize=20;    //  07<5@ H@8DB0 

input color             InpColor=clrGray;  // &25B 

input int               DaysCount = 60;    // >;8G5AB2> 4=59         

input double            InpAngle=0.0;            // #3>; =0:;>=0 2 3@04CA0E 

ENUM_ANCHOR_POINT InpAnchor=ANCHOR_RIGHT_LOWER;  // !?>A>1 ?@82O7:8 

bool              InpBack=true;            // 1J5:B =0 704=5< ?;0=5 

bool              InpSelection=false;      // K45;8BL 4;O ?5@5<5I5=89 

bool              InpHidden=true;          // !:@KB 2 A?8A:5 >1J5:B>2 

long              InpZOrder=0;             // @8>@8B5B =0 =060B85 <KHLN 

string wday[7]={"!","",""","! ","'"",""","!"};

int step,bars;

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

//| !>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_RIGHT_LOWER, // A?>A>1 ?@82O7:8 

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

  { 

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

  } 



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

//| Script program start function                                    | 

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

void OnStart() 

  {

double NW;

//--- >?@545;8< :>;8G5AB2> 10@>2

switch (Period())

{  case 1:step=1440;break;

   case 5:step=288;break;

   case 15:step=96;break;

   case 30:step=48;break;

   case 60:step=24;break; 

   case 240:step=6;break;

   case 1440:step=1;break;

   default:{Print("!:@8?B =5 @01>B05B =0 40==>< TF.");return;}

 } 

  

   int scale=(int)ChartGetInteger(0,CHART_SCALE); 

//--- >?@545;8< A<5I5=85 B5:AB0 

   int scalestep=1; 

   switch(scale) 

     { case 0:scalestep=12;break; 

       case 1:scalestep=6;break; 

       case 2:scalestep=4;break; 

       case 3:scalestep=2;break; 

     }  

     

   if (DaysCount<=0) bars=(int)ChartGetInteger(0,CHART_VISIBLE_BARS); else bars=DaysCount*step;

     

    for(int i=step/2+TimeHour(TimeCurrent())*step/24-scalestep;i<bars;i+=step) 

     { 

      //--- A>7405< =04?8A8 

       NW=MathCeil(i/(step*5));  

          

      if(!TextCreate(0,"WeekDay_"+(string)i,0,iTime(NULL,0,i-NW*step/24),ChartPriceOnDropped(),wday[TimeDayOfWeek(iTime(NULL,0,i))],InpFont,InpFontSize, 

         InpColor,InpAngle,InpAnchor,InpBack,InpSelection,InpHidden,InpZOrder)) 

        { 

         return; 

        } 

     

      //--- ?@>25@8< D0:B ?@8=C48B5;L=>3> 7025@H5=8O A:@8?B0 

      if(IsStopped()) 

         return; 

      //--- ?5@5@8AC5< 3@0D8: 

      ChartRedraw(); 

     } 

return;    

   }

Comments