High/Low based on number of candles

Bill Belt

New member
Is there any Thinkscript code that will draw a line based on user define number of candles? I can find based on a time period but I'm looking for high and low based on candles.
 
Is there any Thinkscript code that will draw a line based on user define number of candles? I can find based on a time period but I'm looking for high and low based on candles.

I used the volumeprofile study, set to bar, to have an input bars and to plot the profilehigh and profilelow. No need to reinvent the wheel if it works for your request. The chart below is set to 39 bars with the extended hours turned off. Also, added are value bubbles and vertical lines.

Screenshot-2021-08-20-192725.jpg
Ruby:
input bars = 5;

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 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 IsNaN(vol.GetHighest()) and con then hProfile[1] else vol.GetHighest();
def lProfile = if IsNaN(vol.GetLowest()) and con then lProfile[1] else vol.GetLowest();
def plotsDomain = IsNaN(close) == onExpansion;
def ProfileHigh = if plotsDomain then hProfile else Double.NaN;
def ProfileLow = if plotsDomain then lProfile else Double.NaN;

plot hrange = ProfileHigh;
plot lrange = ProfileLow;
hrange.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
lrange.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

input showbubbles = yes;
AddChartBubble(showbubbles and hrange != hrange[-1], hrange, AsText(hrange), Color.LIGHT_GREEN);
AddChartBubble(showbubbles and lrange != lrange[-1], lrange, AsText(lrange), Color.LIGHT_RED, up = no);

input showverticalline = yes;
AddVerticalLine(showverticalline and hrange != hrange[1], "", Color.BLUE, stroke = Curve.FIRM);
 

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

I used the volumeprofile study, set to bar, to have an input bars and to plot the profilehigh and profilelow. No need to reinvent the wheel if it works for your request. The chart below is set to 39 bars with the extended hours turned off. Also, added are value bubbles and vertical lines.
Thank you. I'll give it a try
 
I'm getting the bubbles but not the horizontal lines. Any idea what I don't have set right? The Style is dimmed out so I can't choose the line if that means anything. I tried to post a screen shot but it would only accept a URL so I can't show you my settings. Appreciate the help.
 
I'm getting the bubbles but not the horizontal lines. Any idea what I don't have set right? The Style is dimmed out so I can't choose the line if that means anything. I tried to post a screen shot but it would only accept a URL so I can't show you my settings. Appreciate the help.
The plots of the lines are hrange and lrange. I have added some color and lineweight code in case you are having issues. Also, I centered the bubbles on the middle of the lines and added a bubblemover which you can use to move the bubbles left/right;

Here is a share link for the chart. https://tos.mx/EUPNQRY

Screenshot-2021-08-15-064611.jpg
Ruby:
input bars = 5;

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 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 IsNaN(vol.GetHighest()) and con then hProfile[1] else vol.GetHighest();
def lProfile = if IsNaN(vol.GetLowest()) and con then lProfile[1] else vol.GetLowest();
def plotsDomain = IsNaN(close) == onExpansion;
def ProfileHigh = if plotsDomain then hProfile else Double.NaN;
def ProfileLow = if plotsDomain then lProfile else Double.NaN;

plot hrange = ProfileHigh;
plot lrange = ProfileLow;
hrange.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
lrange.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hrange.setdefaultColor(color.green);
lrange.setdefaultColor(color.red);
hrange.setlineWeight(2);
lrange.setlineweight(2);

input bubblemover = 0;
def bct = if hrange != hrange[1] then 1 else if bct[1] <= bars then bct[1] + 1 else bct[1];
input showbubbles = yes;
AddChartBubble(showbubbles and bct == Floor(bars / 2) + bubblemover, hrange, AsText(hrange), Color.LIGHT_GREEN);
AddChartBubble(showbubbles and bct == Floor(bars / 2) + bubblemover, lrange, AsText(lrange), Color.LIGHT_RED, up = no);

input showverticalline = yes;
AddVerticalLine(showverticalline and hrange != hrange[1], "", Color.BLUE, stroke = Curve.FIRM);
 
The plots of the lines are hrange and lrange. I have added some color and lineweight code in case you are having issues. Also, I centered the bubbles on the middle of the lines and added a bubblemover which you can use to move the bubbles left/right;

Here is a share link for the chart. https://tos.mx/EUPNQRY
Thanks. Looks like I'll need to call support on Monday. Bubble show up but no horizontal lines even with the new code. I updated my Java as well as downloading a new TOS but the same results. Not sure why mine is different and it won't put the horizontal lines on the chart.
 
Thanks. Looks like I'll need to call support on Monday. Bubble show up but no horizontal lines even with the new code. I updated my Java as well as downloading a new TOS but the same results. Not sure why mine is different and it won't put the horizontal lines on the chart.
Did you try loading the share link that I included. That should give you another attempt with the settings from my grid, in case it is something with the settings. Also, open the script settings and make sure that hrange and lrange show plots are checked.
 

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
483 Online
Create Post

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