Alex100
Pine Script Rookie
Pine Script Rookie
Posts: 16
Joined: March 14th, 2022

Small popup box on mouse hover

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

processingclouds
Pine Script Master
Pine Script Master
Posts: 115
Joined: January 30th, 2022

Re: Small popup box on mouse hover

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.

Alex100
Pine Script Rookie
Pine Script Rookie
Posts: 16
Joined: March 14th, 2022

Re: Small popup box on mouse hover

I understand. Thank you very much for your suggestion!

Alex

Alex100
Pine Script Rookie
Pine Script Rookie
Posts: 16
Joined: March 14th, 2022

Re: Small popup box on mouse hover

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

processingclouds
Pine Script Master
Pine Script Master
Posts: 115
Joined: January 30th, 2022

Re: Small popup box on mouse hover

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.

Alex100
Pine Script Rookie
Pine Script Rookie
Posts: 16
Joined: March 14th, 2022

Re: Small popup box on mouse hover

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

processingclouds
Pine Script Master
Pine Script Master
Posts: 115
Joined: January 30th, 2022

Re: Small popup box on mouse hover

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/

Alex100
Pine Script Rookie
Pine Script Rookie
Posts: 16
Joined: March 14th, 2022

Re: Small popup box on mouse hover

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

processingclouds
Pine Script Master
Pine Script Master
Posts: 115
Joined: January 30th, 2022

Re: Small popup box on mouse hover

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)

Alex100
Pine Script Rookie
Pine Script Rookie
Posts: 16
Joined: March 14th, 2022

Re: Small popup box on mouse hover

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

Return to “Pine Script Q&A”