Basic Pivot indicator will draw line at bad location

 

hi

i'm having trouble with a basic indicator. it should only draw the pivot line the same way like a moving average line is drawn, but it will not work. it draws a horizontal line very far off from where it should be. please help me point out the mistake i've made, thanks!

#property indicator_buffers 3

#property indicator_color3 Lime

extern int PivotPeriod = 24; //Number of periods for Pivot

double Pivotbuffer[];

SetIndexBuffer(2, Pivotbuffer);

SetIndexStyle(2, DRAW_LINE, STYLE_DOT);


i = Bars - PivotPeriod;

double Top = iHigh("EURUSD",0,iHighest(NULL,0,MODE_HIGH,PivotPeriod,i));

double Bottom = iLow ("EURUSD",0,iLowest (NULL,0,MODE_LOW,PivotPeriod,i));

double Pivot = (Top+Bottom+Ask)/3;

while(i >= 0)

{

Pivotbuffer[i] = Pivot;

i--;

}

i am pretty sure this line is mostly at fault: "Pivotbuffer[i] = Pivot;" but i can't seem to figure it out.... thanks!

 

because Top & Bottom = 0.00000

so

(Top+Bottom+Ask)/3

is the same like Ask / 3

 
double Top = iHigh("EURUSD",0,iHighest(NULL,0,MODE_HIGH,PivotPeriod,i));
Means is will only work on EURUSD
double Top = High[ iHighest(NULL,0,MODE_HIGH,PivotPeriod,i) ];
 
crashtestdummy:

hi

i'm having trouble with a basic indicator. it should only draw the pivot line the same way like a moving average line is drawn, but it will not work. it draws a horizontal line very far off from where it should be. please help me point out the mistake i've made, thanks!

i am pretty sure this line is mostly at fault: "Pivotbuffer[i] = Pivot;" but i can't seem to figure it out.... thanks!

The only thing that changes from bar to bar is what is inside your while loop, i.e.

Pivotbuffer[i] = Pivot;

So all the values for your Buffer will be the same . . .

 
qjol:

because Top & Bottom = 0.00000

so

is the same like Ask / 3


Top and Bottom work right. i made the indicator to comment and manually checked it
 
WHRoeder:
Means is will only work on EURUSD

that is not a problem right now as i am testing on eurusd
 
RaptorUK:

The only thing that changes from bar to bar is what is inside your while loop, i.e.

So all the values for your Buffer will be the same . . .


yes, ive changed it to this:

Pivotbuffer[i] = (iHigh("EURUSD",0,iHighest(NULL,0,MODE_HIGH,PivotPeriod,i))+iLow ("EURUSD",0,iLowest (NULL,0,MODE_LOW,PivotPeriod,i))+Ask)/3;

and this is the result: http://i.imgur.com/uhuMC.png

the pivot indicator is the green dotted line. currently it has a period of 12 and is clearly very off and there are parts where it goes only horizontally for some strange reason?!

 
crashtestdummy:

there are parts where it goes only horizontally for some strange reason?!

Why strange ? you are using iLowest and iHighest . . if the lowest and highest are the lowest and highest for a few bars why shouldn't you get the same values for a few bars and thus get a horizontal line ?
 
RaptorUK:
Why strange ? you are using iLowest and iHighest . . if the lowest and highest are the lowest and highest for a few bars why shouldn't you get the same values for a few bars and thus get a horizontal line ?

yeah, you are right. :) also, at the pivot calculation i removed the "+Ask" and added "+Close[i]", because i figured Ask is always the current price and so the earlier results would be always off. i think i just needed some sleep :D thanks for your help! it seems to work alright now
 
another thing has come up. the backtesting of the ea based up on this indicator takes forever. if i press "skip to", then the test still goes very slowly. to backtest for a month or so takes about 1/2 hour. any tips why this may happen?
 
Are you doing stuff on every tick that you don't need to ?
Reason: