Script: Weighted Average

Short Name: weightedAvg

Definition: Returns a mobile weighted average

Usage: weightedAvg(20) or weightedAvg(RSI(14),20)

  • Returns a mobile weighted average of close values if only one parameter is present
  • Returns a mobile weighted average of an array if the first parameter is an array
  • Returns an array of values.

  • If only one parameter is present, and it is numeric, returns an array representing the mobile average of close values
  • If two parameters are present, returns a mobile average of the array values
  • weightedAvg(20) and weightedAvg(close,20) returns the same array of values
  • Weighted Average is somewhere in between simple and exponential average. It has the advantage of the exponential average in the sense the most recent data carry more weight but does not need as many data points to compute an accurate value. As an example, with a weighted average 3, the current day would have a weight of 2, previous would be 2, and the one before 1. Adding the three weighted points and dividing by 6 would return the value.

  • weightedAvg(20)
  • weightedAvg(rsi(14),20)
  • weightedAvg(dummyArray,20)