Page 1 of 1

Small popup box on mouse hover

Posted: Tue Mar 15, 2022 4:05 pm
by Alex100
Hello!

I need to check the content of some variables for each candlestick of a chart.

The best solution would be a small information box that would show up when hovering the mouse pointer over a candlestick. Inside this box I'd like to write some variable names and their content (for that particular candlestick). Basically, it will only show text information, nothing else.

The box can be displayed either at an exact location on the chart (say, somewhere on the left corner), or better, it can show right above or below the candlestick that is being checked.

I spent a few hours today trying to find a way to code something like this, but without any success. I read about labels, but I couldn't find a way to have them show up (and then hide) when hovering over the candlesticks.

If someone could please help me, that would be great!

Thank you!

Alex

Re: Small popup box on mouse hover

Posted: Tue Mar 15, 2022 5:38 pm
by processingclouds
Hey,

pinescript does not have any function to show a pop up box on mouse hovering.

The closest you can come to this is have a particular input for the candle and display a table based on that selection.
So this way you can have the indicator settings open to one side and than change values and see table value change on the side.

Re: Small popup box on mouse hover

Posted: Tue Mar 15, 2022 5:47 pm
by Alex100
I understand. Thank you very much for your suggestion!

Alex

Re: Small popup box on mouse hover

Posted: Tue Mar 15, 2022 6:24 pm
by Alex100
One more question, please...

If I use the 'plot (variable)' instruction, the value of the variable will be plotted, and it will also be shown in the top-left corner of the chart, next to the name of the script.

Is there any other instruction that I could use to show data in that particular space...? It should not display or change anything else in the chart, that's really important. It should not alter the scale in any way either. Something like this would still be a good solution for what I need!

I tried the 'display.none' option for the 'plot' instruction, but this hides both the plotted line and the value shown in that corner. So, that's not good for me in this case.

Alex

Re: Small popup box on mouse hover

Posted: Tue Mar 15, 2022 7:56 pm
by processingclouds
I have to look into it, but if you are concerned with scaling issue, just use scale=scale.right in the indicator definition. This will put a different scale for your indicator.

Re: Small popup box on mouse hover

Posted: Tue Mar 15, 2022 9:12 pm
by Alex100
Beside using the 'display.none' option to hide the plotted line, I also tried changing its color to white. In this case too, the value in the corner is no longer visible.

If you manage to find a simple, straightforward solution, please do share it here.

Thank you for your time, much appreciated!

Alex

Re: Small popup box on mouse hover

Posted: Wed Mar 16, 2022 6:40 am
by processingclouds
Hey,

Ok, i get what you are trying to do. I have created the simple script to do exactly what you want. You can check it out :

Code: Select all

https://www.tradingview.com/script/wI5e2xaT-Invisible-Friend/
https://www.tradingview.com/script/wI5e ... le-Friend/

Re: Small popup box on mouse hover

Posted: Wed Mar 16, 2022 7:39 am
by Alex100
Yes, this is good, but I'm wondering if it's possible to set a left scale for your indicator, and a right scale for the other indicator of the script (which is actually the main indicator line I'm watching).

I added your code to my script, and while it did show the HL average in the top-left corner and plotted no line at all, it altered (compressed) the plotted line of the main indicator in the script (making it almost impossible to see any trend lines, etc.). The values of the two indicators are very much different, so having them both on the same scale is not a good idea.

I did try adding 'indicator(title="...", scale=scale.left)' right before your code, but all I got was an error. I already have this instruction at the beginning of my script (this time with a scale set on the right side), and I guess you cannot use two instances for this instruction (in the same script).

Is there any way to fix this scaling issue...?

BTW, it would be very nice for the Pine language to have a simple way to display a message box where you can include whatever information you need to check. I believe mostly all computer languages have this basic functionality, so it would be a nice addition to Pine too!

Alex

Re: Small popup box on mouse hover

Posted: Wed Mar 16, 2022 7:11 pm
by processingclouds
I am not sure why you got the error, if you can provide the code , i can look through it , here is scale added to the indicator definition.

Code: Select all

 
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © processingclouds

//@version=5
indicator("Invisible Friend", "High Low Average", overlay=true, scale= scale.left)

plot(math.avg(high,low), "A", color.new(color.black,100), 0)

Re: Small popup box on mouse hover

Posted: Wed Mar 16, 2022 9:37 pm
by Alex100
Here's an example...

Code: Select all

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © processingclouds

//@version=5
indicator("Invisible Friend", "High Low Average", overlay=true, scale= scale.left)

plot(math.avg(high,low), "A", color.new(color.black,100), 0)
plot(close * 10)

Because both plot instructions use the same scale and their values are very much different, the visible plotted line [plot(close * 10)] will not use the entire vertical space of the chart, as it should. It will compress itself at the top, and you will always have to rescale it manually to have it fit all the available space. That's what happens here.

Is there any way to have the first plot instruction use the left scale, and the second one use the right scale? That should fix this scaling problem since the two lines will no longer share the same scale.

Alex