View Single Post
  #2 (permalink)  
Old 02-22-2007, 10:15 AM
ralph.ronnquist's Avatar
ralph.ronnquist ralph.ronnquist is offline
Senior Member
 
Join Date: Oct 2006
Posts: 280
ralph.ronnquist is on a distinguished road
Quote:
Originally Posted by anthonyrae
Hi,

I'm just wondering how you would calculate the moving average high for each candle.

I'm wondering if this is correct :

for(i=0; i <= Bars; i++)
{
hi[i] = High[iHighest(NULL, 0, MODE_HIGH, p, 0)];
}

where p is the number of periods
On straight reading, your code is the same as the following:
PHP Code:
double v High[iHighest(NULL0MODE_HIGHp0)];
for(
i=0<= Barsi++) {
    
hi[i] = v;

which I wouldn't call a Moving Average of any description. Rather, it picks the highest high within the most recent period of size p, and then plots that value for all bars.

Rather, a Simple Moving Average over the highs of bars would be coded like the following:
PHP Code:
double v 0;
for ( 
Bars-1>= Bars-1-pi-- ) {
    
+= High[i];
}
hiBars-1-] = p;
for( 
Bars-1-p-1>= 0i--) {
    
hi[i] = hi[i+1] + ( High[i] - High[i+p] ) / p;

And a Smoothed Simple Moving Average, which is a simpler method, over the highs of bars would be coded like the following:
PHP Code:
hiBars-] = HighBars-];
for(
i=Bars 2>= 0i--) {
    
hi[i] = ( hi[i+1] * ( ) + High] ) / p;

Reply With Quote