Hi guys, I have code for a pivot indicator here that was written by someone else here on the forums, and then I modified it slightly to do a thing or two different that I wanted. At any rate, the problem that occurs is what you see in the picture. If I specify to draw the pivots for 1 day, random lines from previous days are shown at various points on the chart. If I switch to another TF, and switch back, then the lines usually disappear. So I don't think it's necessarily a code problem, but something with the way the bars are counted or something. Can anyone give me any insight? I'm attaching the code in plain text to this post for quick reading, and the picture is below.
Inserted Code
//+------------------------------------------------------------------+ //| Auto-Pivot Plotter Daily V1-00.mq4 | //| Copyright © 2007, BundyRaider | //| | //+------------------------------------------------------------------+ #property link "" #property indicator_chart_window #property indicator_buffers 7 #property indicator_color1 Black #property indicator_color2 Navy #property indicator_color3 Blue #property indicator_color4 White #property indicator_color5 Orange #property indicator_color6 Red #property indicator_color7 FireBrick #property indicator_width4 2 extern int DaysToPlot = 1; extern bool ChangeToFibonacci=False; double Res3[]; double Res2[]; double Res1[]; double Pivot[]; double Supp1[]; double Supp2[]; double Supp3[]; int init() { if (Period() > PERIOD_H1) return(1); SetIndexBuffer(0,Res3); SetIndexLabel(0,"Daily R3"); SetIndexBuffer(1,Res2); SetIndexLabel(1,"Daily R2"); SetIndexBuffer(2,Res1); SetIndexLabel(2,"Daily R1"); SetIndexBuffer(3,Pivot); SetIndexLabel(3,"Daily Pivot"); SetIndexBuffer(4,Supp1); SetIndexLabel(4,"Daily S1"); SetIndexBuffer(5,Supp2); SetIndexLabel(5,"Daily S2"); SetIndexBuffer(6,Supp3); SetIndexLabel(6,"Daily S3"); IndicatorDigits(Digits); return(0); } int deinit() { return(0); } int start() { int counted_bars=IndicatorCounted(); if(counted_bars<0) return(-1); //---- last counted bar will be recounted if(counted_bars>0) counted_bars--; // int limit=Bars-counted_bars; int limit = Bars; int PreviousDailyBar = -1; int DaysPlotted = -1; for(int i=0; i<limit; i++) { datetime DayDate=Time[i]; int DailyBar = iBarShift( NULL, PERIOD_D1, DayDate,false)+1; if (DaysToPlot > 0) { if (PreviousDailyBar != DailyBar) { DaysPlotted++; PreviousDailyBar = DailyBar; } if (DaysPlotted >= DaysToPlot) { if (DaysToPlot == 1 && Pivot[0] != Pivot[1]) { Pivot[1] = Pivot[0]; Res1[1] =Res1[0]; Res2[1] =Res2[0]; Res3[1] =Res3[0]; Supp1[1]=Supp1[0]; Supp2[1]=Supp2[0]; Supp3[1]=Supp3[0]; } return (0); } } double PreviousHigh = iHigh(NULL, PERIOD_D1,DailyBar); double PreviousLow = iLow(NULL, PERIOD_D1,DailyBar); double PreviousClose = iClose(NULL, PERIOD_D1,DailyBar); if(ChangeToFibonacci==False) { double P = (PreviousHigh+PreviousLow+PreviousClose)/3; double R1 = (2*P)-PreviousLow; double S1 = (2*P)-PreviousHigh; double R2 = P+(PreviousHigh - PreviousLow); double S2 = P-(PreviousHigh - PreviousLow); double R3 = (2*P)+(PreviousHigh-(2*PreviousLow)); double S3 = (2*P)-((2* PreviousHigh)-PreviousLow); } else { P = (PreviousHigh+PreviousLow+PreviousClose)/3; R1 = P + ((PreviousHigh-PreviousLow) * 0.382); S1 = P - ((PreviousHigh-PreviousLow) * 0.382); R2 = P + ((PreviousHigh-PreviousLow) * 0.618); S2 = P - ((PreviousHigh-PreviousLow) * 0.618); R3 = P + ((PreviousHigh-PreviousLow) * 1.000); S3 = P - ((PreviousHigh-PreviousLow) * 1.000); } Pivot[i]= NormalizeDouble( P, Digits); Res1[i] =R1; Res2[i] =R2; Res3[i] =R3; Supp1[i]=S1; Supp2[i]=S2; Supp3[i]=S3; } return(0); }