54 private readonly
int _period;
55 private readonly
double _a0 = 1;
56 private readonly
double _a1 = 0;
57 private readonly
double _a2 = 0;
58 private readonly
double _b0 = 1;
59 private readonly
double _b1 = 0;
60 private readonly
double _b2 = 0;
61 private readonly
double _c0 = 1;
70 : this($
"Swiss({period},{delta},{tool})", period, delta, tool)
87 var beta = 2.415 * (1 - Math.Cos(2 * Math.PI / period));
88 var alpha = -beta + Math.Sqrt(Math.Pow(beta, 2) + 2d * beta);
94 _a1 = 2d * (1 - alpha);
95 _a2 = -(1 - alpha) * (1 - alpha);
98 _c0 = alpha * alpha / 4d;
101 _a1 = 2d * (1 - alpha);
102 _a2 = -(1 - alpha) * (1 - alpha);
105 alpha = (Math.Cos(2 * Math.PI / period) + Math.Sin(2 * Math.PI / period) - 1) / Math.Cos(2 * Math.PI / period);
106 _c0 = (1 + alpha) / 2;
111 _c0 = (1 + alpha) * (1 + alpha) / 4;
114 _a1 = 2d * (1 - alpha);
115 _a2 = -(1 - alpha) * (1 - alpha);
118 beta = Math.Cos(2 * Math.PI / period);
119 var gamma = (1 / Math.Cos(4 * Math.PI * delta / period));
120 alpha = gamma - Math.Sqrt(Math.Pow(gamma, 2) - 1);
121 _c0 = (1 - alpha) / 2d;
124 _a1 = -beta * (1 - alpha);
128 throw new ArgumentOutOfRangeException(nameof(tool), tool,
"Invalid SwissArmyKnifeTool");
135 public override bool IsReady => Samples >= _period;
149 _price.Add((
double)input.
Price);
151 if (_price.Samples == 1)
153 _price.Add(_price[0]);
154 _price.Add(_price[0]);
157 var signal = _a0 * _c0 * (_b0 * _price[0] + _b1 * _price[1] + _b2 * _price[2]) + _a0 * (_a1 * _filt[0] + _a2 * _filt[1]);
161 return (decimal)signal;