Date Range Cloud Drawing issue

sserbest

New member
Hi everyone,

I'm having an issue making this script dynamic. If I add year month date as input works perfectly but I would like to define only month and day.
I tried multiple ways including Concat but if you look at the "date1" or "date2", they are not getting concatenated, it's adding up (see labels).
I tried to change the year-month date to month and date but then AddCloud it's not working. I'll appreciate any help. Thank you.


Code:
input date1d = 0215;
def date1 = GetYear() + date1d;

input date2d = 0331;
def date2 = GetYear() + date2d;

def ymd = GetYYYYMMDD();
input showverticals = yes;
AddVerticalLine(showverticals and ymd == date1, "");
AddVerticalLine(showverticals and ymd == date2, "");
DefineGlobalColor("Dates", Color.LIGHT_GRAY);
AddCloud(if Between(ymd, date1, date2) then Double.POSITIVE_INFINITY else Double.NaN, Double.NEGATIVE_INFINITY, GlobalColor("Dates"), GlobalColor("Dates"));


//Printing them to see it matches
AddLabel(yes, "ymd: " + asPrice(ymd) , Color.WHITE);
AddLabel(yes, "date1: " + asPrice(date1) , Color.WHITE);
AddLabel(yes, "date2: " + asPrice(date2), Color.WHITE);
AddLabel(yes, "GetYear(): " + asPrice(GetYear()) , Color.WHITE);


Thinks tried:
Code:
#they returns expected double
def date1 = asPrice(GetYear() + date1d);

def date1 = Concat(GetYear(), date1d);
 
Hi everyone,

I'm having an issue making this script dynamic. If I add year month date as input works perfectly but I would like to define only month and day.
I tried multiple ways including Concat but if you look at the "date1" or "date2", they are not getting concatenated, it's adding up (see labels).
I tried to change the year-month date to month and date but then AddCloud it's not working. I'll appreciate any help. Thank you.


Code:
input date1d = 0215;
def date1 = GetYear() + date1d;

input date2d = 0331;
def date2 = GetYear() + date2d;

def ymd = GetYYYYMMDD();
input showverticals = yes;
AddVerticalLine(showverticals and ymd == date1, "");
AddVerticalLine(showverticals and ymd == date2, "");
DefineGlobalColor("Dates", Color.LIGHT_GRAY);
AddCloud(if Between(ymd, date1, date2) then Double.POSITIVE_INFINITY else Double.NaN, Double.NEGATIVE_INFINITY, GlobalColor("Dates"), GlobalColor("Dates"));


//Printing them to see it matches
AddLabel(yes, "ymd: " + asPrice(ymd) , Color.WHITE);
AddLabel(yes, "date1: " + asPrice(date1) , Color.WHITE);
AddLabel(yes, "date2: " + asPrice(date2), Color.WHITE);
AddLabel(yes, "GetYear(): " + asPrice(GetYear()) , Color.WHITE);


Thinks tried:
Code:
#they returns expected double
def date1 = asPrice(GetYear() + date1d);

def date1 = Concat(GetYear(), date1d);

I tried just to use the month and day, but too many issues. So this allows for the input of dates in the current year and those dates are then used to create verticallines and clouds for additional years in the past. As dates may not appear from one year to another, the code hopefully finds the closest dates in the prior years. The prior years were derived by subtracting 10000 from the dates input.

Ruby:
input date1 = 20220215;
input date2 = 20220531;
input showverticals = yes;
input showclouds    = yes;

AddVerticalLine(showverticals and GetYYYYMMDD()[1] <= (date1) and GetYYYYMMDD() >= (date1), " ", Color.WHITE, stroke = Curve.FIRM);
AddVerticalLine(showverticals and GetYYYYMMDD()[1] <= (date1 - 10000 * 1) and GetYYYYMMDD() >= (date1 - 10000 * 1), " ", Color.WHITE, stroke = Curve.FIRM);
AddVerticalLine(showverticals and GetYYYYMMDD()[1] <= (date1 - 10000 * 2) and GetYYYYMMDD() >= (date1 - 10000 * 2), " ", Color.WHITE, stroke = Curve.FIRM);
AddVerticalLine(showverticals and GetYYYYMMDD()[1] <= (date1 - 10000 * 3) and GetYYYYMMDD() >= (date1 - 10000 * 3), " ", Color.WHITE, stroke = Curve.FIRM);
AddVerticalLine(showverticals and GetYYYYMMDD()[1] <= (date1 - 10000 * 4) and GetYYYYMMDD() >= (date1 - 10000 * 4), " ", Color.WHITE, stroke = Curve.FIRM);
AddVerticalLine(showverticals and GetYYYYMMDD()[1] <= (date1 - 10000 * 5) and GetYYYYMMDD() >= (date1 - 10000 * 5), " ", Color.WHITE, stroke = Curve.FIRM);

