• Get $40 off VIP by signing up for a free account! Sign Up

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
    initialbalance.png
    8.4 KB · Views: 136
  • initialbalance2.png
    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

This should help https://usethinkscript.com/threads/initial-balance-indicator-for-thinkorswim.6617/post-131448
 
Solution

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

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.

I appreciate your help.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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