• Get $40 off VIP by signing up for a free account! Sign Up

Scan: Find when WMA is x% below EMA (within last x agg)

orionanomaly

New member
Hello all! I know this is basic but I seem to be doing something wrong. I want to scan to find stocks with one average that is BELOW another average but close (so looking for BEFORE it might 'cross over'). Exclude those ABOVE.

I am spec. looking for when WMA10 <= 0.5% EMA 40 //So when the WMA is Less Than AND within 0.5% of the EMA. I can then find stocks that have one average below another but within 1% of each other.

I have this but can't figure out why it's not working (I am getting for example results that show a < b even though I have a > b! Any help would be SO appreciated!! :)

Code:
#start code

def a = ExpAverage(close, 40);
def b = WMA(close, 10);
def percentValue = .005;

plot scan = a > b and absValue(a-b) is less than or equal to (a*percentValue);

#end code
 
Last edited:
Solution
Hello! Ok, thank you very much for referencing!

I realized that I was asking the wrong question:

1. When coding a scan filter if you use the 'template builder' you are able to specify "how many bars" are used in the scan filter; it's an option.

2. I wanted to be able to implement this since I now have a hand-coded script. I realized what I was looking for was the "within" protected word. So I can return/chart the result "within x bars".


My final (I believe to be) working scan (which looks at the last 3 bars and finds Exp40 > WMA7 by 1.5% or less and returns them looks like this (and can add the code provided above to tag the chart for inspection if want):

Code:
def a = ExpAverage(close, 40);
def b = WMA(close, 7);
def...
Hello all! I know this is basic but I seem to be doing something wrong. I want to scan to find stocks with one average that is BELOW another average but close (so looking for BEFORE it might 'cross over'). Exclude those ABOVE.

I am spec. looking for when WMA10 <= 0.5% EMA 40 //So when the WMA is Less Than AND within 0.5% of the EMA. I can then find stocks that have one average below another but within 1% of each other.

I have this but can't figure out why it's not working (I am getting for example results that show a < b even though I have a > b! Any help would be SO appreciated!! :)

Code:
#start code

def a = ExpAverage(close, 40);
def b = WMA(close, 10);
def percentValue = .005;

plot scan = a > b and absValue(a-b) is less than or equal to (a*percentValue);

#end code

if i get stuck, i put the code on a chart and use bubbles to display values on each bar. then see if the values are what i think they should be. look at a few stocks of the desired time.

add this
Code:
addchartbubble(1, low, (a > b) + "\n" + absValue(a-b) + "\n" +  (a*percentValue), color.cyan, no);
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Hello! Thank you so much this was very helpful! I added in a few other 'debug' metrics and it looks like it's doing exactly what I thought... my error was actually in the way I had the timeframes set.

*I don't think I understand how timeframes work in the scanner. When you set "D" (DAY) for the aggregation period - what does that mean? Is it performing the scan function on the most recent DAY candle?

1. If I put the scanner at 15M - does it only scan/search against the most recent 15M candle?

2. What if I want to specify in my search function whether the condition was true "in the last x number of candles" and then select the time agg period?
 
Hello! Ok, thank you very much for referencing!

I realized that I was asking the wrong question:

1. When coding a scan filter if you use the 'template builder' you are able to specify "how many bars" are used in the scan filter; it's an option.

2. I wanted to be able to implement this since I now have a hand-coded script. I realized what I was looking for was the "within" protected word. So I can return/chart the result "within x bars".


My final (I believe to be) working scan (which looks at the last 3 bars and finds Exp40 > WMA7 by 1.5% or less and returns them looks like this (and can add the code provided above to tag the chart for inspection if want):

Code:
def a = ExpAverage(close, 40);
def b = WMA(close, 7);
def percentValue = .015;


plot scan = a > b and absValue(a-b) is less than or equal to (a*percentValue) within 3 bars;
 
Solution

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
529 Online
Create Post

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