AddVerticalLine(showverticals and GetYYYYMMDD()[1] <= (date2) and GetYYYYMMDD() >= (date2), " ", Color.WHITE, stroke = Curve.FIRM);
AddVerticalLine(showverticals and GetYYYYMMDD()[1] <= (date2 - 10000 * 1) and GetYYYYMMDD() >= (date2 - 10000 * 1), " ", Color.WHITE, stroke = Curve.FIRM);
AddVerticalLine(showverticals and GetYYYYMMDD()[1] <= (date2 - 10000 * 2) and GetYYYYMMDD() >= (date2 - 10000 * 2), " ", Color.WHITE, stroke = Curve.FIRM);
AddVerticalLine(showverticals and GetYYYYMMDD()[1] <= (date2 - 10000 * 3) and GetYYYYMMDD() >= (date2 - 10000 * 3), " ", Color.WHITE, stroke = Curve.FIRM);
AddVerticalLine(showverticals and GetYYYYMMDD()[1] <= (date2 - 10000 * 4) and GetYYYYMMDD() >= (date2 - 10000 * 4), " ", Color.WHITE, stroke = Curve.FIRM);
AddVerticalLine(showverticals and GetYYYYMMDD()[1] <= (date2 - 10000 * 5) and GetYYYYMMDD() >= (date2 - 10000 * 5), " ", Color.WHITE, stroke = Curve.FIRM);

DefineGlobalColor("Cloud", Color.VIOLET);
def x = if GetYYYYMMDD()[1] <= (date1) and GetYYYYMMDD() >= (date1)
        then 1
        else if x[1] == 1 and GetYYYYMMDD() <= date2
        then 1
        else 0
         ;
plot xx = x;

AddCloud(if showclouds and xx then Double.POSITIVE_INFINITY else Double.NaN, Double.NEGATIVE_INFINITY, GlobalColor("Cloud"));

def x1 = if GetYYYYMMDD()[1] <= (date1 - 10000) and GetYYYYMMDD() >= (date1 - 10000)
        then 1
        else if x1[1] == 1 and GetYYYYMMDD() <= date2 - 10000
        then 1
        else 0
        ;
plot xx1 = x1;

AddCloud(if showclouds and xx1 then Double.POSITIVE_INFINITY else Double.NaN, Double.NEGATIVE_INFINITY, GlobalColor("Cloud"));

def x2 = if GetYYYYMMDD()[1] <= (date1 - 10000 * 2) and GetYYYYMMDD() >= (date1 - 10000 * 2)
        then 1
        else if x2[1] == 1 and GetYYYYMMDD() <= date2 - 10000 * 2
        then 1
        else 0
        ;
plot xx2 = x2;

AddCloud(if showclouds and xx2 then Double.POSITIVE_INFINITY else Double.NaN, Double.NEGATIVE_INFINITY, GlobalColor("Cloud"));

def x3 = if GetYYYYMMDD()[1] <= (date1 - 10000 * 3) and GetYYYYMMDD() >= (date1 - 10000 * 3)
        then 1
        else if x3[1] == 1 and GetYYYYMMDD() <= date2 - 10000 * 3
        then 1
        else 0
        ;
plot xx3 = x3;

AddCloud(if showclouds and xx3 then Double.POSITIVE_INFINITY else Double.NaN, Double.NEGATIVE_INFINITY, GlobalColor("Cloud"));

def x4 = if GetYYYYMMDD()[1] <= (date1 - 10000 * 4) and GetYYYYMMDD() >= (date1 - 10000 * 4)
        then 1
        else if x4[1] == 1 and GetYYYYMMDD() <= date2 - 10000 * 4
        then 1
        else 0
        ;
plot xx4 = x4;

