Author: Wangxin
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
TradeTime
ÿþ//+------------------------------------------------------------------+

//|                                                    TradeTime.mq4 |

//|  8< 3>@L . aka KimIV   http://www.kimiv.ru                    |

//|  Wangxin                  38834228@qq.com                        |

//|                                                                  |

//|  08.02.2006  =48:0B>@ CB@5==53> 480?07>=0.                      |

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

#property copyright "Wangxin"

//#property link      "http://www.kimiv.ru"

//----

#property strict

#property indicator_chart_window

#property indicator_buffers 2

#property indicator_color1 White

#property indicator_color2 White

//------- =5H=85 ?0@0<5B@K 8=48:0B>@0 -------------------------------

extern string StartTime ="09:00";             //hƋ_ËYöeô•¹p

extern string EndTime ="15:00";      // @5<O ?@>25@:8 480?07>=0    hƋÓ~_göeô•¹p

extern bool   ShowHistory =True;     // >:07K20BL 8AB>@8G5A:85 C@>2=8  /f&Tù[†SòSpencۏLˆöeô•µkhƋ

extern bool   ShowAmp = True;          ///f&T>f:yhƋöeô•µk„vLˆÅ`/cE^

extern int    NumberOfDays=10;        // >;8G5AB2> 4=59 8AB>@88  —‰hƋ„v†SòS)Ype

extern bool   ShowComment =False;     // >:07K20BL :><<5=B0@88   /f&T>f:yÐc:yáOo`

//------- CD5@K 8=48:0B>@0 ------------------------------------------

double dBuf0[], dBuf1[];

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

//| Custom indicator initialization function ꁚ[INchRËYSýQpe                         |

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

void init()

  {

   SetIndexArrow(0, 217);

   SetIndexBuffer(0, dBuf0);

   SetIndexStyle(0, DRAW_ARROW, 1, 1);

   SetIndexArrow(1, 218);

   SetIndexBuffer(1, dBuf1);

   SetIndexStyle(1, DRAW_ARROW, 1, 1);

   DeleteLines();

   for(int i=0; i<2; i++)

     {

      //ObjectCreate("HLine"+i, OBJ_HLINE, 0, 0,0);

     }

   for(int i=0; i<NumberOfDays; i++)

     {

      CreateLines("upLine"+i, indicator_color1);

      CreateLines("dnLine"+i, indicator_color2);

     }

  }

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

//| !>740=85 >1J5:B>2 8=8O ?@>H;KE 4=59     Rú^ù[aŒ„vMRàQ)Yöeô•R¿~  |

//| 0@0<5B@K:                               	y˜                      |

//|   no - =08<5=>20=85 ;8=88                no - R¿~÷S             |

//|   cl - F25B ;8=88                        cl - R¿~œ˜r‚             |

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

void CreateLines(string no, color cl)

  {

   ObjectCreate(no, OBJ_TREND, 0, 0,0, 0,0);

//ObjectSet(no, OBJPROP_STYLE, STYLE_SOLID);

   ObjectSet(no, OBJPROP_STYLE, STYLE_DASHDOT);

   ObjectSet(no, OBJPROP_WIDTH, 1);

   ObjectSet(no, OBJPROP_COLOR, cl);

   ObjectSet(no, OBJPROP_RAY, False);

  }

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

//| Custom indicator deinitialization function  ꁚ[INch»SRËYSŸRý€ýQpe |

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

void deinit()

  {

   DeleteLines();

   Comment("");

  }

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

//| #40;5=85 3>@87>=B0;L=KE ;8=89.         Rd–R¿~                   |

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

void DeleteLines()

  {

   for(int i=0; i<2; i++)

     {

      //ObjectDelete("HLine"+i);

     }

   for(int i=0; i<NumberOfDays; i++)

     {

      ObjectDelete("upLine"+i);

      ObjectDelete("dnLine"+i);

      ObjectDelete("AMP" + i);

     }

  }

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

//| Custom indicator iteration function    ꁚ[INchíãNýQpe        |

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

void start()

  {

   datetime t1, t2, dt;

   double   p1, p2;

   int      b1, b2, sd=0;

//----

   if(StartTime<EndTime)

     {

      t1=StrToTime(TimeToStr(TimeCurrent(), TIME_DATE)+" "+StartTime);

      t2=StrToTime(TimeToStr(TimeCurrent(), TIME_DATE)+" "+EndTime);

     }

   else            //Ôk‚YŽýVöeô•/f荊0RæSN*N¤Nfåe

     {

      t1=StrToTime(TimeToStr(decDateTradeDay(TimeCurrent()), TIME_DATE)+" "+StartTime);

      t2=StrToTime(TimeToStr(TimeCurrent(), TIME_DATE)+" "+EndTime);

     }

   b1=iBarShift(NULL, 0, t1);

   b2=iBarShift(NULL, 0, t2);

   p1=High[Highest(NULL, 0, MODE_HIGH, b1-b2+1, b2)];

   p2=Low [Lowest(NULL, 0, MODE_LOW, b1-b2+1, b2)];

//SetHLine(0, p1);

//SetHLine(1, p2);

   if(ShowHistory)

     {

      if(StartTime<EndTime)

        {

         dt=decDateTradeDay(TimeCurrent());

        }

      else

        {

         dt=TimeCurrent();

        }

      for(int i=0; i<NumberOfDays; i++)

        {

         DrawLines(dt, i);

         dt=decDateTradeDay(dt);

         while(TimeDayOfWeek(dt)<1 || TimeDayOfWeek(dt)>5)

            dt=decDateTradeDay(dt);

        }

     }

   if(ShowComment)

      Comment("EndTime="+EndTime);

  }

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

