LocalTime_V1.2

Author: xyz0217@qq.com
Miscellaneous
It issuies visual alerts to the screen
0 Views
0 Downloads
0 Favorites
LocalTime_V1.2
ÿþ//+------------------------------------------------------------------+

//|                              K¿~>f:y,g0Wöeô•	cOO ŸhÚntûy¨R.mq4 |

//|                                                          xyz0217 |

//|                                                   xyz0217@qq.com |

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

#property copyright "xyz0217@qq.com"

#property version   "1.2"

#property strict

#property description "K¿~>f:y,g0Wöeô• OꁨR¡‹—{öeô•î] FO‚YœgúQî] ïSåNKb¨RîOck "

#property description "Kb¨RîOck <PO«ˆ°‹U_Neg êS—‰kX™QN!k"

#property description ">f:ych —‰ Ÿh	cOO-Nô•Úntûy¨RNN  	cNN-N.•àeHeœg Q¤221696452"

#property description "b Ctrl+ Ÿhæ].•¹pûQþVhˆ  ŸhóS.• Rd–"

#property description ",{N!k R}chöe  R}öeô•ˆ_͑‰ ÷‹nx¤‹ s^ðS/f_^¶r` v^(WS¬Nöeô•}v)YkQ¹pT  R}  "

#property indicator_chart_window





extern int shijianchaHour=0;//Kb¨RîOck 
g¡RhVN,g0W„vöeô•î]àQ*N\öe êS—îO9eN!k OÝOX[°‹U_

extern  int py=20;//*j¿~Nïz >f:yöeô• T
NOPûy ‚Y«ˆnÖv

input  int ZT_size=10;//*j¿~Nïz >f:yöeô• „vW[SO'Y\

extern color ZT_color=clrCrimson;//œ˜r‚

extern bool show_details=true;///f&T>f:yK¿~æ‹Æ~áOo`



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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

   ChartSetInteger(0, CHART_EVENT_MOUSE_MOVE, 1);//RËYS Ÿhûy¨RŒT Ÿh¹pûQ‹NöN



   if(shijianchaHour!=0)

     {

      GlobalVariableSet(StringSubstr(AccountServer(),0,6)+"_shicha",shijianchaHour);

      return(INIT_SUCCEEDED);

     }

/////////////////////

   if(GlobalVariableCheck(StringSubstr(AccountServer(),0,6)+"_shicha")==true)//,g0WN
g¡RhV„vöeô•î] \öepe

     {

      shijianchaHour=(int)GlobalVariableGet(StringSubstr(AccountServer(),0,6)+"_shicha");

      if(TimeDayOfWeek(TimeCurrent())==1 && MQLInfoInteger(MQL_TESTER) == 0 && MQLInfoInteger(MQL_VISUAL_MODE) == 0 && TimeHour(TimeLocal())>7 && TimeHour(TimeLocal())<19)

        {

         GlobalVariableSet(StringSubstr(AccountServer(),0,6)+"_shicha",TimeHour(TimeLocal()) - TimeHour(TimeCurrent()));

        }

     }

   else

     {

      if(MQLInfoInteger(MQL_TESTER) == 0 && MQLInfoInteger(MQL_VISUAL_MODE) == 0 && TimeDayOfWeek(TimeCurrent())!=0 && TimeDayOfWeek(TimeCurrent())!=6 && TimeHour(TimeLocal())>7)

        {

         if(TimeHour(TimeLocal()) != TimeHour(TimeCurrent()))

           {

            GlobalVariableSet(StringSubstr(AccountServer(),0,6)+"_shicha",TimeHour(TimeLocal()) - TimeHour(TimeCurrent()));

            shijianchaHour=(int)GlobalVariableGet(StringSubstr(AccountServer(),0,6)+"_shicha");

           }

         else

           {

            Alert("S_MRöeô•
Ncknx b \P^-N 
g¡RhVöeô•¡lôf°e ÷‹Kb¨RîOcköeô•î]");

           }

        }

     }

   return(INIT_SUCCEEDED);

  }

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

//|                                                                  |

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

void OnDeinit(const int reason)

  {

   ObjectDelete(0,"TimeLine1");

   ObjectDelete(0,"LocalTime1");

  }

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

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

  {

//---

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

   return(rates_total);

  }

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

//| ChartEvent function                                              |

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

