-1

I want to point out the highest volume on a candlestick with a vertical line. Now I only see this point inside the body of the candlestick (without seeing this point in the wick). I would include the wicks in this. Could someone help?

//@version=4
study("Name", overlay=true)
i = input(1, title="Volume Periods")
Name = barssince(volume == max(highest(volume, i), 0))
plot(close[Name], color=color.black, title="Name", style=plot.style_circles)

enter image description here

The length of the horizontal line should be shorter.

MNM
  • 1
  • 1

2 Answers2

0

highestbars() returns the offset to the highest value:

//@version=4
study("Name", overlay=true)
i = input(10, title="Volume Periods")
ofst = - highestbars(volume, i)
line.new(bar_index[ofst], low[ofst], bar_index[ofst], high[ofst], color = color.new(color.silver, 0), width = 3)

enter image description here

PineCoders-LucF
  • 8,288
  • 2
  • 12
  • 21
  • I meant horizontal lines instead of vertical. My fault -.-. How would that look like? I would also like to see it for each candle :) – MNM May 29 '20 at 09:47
  • Are you the same daytraderph guy asking the same question in the Pine Script room on TV? – PineCoders-LucF May 29 '20 at 22:17
  • Yes, I am :). Is it possible for you what I described to Bjorn? – MNM May 31 '20 at 14:27
  • First, don't ask the same question in multiple forums. You risk getting different volunteers helping you concurrently, as you are now. Second, your question is unclear and too open-ended, which is why people have so much problems answering. – PineCoders-LucF May 31 '20 at 16:55
  • You are right, I am sorry about that. I have added an image above of what I actually mean. It should place a horizontal line where the most volume is traded for each candlestick. – MNM May 31 '20 at 20:42
  • The only way to do that would be to use `security()` to inspect intrabars, which comes with many constraints. See [Is it possible to use security() on lower intervals than the chart’s current interval?](https://www.pinecoders.com/faq_and_code/#is-it-possible-to-use-security-on-lower-intervals-than-the-charts-current-interval). Would be a project for an advanced Pine coder. – PineCoders-LucF May 31 '20 at 21:16
0

Drawing vertical lines in PineScript is tricky and can cause scaling problems.
Some examples can be found here.

It might be better to just highlight the background when your condition occurs.

//@version=4
study("Name", overlay=true)
i = input(20, title="Volume Periods")
bgcolor(volume == highest(volume,i) ? color.yellow : na)

Which yields

Background highlighted on condition

Bjorn Mistiaen
  • 6,459
  • 3
  • 18
  • 42
  • Is it possible to draw a horizontal line for each candlestick? – MNM May 29 '20 at 09:51
  • Could you post a screen-shot of what you would like? You can draw the lines manually of what you want it to look like. It'll help us better understand what your desired output is. – Bjorn Mistiaen May 29 '20 at 09:54
  • Hi Bjorn, thank you for your reply. I have added the image above. The horizontal line should be the place where the volume is the highest. This horizontal line should also change when the timeframe is changed. – MNM May 29 '20 at 11:24
  • So if I understand this correctly, you want to draw a horizontal line at the price level where the volume was the highest during the formation of the bar? If so, that cannot be done, because you cannot get lower-timeframe information. Sounds to me like you're looking for Volume Profile. Correct? – Bjorn Mistiaen May 29 '20 at 11:38
  • Yes kind of, actually i've seen this earlier but couldn't find it. The line appears after the close of the candle. – MNM May 29 '20 at 12:54
  • It appears I was wrong about not being able to get information for lower timeframes. It can be done. We all learn something new everyday. See [Volume Profile: Intra-bar Volume](https://www.tradingview.com/script/28iP8MSD-Volume-Profile-Intra-bar-Volume/). – Bjorn Mistiaen May 29 '20 at 13:11
  • That looks interesting. But if you look at the code I shared here, you can see that the circles plotted are at the close of the candle. Is there no way to plot this circle just at the place where the most volume is traded? It should work because, I have seen it earlier :) – MNM May 29 '20 at 16:31
  • You can plot the dot at any price level, but the trick is to find the price point with the highest volume within that bar :) – Bjorn Mistiaen May 29 '20 at 17:12
  • It's fine for me :) Thank you for your help and time! – MNM May 29 '20 at 21:26