VHF Script

I am trying to calculate the Vertical Horizontal Filter:

Select the number of periods (n) to include in the indicator. This should be based on the length of the cycle that you are analyzing. The most popular is 28 days (for intermediate cycles).

  1. Determine the highest closing price (HCP) in n periods.
  2. Determine the lowest closing price (LCP) in n periods.
  3. Calculate the range of closing prices in n periods:
    HCP - LCP
  4. Next, calculate the movement in closing price for each period:
    Closing price [today] - Closing price [yesterday]
  5. Add up all price movements for n periods, disregarding whether they are up or down:
    Sum of absolute values of ( Close [today] - Close [yesterday] ) for n periods
  6. Divide Step 4 by Step 6:
    VHF = (HCP - LCP) / (Sum of absolute values for n periods)

Below is the script i am using but in step 5 can u please help. V4 is not giving desired output

v1 = abs(HIGHESTHIGH(BARS=63)); 
v2 = abs(LOWESTLOW(BARS=63));
v3 = abs(CLOSE() - CLOSE()[1]); 
v4 = ACC(v3, BARS=63);

Hi,

Try the following script:

// Set Close
V1 = CLOSE();
// Find Highest Close
HCP = HIGHESTHIGH(V1, BARS=28, INCBAR=True) ;
// Find Lowest Close
LCP = LOWESTLOW(V1, BARS=28, INCBAR=True) ;
// Calc Range in Closing Prices
V2 = HCP - LCP ;
// Calc Absolute Movement in Closing Prices
V3 = ABS(CLOSE() - CLOSE(1)) ;
// Sum V3 for selected period
V4 = ACC(V3, BARS=28, RANGE=Look Back Period, BACKTYPE=Bars);
//Final Calc
VHF = (HCP - LCP) / V4 ;
VHF