how to switch ON/OFF text using MouseClickEvents?

Questions about MultiCharts and user contributed studies.
User avatar
arnie
Posts: 1594
Joined: 11 Feb 2009
Location: Portugal
Has thanked: 481 times
Been thanked: 514 times

how to switch ON/OFF text using MouseClickEvents?

Postby arnie » 27 Jun 2015

I'd like to be able to switch ON/OFF a text box from a chart.

This was my poor attempt to get it which was... nothing :(
Any help?

Code: Select all

[ProcessMouseEvents = true];

Inputs:
TextFont ("Microsoft Sans Serif2"),
TextSize (8),
TextColor (white);

Variables:
DailyHi (-999999),
DailyLo (+999999),
CurrentSess (0),
DailyCl (0),
prevDayHi (0),
prevDayLo (0),
prevDayCl (0),
txtBox (0);

If currentbar = 1 then begin
if MouseClickCtrlPressed then begin
txtBox = text_new_s(date,time_s, high, " ");
text_setfontname(txtBox, TextFont);
text_setcolor(txtBox, TextColor);
text_setsize(txtBox, TextSize);
Text_SetStyle(txtBox, 1, 2);
text_lock(txtBox, true);
end;
end;

CurrentSess = CurrentSession( 0 ) ;

// new session
if CurrentSess <> CurrentSess[1] then begin
prevDayCl = DailyCl;

if DailyHi <> -999999 then
prevDayHi = DailyHi;
if DailyLo <> +999999 then
prevDayLo = DailyLo;
DailyHi = -999999;
DailyLo = +999999;
end;

// high, low and close set
DailyCl = Close;

if High > DailyHi then
DailyHi = High;
if Low < DailyLo then
DailyLo = Low;

// text box string
text_setstring(txtBox, spaces(1) + "yDayHi " + spaces(4) + numtostr(prevdayhi, 2) + spaces(1) +
newline + spaces(1) +
"yDayLo " + spaces(4) + numtostr(prevDaylo, 2) + spaces(1) +
newline + spaces(1) +
"yDayCl " + spaces(5) + numtostr(prevdaycl, 2) + spaces(1));

// text location
if BarStatus(1) = 2 then begin
Text_SetLocation_s(txtBox, date, time_s, high);
end;

// plot lines
if prevDayHi <> 0 then
plot1(prevDayHi);
if prevDayLo <> 0 then
plot2(prevDayLo);
if prevDayCl <> 0 then
plot3(prevDayCl);

Image
Attachments
text_box.png
(22.33 KiB) Downloaded 679 times

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

Re: how to switch ON/OFF text using MouseClickEvents?

Postby TJ » 27 Jun 2015

Why do you need this?

Code: Select all

If currentbar = 1 then begin

User avatar
arnie
Posts: 1594
Joined: 11 Feb 2009
Location: Portugal
Has thanked: 481 times
Been thanked: 514 times

Re: how to switch ON/OFF text using MouseClickEvents?

Postby arnie » 27 Jun 2015

Why do you need this?

Code: Select all

If currentbar = 1 then begin
I stripped the code from all the unnecessary stuff so it could be used as an example an inside the currentbar = 1 I had all labels for all the calculations the study did with a true/false input.
Obviously for this there's no need for it.

Thanks TJ
I

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

Re: how to switch ON/OFF text using MouseClickEvents?

Postby JoshM » 27 Jun 2015

I'd like to be able to switch ON/OFF a text box from a chart.

This was my poor attempt to get it which was... nothing :(
Any help?
Means "switch ON/OFF" drawing/removing (and not relocating) a text box? If so, you may try this (untested, it's already late :] ):

Code: Select all

// Create text box with Control click
if MouseClickCtrlPressed then begin

txtBox = text_new_s(date,time_s, high, " ");
text_setfontname(txtBox, TextFont);
text_setcolor(txtBox, TextColor);
text_setsize(txtBox, TextSize);
Text_SetStyle(txtBox, 1, 2);
text_lock(txtBox, true);

end

// Remove text box with Shift click
else if (MouseClickShiftPressed) then begin

if (txtBox > 0) then
Text_Delete(txtBox);

end;

// If there's no text box on the chart, the
// remainder of the script can be skipped
if (txtBox < 1) then
#return;

// Place the code for calculating/updating the
// text box here

User avatar
arnie
Posts: 1594
Joined: 11 Feb 2009
Location: Portugal
Has thanked: 481 times
Been thanked: 514 times

Re: how to switch ON/OFF text using MouseClickEvents?

Postby arnie » 27 Jun 2015

Strange, I'm playing back data and when I call the box, it opens but as soon a new tick comes in the box disappears.
If I set RecoverDrawings = false then the box stays on the screen but I can't switch it OFF. Actually, everytime I click left or right button it creates a new box, even using John code.

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

Re: how to switch ON/OFF text using MouseClickEvents?

Postby JoshM » 28 Jun 2015

Strange, I'm playing back data and when I call the box, it opens but as soon a new tick comes in the box disappears.
If I set RecoverDrawings = false then the box stays on the screen but I can't switch it OFF. Actually, everytime I click left or right button it creates a new box, even using John code.
If you draw the drawing on bar close, `RecoverDrawings` isn't needed. But that does mean toggling the box on/off can't be implemented as creating/removing but rather as moving/moving again.

For example:

Code: Select all

once (BarStatus(1) = 2) begin

// Create text box here

end;

if (MouseClickCtrlPressed = true) then begin

// Move the text box to the current bar

end

else if (MouseClickShiftPressed = true) then begin

// Move text box to first bar
// (or somewhere else where it isn't visible

end;


Return to “MultiCharts”