Help on this codes
Created at 28 Sep 2015, 09:33
Help on this codes
28 Sep 2015, 09:33
Hi I'm very new to calgo & programming. My code doesn't seem to work & I'm not sure what went wrong. Can anyone please guide me what went wrong. This is based on J. Ehlers' Universal Oscillator http://traders.com/Documentation/FEEDbk_docs/2015/01/TradersTips.html
Thanks
using System; using cAlgo.API; using cAlgo.API.Indicators; namespace cAlgo.Indicators { [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, ScalePrecision = 5)] public class UniversalOscillator : Indicator { #region Variables private IndicatorDataSeries _filt; private IndicatorDataSeries _wn; private double peak; private double uni; private double a1; private double b1; private double c1; private double c2; private double c3; #endregion #region Parameters [Output("Universal Oscillator", Color = Colors.Purple)] public IndicatorDataSeries Universal { get; set; } [Parameter("BandEdge", DefaultValue = 20)] public int Period2 { get; set; } [Parameter()] public DataSeries Source { get; set; } #endregion protected override void Initialize() { _filt = CreateDataSeries(); _wn = CreateDataSeries(); a1 = Math.Exp(-Math.Sqrt(2) * Math.PI / Period2); b1 = 2 * a1 * Math.Cos(Math.Sqrt(2) * Math.PI / Period2); c2 = b1; c3 = -a1 * a1; c1 = 1 - c2 - c3; _wn[0] = 0; _wn[1] = 0; _filt[0] = 0; _filt[1] = 0; } public override void Calculate(int index) { if (index < 2) return; _wn[index] = Source[index - 1] + Source[index - 2] / 2; _filt[index] = c1 * (_wn[index] + _wn[index - 1]) / 2 + c2 * _filt[index - 1] + c3 * _filt[index - 2]; peak = 0.991 * peak; if (Math.Abs(_filt[index]) > peak) peak = Math.Abs(_filt[index]); if (peak != 0) uni = _filt[index] / peak; Universal[index] = uni; } } }
Replies
ClickAlgo
28 Sep 2015, 14:34
Just with a quick look you have removed: an IndicatorDataSeries
private IndicatorDataSeries _filt; private IndicatorDataSeries _wn; private IndicatorDataSeries _pk; private double a1; private double b1; private double c1; private double c2; private double c3;
I would put the original code back and start again or let us know what the exact problem is.
@ClickAlgo
lunarus
28 Sep 2015, 13:34
I made a correction & it looks identical to the results in the other platform but I wasn't sure if the codes was exactly correct
@lunarus