Draw a text box at a fixed position on a chart

Questions about MultiCharts and user contributed studies.
maxmax68
Posts: 163
Joined: 20 Nov 2012
Has thanked: 55 times
Been thanked: 48 times

Draw a text box at a fixed position on a chart

Postby maxmax68 » 29 Dec 2013

Hello,
as others on this forum, I too would like to draw some text boxes on the chart in a fixed position.
I mean a text box that always remains fixed, anchored even when the chart is moved or changed on x and y axes!
I tried using the instructions provided in other posts, and I managed quite easily to anchor the y coordinate of the text box.
Unfortunately I can not find a satisfactory method to anchor the x coordinate of the text box.
In fact, with the solution that currently I adopted in my example, by changing the time on the x axis of the chart, I get the text box moves to the right or to the left, and does not remain anchored as desired.
Would you have any suggestions ?

For the future, it would be nice and maybe a lot easier if it were possible to draw the text or trendlines directly using the coordinates x and y fixed in pixels of the screen, don't you think so !!!
Thanks and regards.
Massimo

Code: Select all

Vars:
vMostLeftDateTime(0),
vMostRightDateTime(0),
vHighestDispValue(0),
vLowestDispValue(0),
vRangeDateTime(0);
//
//
RecalcLastBarAfter(0.1);
//
//
vMostLeftDateTime = GetAppInfo(aiLeftDispDateTime);
vMostRightDateTime = GetAppInfo(aiRightDispDateTime);
vHighestDispValue = GetAppInfo(aiHighestDispValue);
vLowestDispValue = GetAppInfo(aiLowestDispValue);
//
once Value1=Text_New_Dt((vMostLeftDateTime+0.05),((vHighestDispValue-vLowestDispValue)*0.5 + vLowestDispValue),"TestBox");
Text_SetLocation_DT(Value1,(vMostLeftDateTime+0.05),((vHighestDispValue-vLowestDispValue)*0.5 + vLowestDispValue));

seneca
Posts: 97
Joined: 02 Apr 2012
Has thanked: 38 times
Been thanked: 22 times

Re: Draw a text box at a fixed position on a chart

Postby seneca » 30 Dec 2013

I second this. Setting RecalcLastBarAfter to 0.1 or 0.01 in order to allocate a fixed position to textboxes is more a workaround and not a fully satisfying solution.

maxmax68
Posts: 163
Joined: 20 Nov 2012
Has thanked: 55 times
Been thanked: 48 times

Re: Draw a text box at a fixed position on a chart

Postby maxmax68 » 01 Jan 2014

Hi,
I am playing with Text_New, in order to create some buttons on the chart.
I'm stuck with an error I can't reconize and solve.
May you help me ?

Regards.
Massimo
[+] show the code

Code: Select all


//
// The problem I can't solve is this:
// Although vCounter1 and vCounter2 are correctly updated on Mouseclick on TextBoxes, as reported in Print debug,
// I'm unable to redraw on the chart the TextBoxes with the correct updated vCounters.
// It shows always 0 zero.
// Where I'm wrong ???
//
//

[ProcessMouseEvents = True];

Vars:
recalcpersist vValue1(0),
recalcpersist vValue2(0),
recalcpersist vMostLeftDateTime(0),
recalcpersist vMostRightDateTime(0),
recalcpersist vHighestDispValue(0),
recalcpersist vLowestDispValue(0),
recalcpersist vRangeDateTime(0),
recalcpersist vCounter1(0),
recalcpersist vCounter2(0);
//
//
//
RecalcLastBarAfter(0.5);
//
//
vMostLeftDateTime = GetAppInfo(aiLeftDispDateTime);
vMostRightDateTime = GetAppInfo(aiRightDispDateTime);
vHighestDispValue = GetAppInfo(aiHighestDispValue);
vLowestDispValue = GetAppInfo(aiLowestDispValue);
// Draws first time TextBox1
once vValue1=Text_New_Dt((vMostLeftDateTime+0.05),((vHighestDispValue-vLowestDispValue)*0.5 + vLowestDispValue),"TestBox: "+NumToStr(vCounter1,0));
// Formats TextBox1
text_setborder(vValue1,TRUE);
text_setColor(vValue1,blue);
text_setBGColor(vValue1,green);
text_lock(vValue1,TRUE);
// Redraws TextBox1 on recalc or tick
Text_SetLocation_DT(vValue1,(vMostLeftDateTime+0.05),((vHighestDispValue-vLowestDispValue)*0.5 + vLowestDispValue));
// Draws first time TextBox2
once vValue2=Text_New_Dt((vMostLeftDateTime+0.05),((vHighestDispValue-vLowestDispValue)*0.3 + vLowestDispValue),"TestBox: "+NumToStr(vCounter2,0));
// Formats TextBox2
text_setborder(vValue2,TRUE);
text_setColor(vValue2,blue);
text_setBGColor(vValue2,green);
text_lock(vValue2,TRUE);
// Redraws TextBox2 on recalc or tick
Text_SetLocation_DT(vValue2,(vMostLeftDateTime+0.05),((vHighestDispValue-vLowestDispValue)*0.3 + vLowestDispValue));
// Checks for MouseClick on TextBoxes and updates vCounters
if MouseClickShiftPressed and MC_Text_GetActive=vValue1 then begin
vCounter1=vCounter1+1;
Text_SetLocation_DT(vValue1,(vMostLeftDateTime+0.05),((vHighestDispValue-vLowestDispValue)*0.5 + vLowestDispValue));
end
else if MouseClickShiftPressed and MC_Text_GetActive=vValue2 then begin
vCounter2=vCounter2+1;
Text_SetLocation_DT(vValue2,(vMostLeftDateTime+0.05),((vHighestDispValue-vLowestDispValue)*0.3 + vLowestDispValue));
end;
// Prints Debug
print(MC_Text_GetActive:0:0," ",MouseClickShiftPressed," ",vCounter1:0:0," ",vCounter2:0:0);

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Draw a text box at a fixed position on a chart

