public WSum(int period) { lastBar = -1; bars = 0; sum = 0; value = new double[this.period = Math.Max(period, 1)]; set = set_startup; }
private double set_startup(double curVal, int barNum) { if ( barNum == lastBar ) sum -= value[barNum % period] * bars; else { lastBar = barNum; if ( ++bars == period ) set = set_running; } return sum += (value[barNum % period] = curVal) * bars; }
private double set_startup(double curVal, int barNum) { if (barNum == lastBar) { sum -= value[barNum % period] * bars; } else { lastBar = barNum; if (++bars == period) { set = set_running; } } return(sum += (value[barNum % period] = curVal) * bars); }