# Stock Market Days Up vs. Days Down Indicator for ThinkorSwim

#### korygill

##### Well-known member
VIP
Don't try to reverse engineer what this image shows...I'll post the code/description later...

Just wondering if anyone sees a way to play this indicator?

Well, not a lot of input here, but really I wrote this because someone said there are about the same number of up days and down days in a given year. So of course I set out to measure this...who knows, maybe mean reversion or something could be some odd indicator.

As promised, here is the code for this Up Down Ratio. The plots above are year/month/week on a 1-Day chart.

Enjoy

Code:
``````# Stock Market Days Up vs. Days Down Indicator for ThinkorSwim
#
# Shows number of up days versus down days.
#
# Author: Kory Gill, @korygill
#

declare lower;
declare once_per_bar;

input RollOverPeriod = {default year, month, week};

def vClose = close;
def year = GetYear();
def month = GetMonth();
def week = GetWeek();
def isRollOver;
def lookback;

switch (RollOverPeriod) {
case year:
isRollOver = if year != year[1] then 1 else 0;
lookback = 252;
case month:
isRollOver = if month != month[1] then 1 else 0;
lookback = 20;
case week:
lookback = 5;
isRollOver = if week != week[1] then 1 else 0;
};

def bn = BarNumber();

def upCount = if bn == 1 then 0
else if isRollOver then if vClose >= vClose[1] then 1 else 0
else if vClose >= vClose[1] then upCount[1]+1 else upCount[1];

def dnCount = if bn == 1 then 0
else if isRollOver then if vClose < vClose[1] then -1 else 0
else if vClose < vClose[1] then dnCount[1]-1 else dnCount[1];

# used for debugging
#plot pUpCount = upCount;
#plot pDnCount = dnCount;
#plot pTotal = upCount - dnCount;

plot zeroLine = 0;
zeroLine.SetDefaultColor(Color.White);

def upSum = Sum(upCount, lookback);
def dnSum = Sum(dnCount, lookback);
plot pSumUpDnRatio = if dnSum != 0 then (upSum+dnSum)/(upSum-dnSum)*100 else 0;
pSumUpDnRatio.AssignValueColor(if pSumUpDnRatio >= 0 then Color.Green else Color.Red);
pSumUpDnRatio.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);

plot pUpVsDn = upCount + dnCount;
pUpVsDn.AssignValueColor(if pUpVsDn >= 0 then Color.Yellow else Color.Magenta);
pUpVsDn.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);

#### Attachments

• tlr8ksr.png
129.3 KB · Views: 260
Last edited by a moderator:
Well the obvious setup is 0 line cross on fastest momentum(bottom) when in confluence with slower momentum (mid).

Just play the center panel yellow/pink line

As a side note, I used to track number of down days and if we go to around 8-9 down days on the XAU, you could do a pretty low risk trade the next day was up. If it was not, double down. If not again, double down again. Kind of like the ultimate winning roulette strategy if you had infinite funds. /lol That said, there are better ways to play XAU then counting down days, but events outside the norm do mean revert, so it's not all that crazy. Check out my posts on FGMR for a working example of this in action.

Hi TOS experts,

I am trying to write a script that selects stocks that have 3 consecutive days of rising prices and with rising volume, once they cross SMA 20 for a specific market cap.

I have the preset market cap and SMA filters in the scanner.

How do i capture current close, previous-day close and previous-day-1 closing price and compare; and repeat the same for volume.

87k+ Posts
377 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?