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);