AddCloud(if showclouds and xx4 then Double.POSITIVE_INFINITY else Double.NaN, Double.NEGATIVE_INFINITY, GlobalColor("Cloud"));

def x5 = if GetYYYYMMDD()[1] <= (date1) + 10000 * 5 and GetYYYYMMDD() >= (date1) + 10000 * 5
        then 1
        else if x5[1] == 1 and GetYYYYMMDD() <= date2 + 10000 * 5
        then 1
        else 0
         ;
plot xx5 = x5;

AddCloud(if showclouds and xx5 then Double.POSITIVE_INFINITY else Double.NaN, Double.NEGATIVE_INFINITY, GlobalColor("Cloud"));
Screenshot-2022-10-17-082903.png
 
Hi everyone,

I'm having an issue making this script dynamic. If I add year month date as input works perfectly but I would like to define only month and day.
I tried multiple ways including Concat but if you look at the "date1" or "date2", they are not getting concatenated, it's adding up (see labels).
I tried to change the year-month date to month and date but then AddCloud it's not working. I'll appreciate any help. Thank you.


Code:
input date1d = 0215;
def date1 = GetYear() + date1d;

input date2d = 0331;
def date2 = GetYear() + date2d;

def ymd = GetYYYYMMDD();
input showverticals = yes;
AddVerticalLine(showverticals and ymd == date1, "");
AddVerticalLine(showverticals and ymd == date2, "");
DefineGlobalColor("Dates", Color.LIGHT_GRAY);
AddCloud(if Between(ymd, date1, date2) then Double.POSITIVE_INFINITY else Double.NaN, Double.NEGATIVE_INFINITY, GlobalColor("Dates"), GlobalColor("Dates"));


//Printing them to see it matches
AddLabel(yes, "ymd: " + asPrice(ymd) , Color.WHITE);
AddLabel(yes, "date1: " + asPrice(date1) , Color.WHITE);
AddLabel(yes, "date2: " + asPrice(date2), Color.WHITE);
AddLabel(yes, "GetYear(): " + asPrice(GetYear()) , Color.WHITE);


Thinks tried:
Code:
#they returns expected double
def date1 = asPrice(GetYear() + date1d);

def date1 = Concat(GetYear(), date1d);

this seems to work, even when the date is on a weekend

need to think of YYYYMMDD as a big number.
Y,YYYM,MDD
the year digits need to be shifted 4 places before adding to month-day number

Ruby:
# date_rng_yearly_00

# https://usethinkscript.com/threads/date-range-cloud-drawing-issue.13043/
# Date Range Cloud Drawing issue

#input date1d = 0215;
#def date1 = GetYear() + date1d;
#def date1 = (GetYear() * 10000) + date1d;
input start_month = 3;
input start_day = 12;
def start = (GetYear() * 10000) + (start_month * 100)+ start_day;


#input date2d = 0331;
#def date2 = GetYear() + date2d;
#def date2 = (GetYear() * 10000) + date2d;

input stop_month = 5;
input stop_day = 4;
def stop = (GetYear() * 10000) + (stop_month * 100)+ stop_day;

def date1 = start;
def date2 = stop;

def ymd = GetYYYYMMDD();
input showverticals = yes;
AddVerticalLine(showverticals and ymd == date1, "");
AddVerticalLine(showverticals and ymd == date2, "");
DefineGlobalColor("Dates", Color.LIGHT_GRAY);
AddCloud(if Between(ymd, date1, date2) then Double.POSITIVE_INFINITY else Double.NaN, Double.NEGATIVE_INFINITY, GlobalColor("Dates"), GlobalColor("Dates"));


# Printing them to see it matches
#AddLabel(yes, "ymd: " + asPrice(ymd) , Color.WHITE);
#AddLabel(yes, "date1: " + asPrice(date1) , Color.WHITE);
#AddLabel(yes, "date2: " + asPrice(date2), Color.WHITE);
#AddLabel(yes, "GetYear(): " + asPrice(GetYear()) , Color.WHITE);

addlabel(1, " ", color.black);
#addlabel(1, "Start date: " + start_month + "/" + start_day + "/" + asprice(GetYear()), color.white);
addlabel(1, "Start date: " + start_month + "/" + start_day , color.white);
addlabel(1, " ", color.black);
addlabel(1, "Stop date: " + stop_month + "/" + stop_day , color.white);
#

