Modify code to show High/Low lines only in present session

rlohmeyer

Active member
I am using code kindly shared by #Nube that plots Highs and Lows for 1. the previous RTH Session 2. The present RTH Session and 3. the Overnight (Globex) session. Code and image is below. The lines presently extend across the whole chart. I am wondering if it is possible to modify the code so that the High and Low lines only show in the Present Session. Thanks for any help extended.

Code:
# Globex, RTH and prior RTH High and Low
# v0.02 11.12.18 will plot prior RTH during current RTH
# Nube

# inputs
input showOnlyLastPeriod = yes;

# univerals
def na = Double.NaN;
def bn = BarNumber();
def h = high;
def l = low;

# subscript for getting prior value of a BarNumber() defined variable

script prior {
input prior = close;
def priorOf = if prior != prior[1] then prior[1] else priorOf[1];
plot priorBar = priorOf;
}

# variables

def cb = HighestAll(if !IsNaN(h) then bn else na);
def time = GetTime();
def rts = RegularTradingStart(GetYYYYMMDD());
def rte = RegularTradingEnd(GetYYYYMMDD());
def RTH = if time crosses above rts
     then bn else RTH[1];
def globex = if time crosses above rte
    then bn else globex[1];
def priorRTH = prior(RTH);
def priorGlobex = prior(globex);
def hRTH = HighestAll(RTH);
def hGX = HighestAll(globex);
def hPRTH = HighestAll(priorRTH);
def hPGX = HighestAll(priorGlobex);
def gXhigh = HighestAll(if bn >= hGX && bn < hRTH
   then h else if hRTH < hGX && bn >= hGX then h else na);
def gXlow = LowestAll(if bn >= hGX && bn < hRTH
   then l else if hRTH < hGX && bn >= hGX then l else na);
def RTHhigh = HighestAll(if bn >= hRTH && bn < hGX
   then h else if hGX < hRTH && bn >= hRTH then h else na);
def RTHlow = LowestAll(if bn >= hRTH && bn < hGX
   then l else if hGX < hRTH && bn >= hRTH then l else na);
def priorRTHhigh = HighestAll(if bn >= hPRTH
   && bn < if hGX < hRTH then hGX else hPGX then h else na);
def priorRTHlow = LowestAll(if bn >= hPRTH
   && bn < if hGX < hRTH then hGX else hPGX then l else na);

plot
GlobexHigh = gXhigh;
GlobexHigh.SetDefaultColor(Color.LIGHT_GREEN);

plot
GlobexLow = gXlow;
GlobexLow.SetDefaultColor(Color.LIGHT_RED);

plot
HighRTH = RTHhigh;
HighRTH.SetDefaultColor(Color.GREEN);

plot
LowRTH = RTHlow;
LowRTH.SetDefaultColor(Color.RED);

plot
PreviousHighRTH = priorRTHhigh;
PreviousHighRTH.SetDefaultColor(Color.DARK_GREEN);

plot
PreviousLowRTH = priorRTHlow;
PreviousLowRTH.SetDefaultColor(Color.DARK_RED);

jocXy4C.png
 
I assume you want the previous day's high and low plotted onto the current day session only? If so, try this code:

Code:
# Plot Yesterday's High and Low

input ShowTodayOnly = yes;
def Today = if GetDay() == GetLastDay() then 1 else 0;

input aggregationPeriod = AggregationPeriod.DAY;
def high = high(period = aggregationPeriod);
def low = low(period = aggregationPeriod);

# Plot yesterday's high / low
plot h1 = if ShowTodayOnly and !Today then Double.NaN else high(period = aggregationPeriod)[1];
plot l1 = if ShowTodayOnly and !Today then Double.NaN else low(period = aggregationPeriod)[1];
 

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

This is very helpful...thankyou. From various code slices I have gobbled together a swing trading/support_resistance levels indicator I will use daily. I will post it to see if anyone else wants to use it.
 