Postby TJ » 01 Jan 2014

Hi,
I am playing with Text_New, in order to create some buttons on the chart.
I'm stuck with an error I can't reconize and solve.
May you help me ?

Regards.
Massimo
::
Can you describe what are you trying to achieve?
Please post a mock up drawing of your intention?

maxmax68
Posts: 163
Joined: 20 Nov 2012
Has thanked: 55 times
Been thanked: 48 times

Re: Draw a text box at a fixed position on a chart

Postby maxmax68 » 01 Jan 2014

Hi TJ,
as I wrote in my code:

Code: Select all


//
// The problem I can't solve is this:
// Although vCounter1 and vCounter2 are correctly updated on Mouseclick on TextBoxes, as reported in Print debug,
// I'm unable to redraw on the chart the TextBoxes with the correct updated vCounters.
// It shows always 0 zero.
// Where I'm wrong ???
//
//
......

maxmax68
Posts: 163
Joined: 20 Nov 2012
Has thanked: 55 times
Been thanked: 48 times

Re: Draw a text box at a fixed position on a chart

Postby maxmax68 » 04 Jan 2014

I hope this image will be useful.
Any idea or suggestion ?
Thanks

Massimo
Attachments
Text_Buttons_1.png
(62.44 KiB) Downloaded 2124 times

maxmax68
Posts: 163
Joined: 20 Nov 2012
Has thanked: 55 times
Been thanked: 48 times

Re: Draw a text box at a fixed position on a chart

Postby maxmax68 » 06 Jan 2014

Ok, solved.
Massimo
[+] show the code

Code: Select all


[ProcessMouseEvents = True];

Vars:
recalcpersist vValue1(0),
recalcpersist vValue2(0),
recalcpersist vMostLeftDateTime(0),
recalcpersist vMostRightDateTime(0),
recalcpersist vHighestDispValue(0),
recalcpersist vLowestDispValue(0),
recalcpersist vRangeDateTime(0),
recalcpersist vCounter1(0),
recalcpersist vCounter2(0);
//
//
//
//RecalcLastBarAfter(0.5);
//
//
vMostLeftDateTime = GetAppInfo(aiLeftDispDateTime);
vMostRightDateTime = GetAppInfo(aiRightDispDateTime);
vHighestDispValue = GetAppInfo(aiHighestDispValue);
vLowestDispValue = GetAppInfo(aiLowestDispValue);
// Draws first time TextBox1
once vValue1=Text_New_Dt((vMostLeftDateTime+0.05),((vHighestDispValue-vLowestDispValue)*0.5 + vLowestDispValue),"TextBox1: "+NumToStr(vCounter1,0));
// Formats TextBox1
text_setborder(vValue1,TRUE);
text_setColor(vValue1,blue);
text_setBGColor(vValue1,yellow);
text_lock(vValue1,TRUE);
// Redraws TextBox1 on recalc or tick
Text_SetLocation_DT(vValue1,(vMostLeftDateTime+0.05),((vHighestDispValue-vLowestDispValue)*0.5 + vLowestDispValue));
// Draws first time TextBox2
once vValue2=Text_New_Dt((vMostLeftDateTime+0.05),((vHighestDispValue-vLowestDispValue)*0.3 + vLowestDispValue),"TextBox2: "+NumToStr(vCounter2,0));
// Formats TextBox2
text_setborder(vValue2,TRUE);
text_setColor(vValue2,blue);
text_setBGColor(vValue2,yellow);
text_lock(vValue2,TRUE);
// Redraws TextBox2 on recalc or tick
Text_SetLocation_DT(vValue2,(vMostLeftDateTime+0.05),((vHighestDispValue-vLowestDispValue)*0.3 + vLowestDispValue));
// Checks for MouseClick on TextBoxes and updates vCounters
if MouseClickShiftPressed and MC_Text_GetActive=vValue1 then begin
vCounter1=vCounter1+1;
// Updates string of TextBox1
text_setstring(vValue1,"TextBox1: "+NumToStr(vCounter1,0));
Text_SetLocation_DT(vValue1,(vMostLeftDateTime+0.05),((vHighestDispValue-vLowestDispValue)*0.5 + vLowestDispValue));
end
else if MouseClickShiftPressed and MC_Text_GetActive=vValue2 then begin
vCounter2=vCounter2+1;
// Updates string of TextBox2
text_setstring(vValue2,"TextBox2: "+NumToStr(vCounter2,0));
Text_SetLocation_DT(vValue2,(vMostLeftDateTime+0.05),((vHighestDispValue-vLowestDispValue)*0.3 + vLowestDispValue));
end;
// Prints Debug
print(MC_Text_GetActive:0:0," ",MouseClickShiftPressed," ",vCounter1:0:0," ",vCounter2:0:0);

