# Repainting Script Question - Initial Balance Script

#### VP7

##### New member
I wrote a script to plot the high and low of the first hour of trading in RTH, aka the Initial Balance. The script currently draws a line at the high and low of each candle leading to the end of the first hour, similar to a stair-stepping eventually leading to the final result of the high and low (see image). I'd like to redraw the line when a new high/low is established in that first hour.

Here's a snippit of the code that plots the lines.
Ruby:
``````def isIB = GetTime() >= RegularTradingStart(GetYYYYMMDD()) and GetTime() < RegularTradingStart(GetYYYYMMDD()) + 3600000;
#3600000 milliseconds = 1 hour.

#Get the High of the first 1 Hour of RTH session
def ibHigh = if isIB then high else if isIB and high > ibHigh[1] then high else ibHigh[1];

plot pltIbHigh = if isRTH and isIntraday then ibHigh else Double.NaN;``````

Is there a way to adjust the code to get the plots to resemble the second image? This line will be used on intraday charts and would be expected to change as prices change.

Thank you

#### Attachments

• initialbalance.png
8.4 KB · Views: 136
• initialbalance2.png
5.2 KB · Views: 138
Solution
I wrote a script to plot the high and low of the first hour of trading in RTH, aka the Initial Balance. The script currently draws a line at the high and low of each candle leading to the end of the first hour, similar to a stair-stepping eventually leading to the final result of the high and low (see image). I'd like to redraw the line when a new high/low is established in that first hour.

Here's a snippit of the code that plots the lines.
Ruby:
``````def isIB = GetTime() >= RegularTradingStart(GetYYYYMMDD()) and GetTime() < RegularTradingStart(GetYYYYMMDD()) + 3600000;
#3600000 milliseconds = 1 hour.

#Get the High of the first 1 Hour of RTH session
def ibHigh = if isIB then high else if isIB and high > ibHigh[1] then high else...``````
I wrote a script to plot the high and low of the first hour of trading in RTH, aka the Initial Balance. The script currently draws a line at the high and low of each candle leading to the end of the first hour, similar to a stair-stepping eventually leading to the final result of the high and low (see image). I'd like to redraw the line when a new high/low is established in that first hour.

Here's a snippit of the code that plots the lines.
Ruby:
``````def isIB = GetTime() >= RegularTradingStart(GetYYYYMMDD()) and GetTime() < RegularTradingStart(GetYYYYMMDD()) + 3600000;
#3600000 milliseconds = 1 hour.

#Get the High of the first 1 Hour of RTH session
def ibHigh = if isIB then high else if isIB and high > ibHigh[1] then high else ibHigh[1];

plot pltIbHigh = if isRTH and isIntraday then ibHigh else Double.NaN;``````

Is there a way to adjust the code to get the plots to resemble the second image? This line will be used on intraday charts and would be expected to change as prices change.

Thank you

Thank you. That helped a bit. However, unless I misread the code, the script relies on the number of bars to find the high/low which implies the script will work if your charts stay fairly static. I'd like to make it a bit more flexible in that it will work on all intraday timeframes regardless of aggregation.

I was thinking if it was possible to lookahead at future bars. For example instead of var[1] to look at the previous bar, can you do var[-1] to look at a future bar. Maybe I could check future bars to see if the IB has been breached. I'll try it out.

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