void OnChartEvent(const int id,

                  const long &lparam,

                  const double &dparam,

                  const string &sparam)

  {

//---

   if(id == CHARTEVENT_MOUSE_MOVE)//ߍ@w Ÿh„vûy¨R

     {

      int      x1     = (int)lparam;

      int      y1     = (int)dparam;

      datetime dt    = 0;

      double   price = 0;

      int      window = 0;

      int a;//·ƒÖSK¿~„v^R÷S

      //--- Oncåeg/öeô•lbcXŒTYPWh

      if(ChartXYToTimePrice(0, x1, y1, window, dt, price))

        {

         a=iBarShift(NULL,0,dt,true);

         if(dt>=Time[0])

            a=0;

         if(ObjectFind(0,"TimeLine1")==0)

           {

            string LT=TimeToStr(dt+shijianchaHour*3600,TIME_DATE | TIME_MINUTES);

            if(show_details)

               ObjectSetString(0,"TimeLine1",OBJPROP_TOOLTIP,",g0Wöeô• "+LT+"\nOpen: "+string(Open[a])+"\nHigh:  "+string(High[a])+"\nLow:   "+string(Low[a])+"\nClose: "+string(Close[a])+"\nVolume: "+string(Volume[a]));

            else

               ObjectSetString(0,"TimeLine1",OBJPROP_TOOLTIP," ");



            ObjectMove("TimeLine1",0,dt,0);

            ///////////////////////

            if(ObjectFind(0,"LocalTime1")==0)

              {

               ObjectSetInteger(0,"LocalTime1",OBJPROP_TIME,Time[0]);

               ObjectSetString(0,"LocalTime1",OBJPROP_TEXT,LT);

               ObjectMove(0,"LocalTime1",0,ObjectGetInteger(0,"TimeLine1",OBJPROP_TIME),WindowPriceMin(0)+py*_Point);

              }

            else

              {

               TextCreate(0,"LocalTime1",0,ObjectGetInteger(0,"TimeLine1",OBJPROP_TIME),WindowPriceMin(0)+py*_Point,LT);

              }

            ///////////////////////

           }

        }

      if(sparam == "2")// ŸhóS.•

        {

         ObjectDelete(0,"TimeLine1");

         ObjectDelete(0,"LocalTime1");

        }

      if(sparam == "16")// Ÿh-N.•§c¿~ —‰	cOO Úntûy¨RNN  	cNN-N.•àeHeœg

        {

         if(ObjectFind(0,"TimeLine1")<0)

           {

            ObjectCreate(0,"TimeLine1",OBJ_VLINE,0,Time[200],0);

            ObjectSet("TimeLine1",OBJPROP_BACK,false);

            ObjectSet("TimeLine1",OBJPROP_WIDTH,1);

            ObjectSet("TimeLine1",OBJPROP_COLOR,ZT_color);

           }

        }

      if(sparam == "9")//Ctrl+ Ÿhæ].•

        {



         if(ObjectFind(0,"TimeLine1")<0)

           {

            ObjectCreate(0,"TimeLine1",OBJ_VLINE,0,Time[50],0);

            ObjectSet("TimeLine1",OBJPROP_BACK,false);

            ObjectSet("TimeLine1",OBJPROP_WIDTH,1);

            ObjectSet("TimeLine1",OBJPROP_COLOR,ZT_color);

           }

         else

           {

            ObjectDelete(0,"TimeLine1");

            ObjectDelete(0,"LocalTime1");

           }

        }

     }

  }

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

//| Rú^‡e,gù[aŒ                                                       |

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

bool TextCreate(const long              chart_ID=0,               // þVhˆ ID

                const string            name="Text",              // ù[aŒ
Tðy

                const int               sub_window=0,             // P[—zãScpe

                datetime                time=0,                   // š[MO¹pöeô•

                double                  price=0,                  // š[MO¹p÷N<h

                const string            text="Text",              // ‡e,g,g«Ž

                const string            font="Arial",             // W[SO

                const int               font_size=10,             // W[SO'Y\ Ÿ^_

                const color             clr=clrRed,               // œ˜r‚ Ÿ^_

                const double            angle=0.0,                // ‡e,g>Pœe

                const ENUM_ANCHOR_POINT anchor=ANCHOR_CENTER,    // š[MO{|‹W

                const bool              back=false,               // (Ẁof-N

                const bool              selection=false,          // zúQûy¨R

                const bool              hidden=false,             // –Ï…(Wù[aŒRhˆ

                const long              z_order=0)                //  ŸhUSûQOHQ

  {



//--- ͑n•ï‹„v<P

   ResetLastError();

//--- Rú^‡e,gù[aŒ

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

     {

      Print(__FUNCTION__,

            ": failed to create \"Text\" object! Error code = ",GetLastError());

      return(false);

     }

//--- ¾‹n‡e,g

   ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);

//--- ¾‹n‡e,gW[SO

   ObjectSetString(chart_ID,name,OBJPROP_FONT,font);

//--- ¾‹nW[SO'Y\

   ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,ZT_size);

//--- ¾‹n‡e,g„v>Pœe҉

   ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle);

//--- ¾‹nš[MO{|‹W

   ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor);

//--- ¾‹nœ˜r‚

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,ZT_color);

//--- >f:yMRof (false) b̀of (true)

   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);

//--- /T(u (true) by(u (false) Ç Ÿhûy¨Rù[aŒ„v!j_

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);

//--- (Wù[aŒRhˆ–Ï…(true) b>f:y (false) þVb_ù[aŒ
Tðy

   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);

//--- ¾‹n(WþVhˆ-NOHQ¥c6e Ÿh¹pûQ‹NöN

   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);

//--- bŸRgbLˆ

   return(true);

  }

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

Comments