How do I add text to a location on screen?

Have a QScript to share, or need help with programming? Post your comment here.
Post Reply
sbank
Posts: 73
Joined: Tue Jul 21, 2015 9:35 pm
Contact:

How do I add text to a location on screen?

Post by sbank » Thu Feb 21, 2019 5:13 pm

Hi All,

How do I add text to a location on the screen (instead of bar based). I see there is a text() function, but the arguments are thus:

Code: Select all

text(bar, price, string, color, style, size)
I don't see any x or y type reference that I could use. I want to add some text to this part of the screen that will change with each bar:

2019-02-21_12-07-45.png
2019-02-21_12-07-45.png (20.67 KiB) Viewed 289 times

Does anyone have examples on how to do this?

User avatar
earik
Site Admin
Posts: 323
Joined: Mon Dec 01, 2014 12:41 pm
Contact:

Re: How do I add text to a location on screen?

Post by earik » Thu Feb 21, 2019 6:12 pm

There are canvas functions that let you draw right on the bitmap that W59 uses for the chart. Go to help - qscript help, and look for the "canvas" section, and you'll see all of them there. They work with x/y pixel locations rather than bar/price. Canvas_text( ) is the one you want! :)

Earik

sbank
Posts: 73
Joined: Tue Jul 21, 2015 9:35 pm
Contact:

Re: How do I add text to a location on screen?

Post by sbank » Fri Feb 22, 2019 12:51 am

Thanks Earik. I must have missed those. I was just about to start creating helper functions to use the count of bars on the screen, then index up with a -1, and who know what else. :)

canvas_text() looks easy enough to implement, but does it update every bar? (I am going to try now....)

sbank
Posts: 73
Joined: Tue Jul 21, 2015 9:35 pm
Contact:

Re: How do I add text to a location on screen?

Post by sbank » Fri Feb 22, 2019 1:06 am

Okay, I tried a very simple one line script of:

Code: Select all

canvas_text(10,10,close);
It draws, but on each bar it keeps writing text to the same location without clearing the old value (it overlays the text on top of the other text). So I then wrapped it for the updating bar, but that makes new subsequent bars also overlay the text.

Code: Select all

if (barnum >= updating_bar - 1) {
  canvas_text(10,10,close);
}        
Am I missing some sort of clear? Maybe change the font color to the background color then change it back? (trying that now...)

abacaba
Posts: 80
Joined: Sat Aug 15, 2015 5:02 pm
Contact:

Re: How do I add text to a location on screen?

Post by abacaba » Sat Feb 23, 2019 4:45 pm

sbank -- hope this helps.

Todd

# Barcounter
# Use a "hotspot" to locate a swing H or L bar.
# Displays the "count" from that bar at setup time
# AND displays current bar counts from that bar forward.
# color, text size, and space from chart H or chart L may be changed
# adjuster sets variable to alter the bar count by a fixed amount

input adjuster(0),spacer(.50),mycolor(purple),textsize(12),textHL("H"), dotwidth(4);

If (barnum==barsback)
{
textref1=0; TDC=0;
bar1 = hotspot_to_bar(1);
pricepoint=hotspot_to_price(1);
ref=plot_dot(bar1-1,pricepoint,mycolor,dotwidth);
}

If (barnum>=updating_bar-3)
{
barcnt=updating_bar-bar1+1+adjuster;
showtext=to_string(barcnt);
If (textHL=="H")
{ If (textref1!=0)text_delete(textref1);
If (TDC==0)
{
textref1=text(bar1,pricepoint,barcnt,mycolor,tx_left,textsize);
}
else
{
textref1=text(updating_bar+5,chart_high-spacer,showtext,mycolor,tx_left,textsize);
}
}

If (textHL=="L")
{
If (textref1!=0)text_delete(textref1);
If (TDC==0)
{
textref1=text(bar1,pricepoint,barcnt,mycolor,tx_left,textsize);
}
else
{
textref1=text(updating_bar+1,chart_low+spacer,showtext,mycolor,tx_left,textsize);
}

}
}

If (barnum>bar1)
{
IF ( (H==H[1])and (L==L[1])and (O==O[1])and (C==C[1]) ) bar1=bar1+1; #holiday filter
If ( (barnum-bar1+1)/3 == int((barnum-bar1+1)/3) )
{ref=plot_dot(barnum,pricepoint,mycolor,dotwidth);
}
}
TDC=TDC+1;

abacaba
Posts: 80
Joined: Sat Aug 15, 2015 5:02 pm
Contact:

Re: How do I add text to a location on screen?

Post by abacaba » Tue Feb 26, 2019 3:12 pm

Addendum to above posted script:

This is not my script. It is from the very early days of W59 (then W59RT) circa 2004, more or less when I began using the software. I believe it is one of Ken Churchill's. It works well, but keep in mind :

1. Input _texthl_ is case sensitive. This will set text above or below price.
2. Input _spacer_ needs to be adjusted to bring the text into the chart field. For instance, a setting of 20 does nicely on my 24 hr 4 min ES chart currently scaled to .125 x 2/bar. This setting can be adjusted according to price volatility.

Have fun!

Todd

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest