Gaussian filter and ema9 cross scan

camerdr

New member
VIP
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.

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:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
577 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top