mark the present day, every year back

Godwin

New member
I don't think this would be hard & should be a standard script in TOS. But is there a study that looks back & marks the present day, every year back?
 
Solution
I don't think this would be hard & should be a standard script in TOS. But is there a study that looks back & marks the present day, every year back?

What price points would you be looking for on the present day of every year and on what timeframe...??? The devil is in the details...
I don't think this would be hard & should be a standard script in TOS. But is there a study that looks back & marks the present day, every year back?

What price points would you be looking for on the present day of every year and on what timeframe...??? The devil is in the details...
 
Solution
I don't think this would be hard & should be a standard script in TOS. But is there a study that looks back & marks the present day, every year back?

this will check the last bar and look for similar dates in the past
it auto scales depending on the chart time

if chart time is,
.. less than day , then look for the same day of week
.. less than week , then look for the same day of year
.. less than month , then look for the same week of year
.. month , then look for the same month of year

it draws vertical lines for the same bar as last bar
it draws vertical lines when a new year happens


Code:
# day_same_line

def na = Double.NaN;
def bn = BarNumber();
def lastbn = HighestAll(If(IsNaN(close), 0, bn));
def lastbar = if (bn == lastbn) then 1 else 0;

def dowx = GetDayofWeek(GetYYYYMMDD());
def dyx = getday();
def wkx = getweek();
def mox = getmonth();
def yrx = getyear();

def dow;
def dy;
def wk;
def mo;
def t;
if GetAggregationPeriod() < AggregationPeriod.DAY then {
# draw vert lines for same day of week
  dow = HighestAll(if lastbar then dowx else 0);
  dy = 0;
  wk = 0;
  mo = 0;
  t = 1;
} else if GetAggregationPeriod() < AggregationPeriod.week then {
# draw vert line for same day
  dow = 0;
  dy = HighestAll(if lastbar then dyx else 0);
  wk = 0;
  mo = 0;
  t = 2;
} else if GetAggregationPeriod() < AggregationPeriod.month then {
# draw vert line for same week
  dow = 0;
  dy = 0;
  wk = HighestAll(if lastbar then wkx else 0);
  mo = 0;
  t = 3;
} else {
# draw vert line for same month
  dow = 0;
  dy = 0;
  wk = 0;
  mo = HighestAll(if lastbar then mox else 0);
  t = 4;
}


def valid = !isnan(close);
def dowz = (valid and dow == dowx);
addverticalline(dowz, "-", color.cyan);

def dyz = (valid and dy == dyx);
addverticalline(dyz, "-", color.cyan);

def wkz = (valid and wk == wkx);
addverticalline(wkz, "-", color.cyan);

def moz = (valid and mo == mox);
addverticalline(moz, "-", color.cyan);

addlabel(1, 
    (if t == 1 then "day of week " + dow
else if t == 2 then "day of week " + dy
else if t == 3 then "week of year " + wk
else if t == 4 then "month of year " + mo
else if t == 5 then "-"
else "-")
, color.cyan);

addverticalline(valid and yrx != yrx[1], "           new year", color.gray);
#
 

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
338 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