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.
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.
Thank you. I'll give it a tryI 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.
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;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.
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);
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.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
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.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.
Start a new thread and receive assistance from our community.
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.
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.