// Downloaded From https://www.WiseStockTrader.com function SNR(Input, Periods, Alphas) { Result = 0; Noise = 0; // we need a seed value here to keep from referencing uninitialized memory Result[21] = 0.0; for (i = 22; i < BarCount; i++) { alpha = Alphas[i]; if (alpha < 0) alpha = 0; if (alpha > 1) alpha = 1; period = Periods[i]; if (period < 4) period = 4; // this will guarentee one count in the loop below if ((period / 2 - 1) > 99) period = (99 + 1) * 2; Smooth[i] = (4.0 * Input[i] + 3.0 * Input[i-1] + 2.0 * Input[i-2] + 1.0 * Input[i-3]) / 10.0 ; //Q3[0] = (float)ForceFloatRange( .5 * period); Q3[i] = .5 * (Smooth[i] - Smooth[i-2]) * (.1759*period + .4607) ; I3 = 0.0; for (count = 0; count <= int(period / 2) - 1; count++) I3 = I3 + Q3[BarCount-1 - count]; //if (period == 2) // I3 = 0.0; //else I3 = 1.57 * I3 / int(period / 2); Signals = I3*I3 + Q3[i]*Q3[i]; Noise[i] = .1 * (High[i] - Low[i]) *(High[i] - Low[i]) *.25 + .9*Noise[i-1]; if (Noise[i] != 0 && Signals != 0) { Result[i] = alpha * (10*log(Signals/Noise[i]) / log(10)) + (1-alpha) * Result[i-1]; } } return Result; } // subtract 6 to center over zero. SNRs = SNR(Close, 20, .5); //Plot(Close, "Close", colorBlack); Plot(SNRs, "SNR", colorRed);