User avatar
Smoky
Posts: 507
Joined: 03 Dec 2010
Location: Thailand
Has thanked: 97 times
Been thanked: 115 times

Re: Draw a text box at a fixed position on a chart

Postby Smoky » 10 Apr 2016

Great code !

did you find a workaround to anchor textbox to screen ?

too easy with MouseClickBarNumber who can give you the barnumber on screen LoL.

value1 = FirstBarOnScreen(data1);
value1 = LastBarOnScreen(data1);

would be fun for automatic redraw. (with RecalcLastBarAfter(0.5); )


thank for help

arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Re: Draw a text box at a fixed position on a chart

Postby arjfca » 10 Apr 2016

Draw textbox at a fix position

Can't say if it is what your looking for
This code will put a text box at the top right corner. The data displayed is the spread and chart #

The solution is to use the GetAppInfo( aiHighestDispValue ). From it's data, you could position your text box where you want

Code: Select all

If lastbaronchart then begin
Spread = (insideask -insidebid) ;
If jpy_pair = true then spread = spread *100 else spread = spread *10000;
SpreadText ="Chart#: " + numtostr(ChartNum,0) + " Spread: " + NumtoStr(Spread ,2);
HighLocation = GetAppInfo( aiHighestDispValue ) ;
text_setstring(SpreadtextLine,Spreadtext);
text_setlocation_s(spreadTextLine,date,time_s,highLocation);
end;
2016-04-10_10h44_29.png
(94.83 KiB) Downloaded 2031 times

User avatar
Smoky
Posts: 507
Joined: 03 Dec 2010
Location: Thailand
Has thanked: 97 times
Been thanked: 115 times

Re: Draw a text box at a fixed position on a chart

Postby Smoky » 10 Apr 2016

Thanks arjfca,

But when you scroll back you chart you lose your text.

Works fine in real time because with time_s you have time of last bar on chart who is also last bar on screen ;) ....

arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Re: Draw a text box at a fixed position on a chart

Postby arjfca » 10 Apr 2016

Thanks arjfca,

But when you scroll back you chart you lose your text.

Works fine in real time because with time_s you have time of last bar on chart who is also last bar on screen ;) ....

True. You may try to look at reading the left value instead of the right.

Martin

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Draw a text box at a fixed position on a chart

Postby JoshM » 12 Apr 2016

But when you scroll back you chart you lose your text.
You can use `GetAppInfo(aiLeftDispDateTime)` (or `GetAppInfo(aiRightDispDateTime)`) to get the lime from the outmost left (right) bar on the chart as the location for the text box. Then, with `RecalcLastBarAfter()`, the script can be updated every so often so that the text box is moved to the then-current fixed chart location (taking the time and price axis into account).

It sounds a little cryptic if I try to explain it in this way, but if you try it you'll see that you can make a text box in a fixed position this way.

User avatar
Smoky
Posts: 507
Joined: 03 Dec 2010
Location: Thailand
Has thanked: 97 times
Been thanked: 115 times

Re: Draw a text box at a fixed position on a chart

Postby Smoky » 12 Apr 2016

Ok JosH,

I try this code :

Code: Select all