//| #AB0=02;8205B @5:2878BK 3>@87>=B0;L=>9 ;8=88 B5:CI53> 4=O.  ¾‹nS_MR)Y4ls^¿~„v‰y˜0¡l	gǑ(uå‹ýQpe     |

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

void SetHLine(int nl, double pp)

  {

   color cl;

   if(pp!=EMPTY_VALUE)

     {

      switch(nl)

        {

         case 0:

            cl=indicator_color1;

            break;

         case 1:

            cl=indicator_color2;

            break;

        }

      ObjectSet("HLine"+nl, OBJPROP_PRICE1, pp);

      ObjectSet("HLine"+nl, OBJPROP_COLOR, cl);

     }

  }

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

//| @>@8A>2:0 ;8=89 =0 3@0D8:5                þVhˆ
N;uöeô•¿~        |

//| 0@0<5B@K:                                 	y˜ÿ                |

//|   dt - 40B0 B>@3>2>3> 4=O                  dt - ¤Nfåe           |

//|   nd - =><5@ 4=O (4;O =C<5@0F88 >1J5:B>2)  nd - öeô•R¿~÷S     |

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

void DrawLines(datetime dt, int nd)

  {

   datetime t1, t2;

   double   p1, p2;

   int      b1, b2;

   if(StartTime<EndTime)

     {

      t1=StrToTime(TimeToStr(dt, TIME_DATE)+" "+StartTime);

      t2=StrToTime(TimeToStr(dt, TIME_DATE)+" "+EndTime);

     }

   else                 //Ôk‚YŽýVöeô•/f荊0RæSN*N¤Nfåe

     {

      t1=StrToTime(TimeToStr(decDateTradeDay(dt), TIME_DATE)+" "+StartTime);

      t2=StrToTime(TimeToStr(dt, TIME_DATE)+" "+EndTime);

     }

   b1=iBarShift(NULL, 0, t1);

   b2=iBarShift(NULL, 0, t2);

   p1=High[Highest(NULL, 0, MODE_HIGH, b1-b2+1, b2)];

   p2=Low [Lowest(NULL, 0, MODE_LOW, b1-b2+1, b2)];



//ObjectSet("upLine"+nd, OBJPROP_TIME1 , t1);

//ObjectSet("upLine"+nd, OBJPROP_PRICE1, p1);

//ObjectSet("upLine"+nd, OBJPROP_TIME2 , t2);

//ObjectSet("upLine"+nd, OBJPROP_PRICE2, p1);



   ObjectSet("upLine"+nd, OBJPROP_TIME1, t1);

   ObjectSet("upLine"+nd, OBJPROP_PRICE1, p1);

   ObjectSet("upLine"+nd, OBJPROP_TIME2, t1);

   ObjectSet("upLine"+nd, OBJPROP_PRICE2, p2);



//ObjectSet("dnLine"+nd, OBJPROP_TIME1 , t1);

//ObjectSet("dnLine"+nd, OBJPROP_PRICE1, p2);

//ObjectSet("dnLine"+nd, OBJPROP_TIME2 , t2);

//ObjectSet("dnLine"+nd, OBJPROP_PRICE2, p2);



   ObjectSet("dnLine"+nd, OBJPROP_TIME1, t2);

   ObjectSet("dnLine"+nd, OBJPROP_PRICE1, p1);

   ObjectSet("dnLine"+nd, OBJPROP_TIME2, t2);

   ObjectSet("dnLine"+nd, OBJPROP_PRICE2, p2);

   if(ShowAmp)

     {

      ObjectCreate("AMP" + nd, OBJ_TEXT, 0, t2, p1*1.008);

      ObjectSetText("AMP" + nd, DoubleToStr((p1-p2),0), 10, "Arial", clrYellow);

     }

  }



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

//| #<5=LH5=85 40BK =0 >48= B>@3>2K9 45=L     ÏQ\N*N¤Nfåe„våeg   |

//| 0@0<5B@K:                                	y˜ÿ                 |

//|   dt - 40B0 B>@3>2>3> 4=O                 dt - ¤Nfåe             |

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

datetime decDateTradeDay(datetime dt)

  {

   int ty=TimeYear(dt);

   int tm=TimeMonth(dt);

   int td=TimeDay(dt);

   int th=TimeHour(dt);

   int ti=TimeMinute(dt);

//----

   td--;

   if(td==0)

     {

      tm--;

      if(tm==0)

        {

         ty--;

         tm=12;

        }

      if(tm==1 || tm==3 || tm==5 || tm==7 || tm==8 || tm==10 || tm==12)

         td=31;

      if(tm==2)

         if(MathMod(ty, 4)==0)

            td=29;

         else

            td=28;

      if(tm==4 || tm==6 || tm==9 || tm==11)

         td=30;

     }

   return(StrToTime(ty+"."+tm+"."+td+" "+th+":"+ti));

  }

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

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