Scanner for monthly down stocks at certain %

serendipity2020

Member
Plus
Hello

I created scan in ToS with monthly aggregation with below code to find stocks that are down in Jan month at least 80% of the time. However, it seems to be reporting incorrect results. When plotted this in the chart, it shows correct results but the scanner does not return correct data. What am I missing?

def targetMonth = getmonth() == 1;

def down = close < open;

def ctDownMonths = if targetMonth then down else 0;

rec totalMonths = if targetMonth then totalMonths[1] + 1 else totalMonths[1];
rec downMonths = if ctDownMonths then downMonths[1] + 1 else downMonths[1];

def percentDown = 100 * (downMonths / totalMonths);

plot signal = percentDown > 80;

Note: I created scan by copying above code in thinkscript editor and selected aggregation as "Mo".
 
Solution
Hello

I created scan in ToS with monthly aggregation with below code to find stocks that are down in Jan month at least 80% of the time. However, it seems to be reporting incorrect results. When plotted this in the chart, it shows correct results but the scanner does not return correct data. What am I missing?



Note: I created scan by copying above code in thinkscript editor and selected aggregation as "Mo".

if you are comparing chart results to scan, maybe the difference is that a scan will use a short period of data. maybe a year? i forget how much.
https://usethinkscript.com/threads/fib-scan-watchlist.9857/#post-126493


here is a lower study to experiment with. could alter it to use in a column.
set chart to...
Hello

I created scan in ToS with monthly aggregation with below code to find stocks that are down in Jan month at least 80% of the time. However, it seems to be reporting incorrect results. When plotted this in the chart, it shows correct results but the scanner does not return correct data. What am I missing?



Note: I created scan by copying above code in thinkscript editor and selected aggregation as "Mo".

if you are comparing chart results to scan, maybe the difference is that a scan will use a short period of data. maybe a year? i forget how much.
https://usethinkscript.com/threads/fib-scan-watchlist.9857/#post-126493


here is a lower study to experiment with. could alter it to use in a column.
set chart to month
i renamed some variables, to be more descriptive.
draws a cyan line, for output, that is 0 or 1.
draws a line with downward spikes, for each target month. a longer spike if it is a down month.
bubbles with totals and %

Code:
#scan_jan_lower

#https://usethinkscript.com/threads/scanner-for-monthly-down-stocks-at-certain.18061/
#Scanner for monthly down stocks at certain %

declare lower;

def na = Double.NaN;
def bn = BarNumber();

def is = !isnan(close);
input target_month = 1;
def is_month = GetMonth() == target_month;

def up = close > open;
def down = close < open;
def is_dwn_mo = (is_month and down);

def total_target_months = if bn == 1 then 0 else if is_month then total_target_months[1] + 1 else total_target_months[1];
def total_down_months = if bn == 1 then 0 else if is_dwn_mo then total_down_months[1] + 1 else total_down_months[1];

def percentDown = round(100 * (total_down_months / total_target_months),1);
input target_percent = 80.0;
plot signal = (percentDown > target_percent);

# ===========================
# for a scan , disable code after this line

signal.setdefaultcolor(color.cyan);

input test_line = yes;
plot z1 = if !test_line or !is then na
 else if !is_month then -0.1
 else if is_dwn_mo then -is_dwn_mo
 else -0.3;
z1.setdefaultcolor(getcolor(2));

input bubble = yes;
AddChartBubble(bubble and is_month and is, 0.2,
 total_down_months + "/" + total_target_months + "\n" +
 percentDown + " %\n"
, Color.YELLOW, yes);


input test_bubble = no;
AddChartBubble(test_bubble and !IsNaN(close), 1,
 is_month + " mo\n" +
 down + " D\n" +
 is_dwn_mo  + " Dmo\n" +
 total_target_months + " tot\n" +
 total_down_months + " cnt\n" +
 percentDown + " %\n"
, Color.YELLOW, yes);
#
 

Attachments

  • img1.JPG
    img1.JPG
    145.6 KB · Views: 46
Last edited:
Solution

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
365 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