@BenTen any idea how i can add RTH Mid and 24h Mid to this study ? take difference of HighRTH and LowRTH / divide by 2 ? but then it wont be a running line which reflect the mid of the range as it develops , right ?
 
i tired this to plot mids but nothing is plotting. is it bcoz its sunday today ?

plot
midRTH = RTHhigh-RTHlow/2;
midRTH.SetDefaultColor(Color.white);

plot
midGlobex = GlobexHigh-GlobexLow/2;
midGlobex.SetDefaultColor(Color.yellow);
 
@BenTen

Hello guys, any ideas to hide the cloud, only the lines are hiding and I want the cloud to be hidden too


thank you


plot R6 = LinePlot(BarID = R6PHBarID, Value = R6PHValue, BarOrigin = R6PHBarOrigin);
R6.SetDefaultColor(Color.RED);
def r6v = if bar == HighestAll(R6PHBarOrigin) then h else r6v[1];
def crossr6 = if bar < HighestAll(R6PHBarOrigin) then 0 else if bar > HighestAll(R6PHBarOrigin) and c crosses HighestAll(r6v) then crossr6[1] + 1 else crossr6[1];
R6.SetHiding(crossr6 >= sh);
AddChartBubble(HighestAll(crossr6) < sh and bar == HighestAll(R6PHBarOrigin), PHValue, "R6", Color.RED, 1);

def hidecloudr6 = crossr6 >= sh;
plot R6_ = LinePlot(BarID = R6PHBarID, Value =R6 + Num_Dev_Up, BarOrigin = R6PHBarOrigin);
R6_.SetDefaultColor(Color.RED);
R6_.SetHiding(crossr6 >= sh);
AddCloud( if hidecloudr6 then nan else R6 , R6_ , Color.LIGHT_RED , Color.LIGHT_RED );
 
@BenTen

Hello guys, any ideas to hide the cloud, only the lines are hiding and I want the cloud to be hidden too


thank you


plot R6 = LinePlot(BarID = R6PHBarID, Value = R6PHValue, BarOrigin = R6PHBarOrigin);
R6.SetDefaultColor(Color.RED);
def r6v = if bar == HighestAll(R6PHBarOrigin) then h else r6v[1];
def crossr6 = if bar < HighestAll(R6PHBarOrigin) then 0 else if bar > HighestAll(R6PHBarOrigin) and c crosses HighestAll(r6v) then crossr6[1] + 1 else crossr6[1];
R6.SetHiding(crossr6 >= sh);
AddChartBubble(HighestAll(crossr6) < sh and bar == HighestAll(R6PHBarOrigin), PHValue, "R6", Color.RED, 1);

def hidecloudr6 = crossr6 >= sh;
plot R6_ = LinePlot(BarID = R6PHBarID, Value =R6 + Num_Dev_Up, BarOrigin = R6PHBarOrigin);
R6_.SetDefaultColor(Color.RED);
R6_.SetHiding(crossr6 >= sh);
AddCloud( if hidecloudr6 then nan else R6 , R6_ , Color.LIGHT_RED , Color.LIGHT_RED );

Remove anything with "AddCloud" in it or add "#" in front of "AddCloud"

For example:

Code:
AddCloud( if hidecloudr6 then nan else R6 , R6_ , Color.LIGHT_RED , Color.LIGHT_RED );
 
Remove anything with "AddCloud" in it or add "#" in front of "AddCloud"

For example:

Code:
AddCloud( if hidecloudr6 then nan else R6 , R6_ , Color.LIGHT_RED , Color.LIGHT_RED );
Ups , sorry, I didn't explain well, what I want is that the cloud be hidden together with the lines, in this example, the lines are hidden when (crossr6 >= sh ) happen but the cloud doesn't , so what I want is that the lines and the cloud show up and hide automatically as the lines does at the moment

Thanks again
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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