var: intrabarpersist TimeLastBar(0), intrabarpersist Counter(0);

counter=counter+1;

TimeLastBar=GetAppInfo(aiRightDispDateTime);
messagelog(numtostr(Counter,0)," Time ",TimeLastBar);

RecalcLastBarAfter(1);
you will see that time resolution is lower than Time_s and you can't use pixel resolution to choose X coordinate :(

Thanks ;)

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Draw a text box at a fixed position on a chart

Postby TJ » 12 Apr 2016

Ok JosH,
I try this code :

Code: Select all

var: intrabarpersist TimeLastBar(0), intrabarpersist Counter(0);
counter=counter+1;
TimeLastBar=GetAppInfo(aiRightDispDateTime);
messagelog(numtostr(Counter,0)," Time ",TimeLastBar);
RecalcLastBarAfter(1);
you will see that time resolution is lower than Time_s and you can't use pixel resolution to choose X coordinate :(
Thanks ;)
There is a bug with the white space time scale. It has been confirmed in one of the threads.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Draw a text box at a fixed position on a chart

Postby TJ » 12 Apr 2016

Timescale inconsistency
viewtopic.php?f=1&t=49024

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Draw a text box at a fixed position on a chart

Postby JoshM » 12 Apr 2016

Ok JosH,

I try this code :

Code: Select all

var: intrabarpersist TimeLastBar(0), intrabarpersist Counter(0);

counter=counter+1;

TimeLastBar=GetAppInfo(aiRightDispDateTime);
messagelog(numtostr(Counter,0)," Time ",TimeLastBar);

RecalcLastBarAfter(1);
you will see that time resolution is lower than Time_s and you can't use pixel resolution to choose X coordinate :(
Uhm, I don't understand you at all, sorry.

- I don't know get how a time resolution can be lower than `Time_s` (the bar time with seconds precision).
- I don't know what a 'pixel resolution' for the x coordinate is. If we draw a text box in PowerLanguage, we need to specify the time value but not the x pixel coordinate. (In MultiCharts .NET we can use x pixel coordinates though).
- And your code runs fine here. At least, it gives the output I was expecting to see based on the code. Can you elaborate on what is wrong or missing with this code?

If you're talking about the 'Chart Shift' option of the chart's 'Format Window' settings specified to a pixel or percentage value, then `GetAppInfo(aiRightDispDateTime)` has no influence on that. (Unless, of course, we change the 'Chart Shift' option but that makes sense).

User avatar
Smoky
Posts: 507
Joined: 03 Dec 2010
Location: Thailand
Has thanked: 97 times
Been thanked: 115 times

Re: Draw a text box at a fixed position on a chart

Postby Smoky » 12 Apr 2016

This code help you to see TimeLastBar value when you scroll back a chart, you can see a lot of bar scrolling with no value change ...

wiki :

aiRightDispDateTime .... and the fractional portion of the DateTime value specifies the fraction of the day since midnight.

only two digits for 24h :( and you will see only last digit change with many bar scrolling back ...


I ask for new EL code :

value1 = FirstBarOnScreen(data1);
value1 = LastBarOnScreen(data1);

because it's the only workaround to find barnumber on screen without use MouseClickBarNumber...

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Draw a text box at a fixed position on a chart

Postby JoshM » 25 Apr 2016

I ask for new EL code :

value1 = FirstBarOnScreen(data1);
value1 = LastBarOnScreen(data1);

because it's the only workaround to find barnumber on screen without use MouseClickBarNumber...
Another workaround would be to compare the DateTime value of the left bar on the screen (`GetAppInfo(aiLeftDispDateTime)`) with the `DateTime` value returned of the recent x bars, and when they match, retrieve that bar's number.

So we can probably do this in PowerLanguage with the keywords and features that we already have, I think.

gilko
Posts: 16
Joined: 19 Dec 2013
Has thanked: 5 times
Been thanked: 3 times

Re: Draw a text box at a fixed position on a chart

Postby gilko » 25 Apr 2016

Yes JoshM , for precise anchor we need other EL code.

please, put this indicator on a 1 minute chart,

Code: Select all

var: intrabarpersist TimeLastBar(0), intrabarpersist Counter(0);

counter=counter+1;

TimeLastBar=GetAppInfo(aiLeftDispDateTime);
messagelog(numtostr(Counter,0)," Time ",TimeLastBar);

RecalcLastBarAfter(1);
Scroll back our chart, and you will see many bars scrolling with the same value returned by GetAppInfo !

like Smoky already said before, not any resolution on date/time returned

with this workaround you can only anchor text/box on the middle of the screen with little move ...


Return to “MultiCharts”