//This static method allows ad-hoc calculation of FractDim (single calc mode) public static double Calculate(int bar, TimeSeries ds, int period) { if (period < 2 || period > bar + 1) { return(0); } // Calculate length double Range = Highest.Calculate(bar, ds, period) - Lowest.Calculate(bar, ds, period); if (Range <= 0) { return(0); } double L = 0; for (int j = bar - period + 2; j <= bar; j++) { // Transform Y double dY = ds[j] - ds[j - 1]; // Calculate Length - X is transformed to bars L += hypot(dY / Range, 1 / (period - 1)); } // Calculate Fractal Dimension Approximation return(1 + Math.Log(L) / Math.Log(2 * (period - 1))); }
//This static method allows ad-hoc calculation of RSS (single calc mode) public static double Calculate(int bar, BarHistory ds, int period) { //Avoid exception errors if (period < 2) { return(Double.NaN); } double range = Highest.Calculate(bar, ds.High, period) - Lowest.Calculate(bar, ds.Low, period); if (range <= 0) { return(Double.NaN); } return(Math.Log10(range) / Math.Log10(period)); }
//This static method allows ad-hoc calculation of TTF (single calc mode) public static double Calculate(int bar, BarHistory ds, int period) { if (bar < 2 * period - 1) { return(0); } double BuyPwr = Highest.Calculate(bar, ds.High, period) - Lowest.Calculate(bar - period, ds.Low, period); double SellPwr = Highest.Calculate(bar - period, ds.High, period) - Lowest.Calculate(bar, ds.Low, period); if (BuyPwr + SellPwr == 0) { return(0); } return(200 * (BuyPwr - SellPwr) / (BuyPwr + SellPwr)); }
//populate public override void Populate() { //get parameter values BarHistory source = Parameters[0].AsBarHistory; int period = Parameters[1].AsInt; int fastEMA = Parameters[2].AsInt; int slowEMA = Parameters[3].AsInt; DateTimes = source.DateTimes; if (source.Count < period + 1) { return; } //calculate AMA, populate double fastSC = 2.0 / (fastEMA + 1.0); double slowSC = 2.0 / (slowEMA + 1.0); double priorAMA = source.Close[period]; for (int n = period + 1; n < source.Count; n++) { //MLTP double mltp = 0.5; double c = source.Close[n]; double hh = Highest.Calculate(n, source.High, period + 1); double ll = Lowest.Calculate(n, source.Low, period + 1); double diff = hh - ll; if (diff != 0 && !Double.IsNaN(diff)) { mltp = Math.Abs((c - ll) - (hh - c)) / diff; } //Smoothing constant double ssc = mltp * (fastSC - slowSC) + slowSC; double constant = Math.Pow(ssc, 2.0); //current AMA Values[n] = priorAMA + constant * (c - priorAMA); priorAMA = Values[n]; } }