i-DayRange
Price Data Components
Series array that contains the highest prices of each barSeries array that contains the highest prices of each barSeries array that contains the lowest prices of each barSeries array that contains the lowest prices of each bar
0 Views
0 Downloads
0 Favorites
i-DayRange
//+------------------------------------------------------------------+
//|                                                   i-DayRange.mq4 |
//|                                           Êèì Èãîðü Â. aka KimIV |
//|                                              http://www.kimiv.ru |
//|                                                                  |
//|  17.11.2005  Èíäèêàòîð äíåâíîãî äèàïàçîíà                        |
//|  09.10.2006  Ïî ïðîñüáå CW äîáàâèë ïàðàìåòð MaxRange, êîòîðûé    |
//|              îãðàíè÷èâàåò äèàïàçîí èçìåíåíèÿ èíäèêàòîðà.         |
//|  28.03.2007  Ïî ïðîñüáå avtotorg@list.ru äîáàâèë ïðîäîëæåíèå     |
//|              ëèíèé äî êîíöà äíÿ è öåíîâûå óðîâíè.                |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 SteelBlue
#property indicator_style1 1
#property indicator_width1 2
#property indicator_color2 SteelBlue
#property indicator_style2 1
#property indicator_width2 2
#property indicator_color3 LightSlateGray
#property indicator_style3 0
#property indicator_width3 1

//------- Âíåøíèå ïàðàìåòðû èíäèêàòîðà -------------------------------
extern int   NumberOfDays = 5;      // Êîëè÷åñòâî äíåé (0-âñå)
extern int   MaxRange     = 300;    // Ìàêñèìàëüíûé äèàïàçîí
extern bool  ShowContinue = True;   // Ïîêàçûâàòü ïðîäîëæåíèå ëèíèé
extern bool  ShowPrice    = True;   // Ïîêàçûâàòü öåíîâûå óðîâíè
extern color clFont       = Green;  // Öâåò øðèôòà
extern int   SizeFont     = 8;      // Ðàçìåð øðèôòà
extern int   OffSet       = 10;     // Ñìåùåíèå

double shifthigh[];
double shiftlow[];
double shiftaver[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void init() {
  SetIndexBuffer   (0, shifthigh);
  SetIndexDrawBegin(0, 0);
  SetIndexLabel    (0, "Up Channel");
  SetIndexStyle    (0, DRAW_LINE);

  SetIndexBuffer   (1, shiftlow);
  SetIndexDrawBegin(1, 0);
  SetIndexLabel    (1, "Down Channel");
  SetIndexStyle    (1, DRAW_LINE);

  SetIndexBuffer   (2, shiftaver);
  SetIndexDrawBegin(2, 0);
  SetIndexLabel    (2, "Average Channel");
  SetIndexStyle    (2, DRAW_LINE, 0,1);
}

//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
void deinit() {
  ObjectDelete("UpPrice");
  ObjectDelete("DnPrice");
  Comment("");
}

//+------------------------------------------------------------------+ 
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+ 
void start() {
  datetime dt=CurTime();
  double   HighLine=0, LowLine=0, AverLine=0;
  int      i, j, kb;

  for (i=NumberBar(); i>=0; i--) {
    if (TimeHour(Time[i])==0 && TimeMinute(Time[i])==0) {
      HighLine=iHigh(Symbol(),0,i);
      LowLine=iLow(Symbol(),0,i);
    } else {
      if (MaxRange<=0 || MaxRange*Point>HighLine-LowLine) {
        if (iHigh(NULL,0,i)>HighLine) HighLine=iHigh(NULL,0,i);
        if (iLow(NULL,0,i)<LowLine) LowLine=iLow(NULL,0,i);
      }
    }
    AverLine=LowLine+(HighLine-LowLine)/2;

    kb=(StrToTime(TimeToStr(Time[0], TIME_DATE)+" 23:59")-Time[0])/Period()/60;
    if (i==0 && ShowContinue) {
      SetIndexShift(0, kb);
      SetIndexShift(1, kb);
      SetIndexShift(2, kb);
      for (j=kb; j>=0; j--) {
        shifthigh[j]=HighLine;
        shiftlow [j]=LowLine;
        shiftaver[j]=AverLine;
      }
    }
    shifthigh[i+kb]=HighLine;
    shiftlow [i+kb]=LowLine;
    shiftaver[i+kb]=AverLine;

    if (i==0 && ShowPrice) {
      DrawPrices(dt, "Price", HighLine, LowLine);
    }
  }
  Comment("Òåêóùèé äíåâíîé äèàïàçîí: "+DoubleToStr((HighLine-LowLine)/Point,0)+" ï.");
}

//+------------------------------------------------------------------+
//| Ïðîðèñîâêà öåíîâûõ ìåòîê íà ãðàôèêå                              |
//| Ïàðàìåòðû:                                                       |
//|   dt - äàòà òîðãîâîãî äíÿ                                        |
//|   no - íàèìåíîâàíèå îáúåêòà                                      |
//|   up - âåðõíèé öåíîâîé óðîâåíü                                   |
//|   dn - íèæíèé öåíîâîé óðîâåíü                                    |
//+------------------------------------------------------------------+
void DrawPrices(datetime dt, string no, double up, double dn) {
  if (ObjectFind("Up"+no)<0) ObjectCreate("Up"+no, OBJ_TEXT, 0, 0,0);
  ObjectSet("Up"+no, OBJPROP_TIME1   , dt);
  ObjectSet("Up"+no, OBJPROP_PRICE1  , up+(OffSet+SizeFont)*Point);
  ObjectSet("Up"+no, OBJPROP_COLOR   , clFont);
  ObjectSet("Up"+no, OBJPROP_FONTSIZE, SizeFont);
  ObjectSetText("Up"+no, DoubleToStr(up, Digits));

  if (ObjectFind("Dn"+no)<0) ObjectCreate("Dn"+no, OBJ_TEXT, 0, 0,0);
  ObjectSet("Dn"+no, OBJPROP_TIME1   , dt);
  ObjectSet("Dn"+no, OBJPROP_PRICE1  , dn-OffSet*Point);
  ObjectSet("Dn"+no, OBJPROP_COLOR   , clFont);
  ObjectSet("Dn"+no, OBJPROP_FONTSIZE, SizeFont);
  ObjectSetText("Dn"+no, DoubleToStr(dn, Digits));
}

//+------------------------------------------------------------------+ 
//| Âîçâðàùàåò íîìåð áàðà                                            |
//+------------------------------------------------------------------+ 
int NumberBar() {
  int nd=0, i=0;

  while (nd<NumberOfDays) {
    i++;
    if (TimeHour(Time[i])==0 && TimeMinute(Time[i])==0) nd++;
  }
  return(i);
}
//+------------------------------------------------------------------+

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