Need help with TD Pivot indicator

 

Hi,

I need some help with the TD Pivot indicator.

I want the indicator to show the weekly pivot lines on the daily chart. As you can see on the attached picture, the indicator builds the pivot lines of seven days instead of five days.

What to do to make the indicator build the pivot and show the pivot of five consecutive days instead of seven?

The code is:

//+------------------------------------------------------------------+//| TD Pivot.mq4 |//+------------------------------------------------------------------+#property indicator_chart_window#property indicator_buffers 2#property indicator_color1 RoyalBlue#property indicator_color2 OrangeRed//---- buffersdouble high[],low[];//+------------------------------------------------------------------+//| Custom indicator initialization function |//+------------------------------------------------------------------+int init(){IndicatorShortName("TD Pivot");//---- indicatorsSetIndexLabel (0,"High");SetIndexStyle (0,DRAW_LINE);SetIndexBuffer(0,high);SetIndexLabel (1,"Low");SetIndexStyle (1,DRAW_LINE);SetIndexBuffer(1,low);//----return(0);}//+------------------------------------------------------------------+//| Custom indicator iteration function |//+------------------------------------------------------------------+int start(){//----for (int i = Bars-IndicatorCounted(); i >= 0; i--){if(TimeHour(iTime(NULL,0,i)) != 0){high = high[i+1];
low = low[i+1];
continue;
}

int candlesPerWeek = PERIOD_W1/Period(),
week = MathFloor(i/candlesPerWeek)+1;

double H = iHigh(NULL,PERIOD_W1,week),
L = iLow(NULL,PERIOD_W1,week),
O = iOpen(NULL,PERIOD_W1,week),
C = iClose(NULL,PERIOD_W1,week),
X;

if (C < O) X = H + 2*L + C;
else if (C > O) X = 2*H + L + C;
else if (C ==O) X = H + L + 2*C;

high = 0.5*X - L;
low = 0.5*X - H;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Files:
td-pivot.gif  12 kb
Reason: