Keeping text objects fixed on the right edge of the chart  [SOLVED]

Questions about MultiCharts and user contributed studies.
PD Quig
Posts: 191
Joined: 27 Apr 2010
Location: San Jose
Has thanked: 67 times
Been thanked: 10 times

Keeping text objects fixed on the right edge of the chart

Postby PD Quig » 20 Mar 2017

I've got a number of studies that plot horizontal trend lines that extend to the right edge of the chart (swing highs, swing lows, gaps, etc.). I like to label the price value of the trend lines flush right against the right edge of the chart. The code I've been using works okay as long as I don't scroll around. When the study is turned on, the text plots pretty close to the right edge (not as close as the MultiCharts horizontal line does, but good enough for me).

The problem comes in when you scroll left and right. When you use the background dragging tool to move the whole chart to the left, the label text will remain on the right edge until you get to about a 70% chart shift. At that point the label text starts dragging along with the background. Worse, when you scroll back to the right, the text disappears into the right margin and is invisible.

I'm using aiRightDispDateTime to get the date and time values of the right edge. I can see from output that the correct values of date and time are getting picked up on the fly as I scroll around. But for some reason that I can't figure, the Text_SetLocation is not moving the text to the date and time. I've spent about two hours experimenting to no avail. If anybody has any clues I'd be most appreciative.

Thanks in advance!

-PDQ

Here's the test code. I've also attached a simple workspace.

Code: Select all

{********************************************************************************************************************
Name : $Text_Scrolling_Test
Description : Want text to stay fixed on right edge of chart when the chart is scrolled (like MC horz line)
Last Modified Date : 03/20/2017
********************************************************************************************************************}

[RecoverDrawings = false];
[LegacyColorValue = false];

{********************************************************************************************************************
inputs and variable initialization section
********************************************************************************************************************}

inputs:
Plot_Price (1385.5);

variables:
Swing_Line (0),
Swing_Text (0),
Text_Plot_Date (0),
Text_Plot_Time (0);

{*********************************************************************************************************************
draw line and text
*********************************************************************************************************************}

Text_Plot_Date = JulianToDate(GetAppInfo(aiRightDispDateTime)); { get date value of right edge of chart }
Text_Plot_Time = DateTime2ELTime_s(GetAppInfo(aiRightDispDateTime)); { get time value of right edge of chart }

if LastBarOnChart then once begin

Swing_Line = TL_New_bn(currentbar, Plot_Price, currentbar, Plot_Price); { create new line object }
TL_SetExtRight(Swing_Line, true); { set extend right to true }
TL_setsize(Swing_Line, 0.5); { set line weight }
TL_setstyle(Swing_Line, tool_solid); { set line style }
TL_setcolor(Swing_Line, yellow); { set line color }

Swing_Text = Text_New(Text_Plot_Date, Text_Plot_Time, Plot_Price, {create new text object }
numtostr(Swing_Text, 1));
Text_SetColor(Swing_Text, yellow);
Text_SetAttribute(Swing_Text, 1, true);
Text_SetStyle(Swing_Text, 1, 1);
Text_SetSize(Swing_Text, 9);
end;

{*********************************************************************************************************************
update trend lines and text positions
*********************************************************************************************************************}

RecalcLastBarAfter(1);

TL_SetBegin_bn(Swing_Line, currentbar, Plot_Price); { update trend line values }
TL_SetEnd_bn(Swing_Line, currentbar + 20, Plot_Price);

Text_SetString(Swing_Text, numtostr(Plot_Price, 1)); { update the swing text string }
Text_SetLocation_s(Swing_Text, Text_Plot_Date, Text_Plot_Time, Plot_Price); { move text location to right edge }

{*********************************************************************************************************************
diagnostic print section
*********************************************************************************************************************}

once begin

ClearPrintLog;
end;

print(Text_Plot_Date:6:0, " ", Text_Plot_Time:8:0);
Attachments
Scroll Test.wsp
(85.49 KiB) Downloaded 253 times
2017-03-20_2332.png
(27.43 KiB) Downloaded 824 times
2017-03-20_2331.png
(28.33 KiB) Downloaded 824 times
2017-03-20_2330.png
(25.89 KiB) Downloaded 824 times
2017-03-20_2326.png
(31.72 KiB) Downloaded 824 times
Last edited by PD Quig on 26 Mar 2017, edited 1 time in total.

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

Re: Keeping text objects fixed on the right edge of the chart  [SOLVED]

Postby JoshM » 26 Mar 2017

I'm using aiRightDispDateTime to get the date and time values of the right edge. I can see from output that the correct values of date and time are getting picked up on the fly as I scroll around. But for some reason that I can't figure, the Text_SetLocation is not moving the text to the date and time. I've spent about two hours experimenting to no avail. If anybody has any clues I'd be most appreciative.
Have you tried using Text_SetLocation_s or Text_SetLocation_DT for more precision? Especially that latter, when used with `GetAppInfo(aiRightDispDateTime)` should locate the text box with the highest precision possible (that is, at the exact location of the chart's right margin).

I can't say I'm confident that this will help, but it's when examining your code and screenshot unfortunately the only thing that comes to mind. Perhaps someone else has a better idea. :)

PD Quig
Posts: 191
Joined: 27 Apr 2010
Location: San Jose
Has thanked: 67 times
Been thanked: 10 times

Re: Keeping text objects fixed on the right edge of the chart

Postby PD Quig » 26 Mar 2017

Josh,

The combination of assigning the Text_Plot_Time variable using DateTime3ELTTime_s(GetAppInfo(aiRightDispDateTime)) and Text_SetLocation_s did the trick. Background dragging and using the scroll bar to move in either direction keeps the price text pegged close to the right hand edge of the chart.

Brilliant. Thank you!

-PDQ

PD Quig
Posts: 191
Joined: 27 Apr 2010
Location: San Jose
Has thanked: 67 times
Been thanked: 10 times

Re: Keeping text objects fixed on the right edge of the chart

Postby PD Quig » 29 Mar 2017

Quick note about using DateTime3ELTTime_s(GetAppInfo(aiRightDispDateTime)) and Text_SetLocation_s:

You should also use Text_Anchor_To_Bars(ID, true) when defining the text. Otherwise, the text jumps around.


Return to “MultiCharts”