English

## Week High-Low from lower timeframe

 22 fonx 2015.01.07 13:50   Hi there, I've been fighting this thing since yesterday, tried different things, googled like a mad... I can't make it work. Let me explain:I want an indicator that marks with a vertical line the end of different times (end of day, end of week, end of month, end of quarter). The length of the vertical line goes from High to Low of the specific period, that way I can compare the end of the period with the overall range of the period:- End of Day (5pm NY, only visible when TF is < PERIOD_D1). The line goes from High to Low of that day. WORKS.- End of Week (Friday 5pm. Length of vertical line is from High to Low of that week. TF < PERIOD_W1). NOT WORKING- Month and quarter not implemented yet, I'm stack in the week one. Honestly, I don't know why the End of Week doesn't work, the logic should be quite similar than the End of Day. This is my Start() method. Below I'll copy the whole indicator code: ```void start() {    int counted_bars = IndicatorCounted();    if(counted_bars < 0) counted_bars=0;    if(counted_bars > 0) counted_bars--;    int limit = Bars-counted_bars;    for(int i = 0 ;i <= limit ;i++)    {       datetime t = iTime(Symbol(), Period(), i);              if(IsFriday(t) && IsEndOfDay(t) && DisplayEndOfWeek())       {            int barShift = iBarShift(Symbol(), PERIOD_W1, Time[i], false);                                l2UpBuffer[i] = iHigh(Symbol(), PERIOD_W1, barShift);          l2DnBuffer[i] = iLow(Symbol(), PERIOD_W1, barShift);       }       else if(IsEndOfDay(t) && DisplayEndOfDay())       {          int barShift = iBarShift(Symbol(),PERIOD_D1,Time[i]);          l1UpBuffer[i] = iHigh(Symbol(),PERIOD_D1, barShift);          l1DnBuffer[i] = iLow(Symbol(),PERIOD_D1, barShift);       }        }       return; }``` The Day mark works perfectly on H1 chart (aparently) but the weekly one at NY 5pm Friday does not work and I don't know why :(. Another problem that I just realised is that bars from D1 and above might not close at 5pm NY but that is an issue I'll fight later. My plan B is to calculate the number of bars for each period per time frame (for instance in H1 there are 118 bars per week I think) and having that number I can get High[Highest] and Low[Lowest]. But this approach is a bit more complex and not flexible.Any help is appreciated. Thanks in advance. #### whole indicator code, also attached ```//+------------------------------------------------------------------+ //|                                               End of Period.mq4 | //|                               Copyright 2014, Software Corp. | //|                                              https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2014, Software Corp." #property link      "https://www.mql5.com" #property version   "1.00" #property strict #property indicator_chart_window #property indicator_buffers 8 #property indicator_color1 DarkSlateGray #property indicator_color2 DarkSlateGray #property indicator_color3 DarkSlateGray #property indicator_color4 DarkSlateGray #property indicator_color5 DarkSlateGray #property indicator_color6 DarkSlateGray #property indicator_color7 Red #property indicator_color8 Red // external parameters   extern bool EndOfDay = true; extern bool EndOfWeek = true; extern bool EndOfMonth = true; extern bool EndOfQuarter = true;                                    // Global variables double l1UpBuffer[]; double l1DnBuffer[]; double l2UpBuffer[]; double l2DnBuffer[]; double l3UpBuffer[]; double l3DnBuffer[]; double l4UpBuffer[]; double l4DnBuffer[]; string prefix = "eop_"; string shortName = "AMG End of Period"; int init() {    IndicatorBuffers(6);    SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_DOT,1);    SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_DOT,1);    SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_DASH,1);    SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_DASH,1);    SetIndexStyle(4,DRAW_HISTOGRAM,STYLE_SOLID,1);    SetIndexStyle(5,DRAW_HISTOGRAM,STYLE_SOLID,1);    SetIndexStyle(6,DRAW_HISTOGRAM,STYLE_SOLID,1);    SetIndexStyle(7,DRAW_HISTOGRAM,STYLE_SOLID,1);       SetIndexBuffer(0,l1UpBuffer);    SetIndexBuffer(1,l1DnBuffer);       SetIndexBuffer(2,l2UpBuffer);    SetIndexBuffer(3,l2DnBuffer);       SetIndexBuffer(4,l3UpBuffer);    SetIndexBuffer(5,l3DnBuffer);       SetIndexBuffer(6,l4UpBuffer);    SetIndexBuffer(7,l4DnBuffer);    IndicatorShortName(shortName);       return(INIT_SUCCEEDED); } void OnDeinit(const int reason) {    ObjectsDeleteAll();    //ResetHud(); } void ResetHud() { } void start() {    int counted_bars = IndicatorCounted();    if(counted_bars < 0) counted_bars=0;    if(counted_bars > 0) counted_bars--;    int limit = Bars-counted_bars;    for(int i = 0 ;i <= limit ;i++)    {       datetime t = iTime(Symbol(), Period(), i);              if(IsFriday(t) && IsEndOfDay(t) && DisplayEndOfWeek())       {            int barShift = iBarShift(Symbol(), PERIOD_W1, Time[i], false);                                l2UpBuffer[i] = iHigh(Symbol(), PERIOD_W1, barShift);          l2DnBuffer[i] = iLow(Symbol(), PERIOD_W1, barShift);       }       else if(IsEndOfDay(t) && DisplayEndOfDay())       {          int barShift = iBarShift(Symbol(),PERIOD_D1,Time[i]);          l1UpBuffer[i] = iHigh(Symbol(),PERIOD_D1, barShift);          l1DnBuffer[i] = iLow(Symbol(),PERIOD_D1, barShift);       }        }       return; } bool DisplayEndOfDay() {    return EndOfDay && Period() < PERIOD_D1; } bool DisplayEndOfWeek() {    return EndOfWeek && Period() <= PERIOD_D1; } bool DisplayEndOfMonth() {    return EndOfMonth && Period() <= PERIOD_W1; } bool DisplayEndOfQuarter() {    return EndOfQuarter; } // End of day is 5pm NY time bool IsEndOfDay(datetime t) {    return TimeHour(t) == 17; } // 0-Sunday,1,2,3,4,5,6 bool IsFriday(datetime t) {    return TimeDayOfWeek(t) == 5; } ```  Attached files:   amgbenduofiperiod.mq4  (3.56 KB)
 22 fonx 2015.01.07 15:20 #   angevoyageur: What do you mean by "doesn't work" ?I mean that I don't see a line that goes from the highest of the week to the lowest of the week at 5pm on Friday. There is no line at all. I can put:```      if(IsFriday(t) && IsEndOfDay(t) && DisplayEndOfWeek())       {            l2UpBuffer[i] = High[i] + 0.01;          l2DnBuffer[i] = Low[i] - 0.01;       }```and it draws a vertical line from the H1 candle, 100 pips up from the high of i and 100 pips down from the low of i. But if I try to get the highest and lowest of the week nothing comes to the chart.
 250 ffoorr 2015.01.07 22:16 #   hi man Try something like that, put different color for the buffers :```void start() {    int limit=-1,  counted_bars = IndicatorCounted();    if(counted_bars < 100)  limit = Bars -1000 ;    if(counted_bars > 0) counted_bars--;     limit = Bars-counted_bars;    for(int i = limit ;i >= 0 ;i--)    {       if(TimeDayOfWeek(iTime(Symbol(), Period(), i) )==5 && TimeHour(iTime(Symbol(), Period(), i) ) == 20 )       {          int barShift = iBarShift(Symbol(), PERIOD_W1, Time[i]);                              if( iClose(Symbol(), PERIOD_W1, barShift) > iOpen(Symbol(), PERIOD_W1, barShift) )          {         l2DnBuffer[i]  = iHigh(Symbol(), PERIOD_W1, barShift);         l2UpBuffer[i]  = iLow(Symbol(), PERIOD_W1, barShift);          }          else         {         l2UpBuffer[i] = iHigh(Symbol(), PERIOD_W1, barShift);         l2DnBuffer[i] = iLow(Symbol(), PERIOD_W1, barShift);          }       }    }    return; } ```what's showed up :It seem nothing special happen at the end of a week.Traders may close winning orders and hedge loosing orders, waiting for the monday morning, but nothing can be see on the chart price ! ;-)