Here is a scanner that I use for the Gaussian filter and ema9 cross.
@samer800 please check out this scan and see if there is any further optimization that can be done to it.
@samer800 please check out this scan and see if there is any further optimization that can be done to it.
Ruby:
input period = 25;
input noOfPoles = 5;
input FilterOptions = {"Price", default "Gaussian Filter", "Both", "None"};
input filterPeriod = 10;
input FilterDevaitions = 1;
input ReducedLagMode = no;
input FastResponseMode = no;
# Define Pi
def pi = 3.14159265358979;
# Price & Gaussian Filter
def price = FilterOptions == FilterOptions."Price" or FilterOptions == FilterOptions."Both";
def gauss = FilterOptions == FilterOptions."Gaussian Filter" or FilterOptions == FilterOptions."Both";
# Variables
def w = 2.0 * pi / period;
def beta = (1.0 - Cos(w)) / (Power(1.414, 2.0 / noOfPoles) - 1.0);
def alpha = - beta + Sqrt(Power(beta, 2) + 2 * beta);
def lag = (period - 1) / (2 * noOfPoles);
def tr = TrueRange(high, close, low);
def srcData = if ReducedLagMode then 2 * close - close[lag] else close;
def trdata = if ReducedLagMode then 2 * tr - tr[lag] else tr;
# Basic Filtering (Replaces custom _filt function)
def filtSrc = if FilterDevaitions > 0 then Average(srcData, filterPeriod) else srcData;
def src = if price and FilterDevaitions > 0 then filtSrc else srcData;
# Using moving average for the "pole" and "filter" functionality
def filtn = Average(src, noOfPoles);
def filt1 = Average(src, 1); # Simplified to single-period moving average
def filtntr = Average(trdata, noOfPoles);
def filt1tr = Average(trdata, 1);
# Using the average for fast response mode
def filt = if FastResponseMode then (filtn + filt1) / 2 else filtn;
def filttr = if FastResponseMode then (filtntr + filt1tr) / 2 else filtntr;
# Filtering again based on standard deviation
def filtStd = Average(filt, filterPeriod);
def filtBand = Average(filttr, filterPeriod);
def std = if gauss and FilterDevaitions > 0 then filtStd else filt;
def fTR = if gauss and FilterDevaitions > 0 then filtBand else filttr;
# Bands and Signals
def hband = std + fTR * 2.0;
def lband = std - fTR * 2.0;
# Handle NaN replacement with conditional logic
def sig = if isNaN(std[1]) then 0 else std[1];
def state = if (std > sig) then 1 else if (std < sig) then -1 else 0;
# Signal conditions for scanning
def pregoLong = std > sig and (sig < sig[1] or sig == sig[1]);
def pregoShort = std < sig and (sig > sig[1] or sig == sig[1]);
def contsw = if pregoLong then 1 else if pregoShort then -1 else contsw[1];
def goLong = pregoLong and contsw[1] == -1;
def goShort = pregoShort and contsw[1] == 1;
# Add the 9-period EMA
def ema9 = ExpAverage(close, 9);
# Scan for when EMA 9 crosses above the std (standard value)
plot scanLong = ema9 crosses above std;
Last edited by a moderator: