Add cloud based on time

SJP07

Member
I'm looking for a code that plots a horizontal line at the highs and lows within a specific time. I'd also like for their to be a cloud between each high and low set.

Time 1: 8pm to midnight EST
Time 2: 2am - 5am EST
Time 3: 8:30 - 9:30am EST

Here's a photo for context. The lines should only be shown within the set time frame. Thanks in advance!
 
Solution
I'm looking for a code that plots a horizontal line at the highs and lows within a specific time. I'd also like for their to be a cloud between each high and low set.

Time 1: 8pm to midnight EST
Time 2: 2am - 5am EST
Time 3: 8:30 - 9:30am EST

Here's a photo for context. The lines should only be shown within the set time frame. Thanks in advance!

Although the scripts that were in the link above help, the following modifications to those will allow for a better match to your screen image
1. all 3 timeframes will be in one script
2. clouds were added. These will only appear for the timeframes input.
3. horizonal lines have an option to extend beyond the timeframes input. These can be limited to just the last...
I'm looking for a code that plots a horizontal line at the highs and lows within a specific time. I'd also like for their to be a cloud between each high and low set.

Time 1: 8pm to midnight EST
Time 2: 2am - 5am EST
Time 3: 8:30 - 9:30am EST

Here's a photo for context. The lines should only be shown within the set time frame. Thanks in advance!

take a look at this.
load it 3 times and change the times
( Might have to make 3 studies each with a different name.)
https://usethinkscript.com/threads/morning-session-range.7646/#post-73691
 

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

I'm looking for a code that plots a horizontal line at the highs and lows within a specific time. I'd also like for their to be a cloud between each high and low set.

Time 1: 8pm to midnight EST
Time 2: 2am - 5am EST
Time 3: 8:30 - 9:30am EST

Here's a photo for context. The lines should only be shown within the set time frame. Thanks in advance!

Although the scripts that were in the link above help, the following modifications to those will allow for a better match to your screen image
1. all 3 timeframes will be in one script
2. clouds were added. These will only appear for the timeframes input.
3. horizonal lines have an option to extend beyond the timeframes input. These can be limited to just the last ones. Colors can be changed at the input screen (global colors not working at this time in testing)
4. movable bubbles will appear at the right edge of the extended lines.

Screenshot-2023-03-29-163730.png
Code:
#HorizonalLines_High_Low_Multiple_Time_Ranges

script r {
    input oTime = 2300;
    input cTime = 0500;
    input extend = yes;
    input showlastonly = yes;

    def sec1 = SecondsFromTime(oTime);
    def sec2 = SecondsFromTime(cTime);
    def isTime1 = (sec1 >= 0 and sec1[1] < 0) or (sec1 < sec1[1] and sec1 >= 0);
    def isTime2 = (sec2 >= 0 and sec2[1] < 0) or (sec2 < sec2[1] and sec2 >= 0);
    def inRange = CompoundValue(1, if isTime1 then 1 else if isTime2 then 0 else inRange[1], 0);
    def bars   = 200000;

    input pricePerRowHeightMode = { AUTOMATIC, default TICKSIZE, CUSTOM};
    input customRowHeight = 1.0;
    input timePerProfile = {default BAR};
    input onExpansion = no;
    input profiles = 1000;

    def period;

    switch (timePerProfile) {
    case BAR:
        period = BarNumber() - 1;
}


    def count = CompoundValue(1, if inRange and period != period[1] then (count[1] + period - period[1]) % bars else count[1], 0);
    def cond = count < count[1] + period - period[1];
    def height;
    switch (pricePerRowHeightMode) {
    case AUTOMATIC:
        height = PricePerRow.AUTOMATIC;
    case TICKSIZE:
        height = PricePerRow.TICKSIZE;
    case CUSTOM:
        height = customRowHeight;
}

    profile vol = VolumeProfile("startNewProfile" = cond, "onExpansion" = no, "numberOfProfiles" = 1000, "pricePerRow" = height, "value area percent" = 0);
    def con = CompoundValue(1, onExpansion, no);

    def hProfile = if inRange and IsNaN(vol.GetHighest()) and con then hProfile[1] else vol.GetHighest();
    def lProfile = if inRange and IsNaN(vol.GetLowest()) and con then lProfile[1] else vol.GetLowest();
    def plotsDomain = IsNaN(close) == onExpansion;
    def ProfileHigh = if inRange and plotsDomain then hProfile else if extend then ProfileHigh[1] else Double.NaN;
    def ProfileLow  = if inRange and plotsDomain then lProfile else if extend then ProfileLow[1] else Double.NaN;

    def dataCount = CompoundValue(1, if cond != cond[1] then dataCount[1] + 1 else dataCount[1]  , 0);

    plot hrange = if !showlastonly then ProfileHigh else if showlastonly and  HighestAll(dataCount) - dataCount <= if cTime <= 0000 then 2 else 1  then ProfileHigh else Double.NaN;
    plot lrange = if !showlastonly then ProfileLow else if showlastonly and HighestAll(dataCount) - dataCount <= if cTime <= 0000 then 2 else 1  then ProfileLow else Double.NaN;
}

input showclouds = yes;
input showbubbles = yes;
input showbubble_times = yes;
input showlastonly = yes;

input otime1 = 2000;
input ctime1 = 0000;
input otime2 = 0200;
input ctime2 = 0500;
input otime3 = 0830;
input ctime3 = 0930;

#Horizontal Lines - Separate input for line_extend was necessary as request was for extended lines, whereas the clouds were not wanted to extend by the times input

input line_extend = yes;
plot r1h = r(otime1, ctime1, extend = line_extend, showlastonly = showlastonly);
plot r1l = r(otime1, ctime1, extend = line_extend, showlastonly = showlastonly).lrange;

plot r2h = r(otime2, ctime2, extend = line_extend, showlastonly = showlastonly);
plot r2l = r(otime2, ctime2, extend = line_extend, showlastonly = showlastonly).lrange;

plot r3h = r(otime3, ctime3, extend = line_extend, showlastonly = showlastonly);
plot r3l = r(otime3, ctime3, extend = line_extend, showlastonly = showlastonly).lrange;

DefineGlobalColor("H", Color.LIGHT_GREEN);
DefineGlobalColor("L", Color.LIGHT_RED);

r1h.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
r1l.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
r2h.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
r2l.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
r3h.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
r3l.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

r1h.SetDefaultColor(GlobalColor("H"));
r1l.SetDefaultColor(GlobalColor("L"));
r2h.SetDefaultColor(GlobalColor("H"));
r2l.SetDefaultColor(GlobalColor("L"));
r3h.SetDefaultColor(GlobalColor("H"));
r3l.SetDefaultColor(GlobalColor("L"));

#Clouds - Cloud plots for cloud1-3 hl are needed 

input cloud_extend = no;
plot cloud1h = r(otime1, ctime1, extend = cloud_extend, showlastonly = showlastonly);
plot cloud1l = r(otime1, ctime1, extend = cloud_extend, showlastonly = showlastonly).lrange;
plot cloud2h = r(otime2, ctime2, extend = cloud_extend, showlastonly = showlastonly);
plot cloud2l = r(otime2, ctime2, extend = cloud_extend, showlastonly = showlastonly).lrange;
plot cloud3h = r(otime3, ctime3, extend = cloud_extend, showlastonly = showlastonly);
plot cloud3l = r(otime3, ctime3, extend = cloud_extend, showlastonly = showlastonly).lrange;

AddCloud(if showclouds then cloud1h else Double.NaN, cloud1l, Color.CYAN, Color.CYAN);
AddCloud(if showclouds then cloud2h else Double.NaN, cloud2l, Color.CYAN, Color.CYAN);
AddCloud(if showclouds then cloud3h else Double.NaN, cloud3l, Color.CYAN, Color.CYAN);

input bubblemover = 5;
def b  = bubblemover;
def b1 = b + 1;
def mover = showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]);

AddChartBubble(mover, r1h[b1],
if showbubble_times then AsPrice(otime1) + " : " + AsPrice(ctime1) + "\n" + r1h else "" + AsText(r1h), r1h.TakeValueColor());
AddChartBubble(mover, r1l,
if showbubble_times then AsPrice(otime1) + " : " + AsPrice(ctime1) + "\n" + r1l else "" + AsText(r1l),  r1l.TakeValueColor(), up = no);
AddChartBubble(mover, r2h,
if showbubble_times then AsPrice(otime2) + " : " + AsPrice(ctime2) + "\n" + r2h else "" + AsText(r2h),  r2h.TakeValueColor());
AddChartBubble(mover , r2l,
if showbubble_times then AsPrice(otime2) + " : " + AsPrice(ctime2) + "\n" + r2l else "" + AsText(r2l), r2l.TakeValueColor(), up = no);
AddChartBubble(mover, r3h,
if showbubble_times then AsPrice(otime3) + " : " + AsPrice(ctime3) + "\n" + r3h else "" + AsText(r3h),  r3h.TakeValueColor());
AddChartBubble(mover, r3l,
if showbubble_times then AsPrice(otime3) + " : " + AsPrice(ctime3) + "\n" + r3l else "" + AsText(r3l), r3l.TakeValueColor(), up = no);
 
Last edited:
Solution

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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