9PXX9JF.jpg
 
I tried just to use the month and day, but too many issues. So this allows for the input of dates in the current year and those dates are then used to create verticallines and clouds for additional years in the past. As dates may not appear from one year to another, the code hopefully finds the closest dates in the prior years. The prior years were derived by subtracting 10000 from the dates input.
Thank you SleepyZ, this is very nice. I think halcyonguy's solution it's a more simple way, I think I will stick with his. Thank you so much for your time and effort.
 
this seems to work, even when the date is on a weekend

need to think of YYYYMMDD as a big number.
Y,YYYM,MDD
the year digits need to be shifted 4 places before adding to month-day number

Ruby:
# date_rng_yearly_00

# https://usethinkscript.com/threads/date-range-cloud-drawing-issue.13043/
# Date Range Cloud Drawing issue

#input date1d = 0215;
#def date1 = GetYear() + date1d;
#def date1 = (GetYear() * 10000) + date1d;
input start_month = 3;
input start_day = 12;
def start = (GetYear() * 10000) + (start_month * 100)+ start_day;


#input date2d = 0331;
#def date2 = GetYear() + date2d;
#def date2 = (GetYear() * 10000) + date2d;

input stop_month = 5;
input stop_day = 4;
def stop = (GetYear() * 10000) + (stop_month * 100)+ stop_day;

def date1 = start;
def date2 = stop;

def ymd = GetYYYYMMDD();
input showverticals = yes;
AddVerticalLine(showverticals and ymd == date1, "");
AddVerticalLine(showverticals and ymd == date2, "");
DefineGlobalColor("Dates", Color.LIGHT_GRAY);
AddCloud(if Between(ymd, date1, date2) then Double.POSITIVE_INFINITY else Double.NaN, Double.NEGATIVE_INFINITY, GlobalColor("Dates"), GlobalColor("Dates"));


# Printing them to see it matches
#AddLabel(yes, "ymd: " + asPrice(ymd) , Color.WHITE);
#AddLabel(yes, "date1: " + asPrice(date1) , Color.WHITE);
#AddLabel(yes, "date2: " + asPrice(date2), Color.WHITE);
#AddLabel(yes, "GetYear(): " + asPrice(GetYear()) , Color.WHITE);

addlabel(1, " ", color.black);
#addlabel(1, "Start date: " + start_month + "/" + start_day + "/" + asprice(GetYear()), color.white);
addlabel(1, "Start date: " + start_month + "/" + start_day , color.white);
addlabel(1, " ", color.black);
addlabel(1, "Stop date: " + stop_month + "/" + stop_day , color.white);
#


Thank you so much, @halcyonguy; this is very clean; I love it. One thing @SleepyZ mentioned it's important, and I would like to implement it is rolling over to the following year. I was thinking of adding another variable so it can roll over the year and end some managing date changes, but the cloud is not working as expected. Am I missing something?

Code:
# date_rng_yearly_00

# https://usethinkscript.com/threads/date-range-cloud-drawing-issue.13043/
# Date Range Cloud Drawing issue


input rollover = 10000;
input start_month = 11;
input start_day = 24;
def start = (GetYear() * 10000) + (start_month * 100)+ start_day;


input stop_month = 1;
input stop_day = 20;
def stop = (GetYear() * 10000 + rollover) + (stop_month * 100)+ stop_day;

def date1 = start;
def date2 = stop;

def ymd = GetYYYYMMDD();
input showverticals = yes;
AddVerticalLine(showverticals and ymd == date1, "");
AddVerticalLine(showverticals and ymd == date2, "");
DefineGlobalColor("Dates", Color.LIGHT_GRAY);
AddCloud(if Between(ymd, date1, date2) then Double.POSITIVE_INFINITY else Double.NaN, Double.NEGATIVE_INFINITY, GlobalColor("Dates"), GlobalColor("Dates"));


# Printing them to see it matches
addlabel(1, " ", color.black);
addlabel(1, "Start date: " + start_month + "/" + start_day , color.white);
addlabel(1, " ", color.black);
addlabel(1, "Stop date: " + (GetYear() * 10000 + rollover) + "/" + stop_month + "/" + stop_day , color.white);
 

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