MC_Text_GetActive de-select function

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

MC_Text_GetActive de-select function

Postby PD Quig » 18 Jun 2016

Reference this thread: viewtopic.php?f=5&t=7764

Is there a command that you can embed in code that will programatically de-select a selected text object?

Several years ago, I used jbowles MC_Text_GetActive technique as the springboard for coding the activation / deactivation of several commands that are placed in the upper left corner of a chart. Works well with one minor exception: if you are trying to toggle between states you either have to click another text object or the background to de-select the selected text so you can select it again to change its state.

By way of example: one of my signals has a text object named "Exit at Target 1" that is colored red. When you select this text object, its color changes from red to green and it changes the target functionality so that the entire open position will be closed when the target 1 price level is hit. All good.

If, however, you want to switch the setting back to the normal target function, you need to click somewhere else and then click the now green text and it will change the target function back to the default and change the text object color back to red. It would be nice to be able to automatically remove the focus from the selected text after it was selected and the work had been done.

Meecc
Posts: 50
Joined: 23 Jun 2011
Has thanked: 22 times
Been thanked: 7 times

Re: MC_Text_GetActive de-select function

Postby Meecc » 20 Jun 2016

Please vote for this PM.
MC-1868 -
Add reserved words to deactive by code for Arrow, Text and Trend line

https://www.multicharts.com/pm/viewissu ... no=MC-1868

evdl
Posts: 401
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 85 times
Been thanked: 124 times

Re: MC_Text_GetActive de-select function

Postby evdl » 28 Oct 2016

i have been working with trading buttons on the chart and use GV to send changes to a signal realtime.

To avoid de-select I use this:

Code: Select all

Inputs:
Stop_Trading_Button_from_Top(0.10),
Stop_Trading_Button_from_Right(0.001),
Stop_Trading_Button_Text_Size(8);

Vars: // Stop Trading button
Intrabarpersist Stop_Trading_button(1),
Text_ID_Stop_Trading_ON(0),
Text_ID_Stop_Trading_OFF(0),
Intrabarpersist Text_Location_Stop_Trading(0),
Intrabarpersist ProcessDone_Stop_Trading_ON("N"),
Intrabarpersist ProcessDone_Stop_Trading_OFF("N"),
Intrabarpersist Stop_Trading_Button_horizontal(0), // horizontally setting
Intrabarpersist Stop_Trading_Button_vertical(0), // vertical setting
Intrabarpersist Stop_Trading_Button_offscreen_Location(0), // off screen setting
Intrabarpersist Stop_Trading_Button_ON_location(0),
// combination of horizontal and vertical setting
Intrabarpersist Stop_Trading_Button_OFF_location(0);
// combination of horizontal and vertical setting

// OVERALL VARIABELS ============================================

// location on screen
ScreenValHighest = GetAppInfo(aiHighestDispValue);// Highest price on the screen
ScreenValLowest = GetAppInfo(aiLowestDispValue);// Lowest price on the screen
ScreenBeginTime = GetAppInfo(aiLeftDispDateTime);// first date and time on screen
ScreenEndTime = GetAppInfo(aiRightDispDateTime);// last date and time on screen

Barspacing = getappinfo(aiBarSpacing);
// horizontal barspacing of chart (5 is standard setting)

// ==============================================================


// STOP TRADING BUTTON ==============================================================

if CurrentBar = 1 then begin
{Create the buttons on the first bar so you do not have to wait to start executing it}
Text_ID_Stop_Trading_ON = Text_New_s(Date,Time_s,0," STOP\n TRADE \n ON");
Text_ID_Stop_Trading_OFF = Text_New_s(Date,Time_s,0," STOP\n TRADE \n OFF");
end; // end of if CurrentBar = 1 then begin


If LastBarOnChart_s then Begin

// Stop Trading on button active
If MC_Text_GetActive = Text_ID_Stop_Trading_ON
then begin

If ProcessDone_Stop_Trading_ON = "N"
and Stop_Trading_Button = 0
then begin
{You have highlighted the text marked "Stop_Trading ON" to Stop the user
interactive process of your choice}
{Place code you want to execute when you highlight the "Stop_Trading ON"
command here:}

Stop_Trading_Button = 1; // set: to Stop Trading off

ProcessDone_Stop_Trading_ON = "Y";
// set "ON" proces to done, otherwise it will keep running.
ProcessDone_Stop_Trading_OFF = "N";
// set "OFF" proces to the Stop position
Playsound("C:\WINDOWS\Media\Notify.wav");
// The notify sound tells you a tick caused the process to execute one time
end;

end; // end of If MC_Text_GetActive = Text_ID_Stop_Trading_ON


// Stop Trading on button active
If MC_Text_GetActive = Text_ID_Stop_Trading_OFF
then begin

If ProcessDone_Stop_Trading_OFF = "N"
and Stop_Trading_Button = 1
then begin

Stop_Trading_Button = 0; // set: to Stop trading on

ProcessDone_Stop_Trading_OFF = "Y";
// set "OFF" proces to done, otherwise it will keep running.
ProcessDone_Stop_Trading_ON = "N";
// set "ON" proces to the Stop position
Playsound("C:\WINDOWS\Media\Notify.wav");
// The notify sound tells you a tick caused the process to execute one time
end;

end; // end of If MC_Text_GetActive = Text_ID_Stop_Trading_OFF


// set location and format text
{Note: Locating the text must be executed on every tick so manual chart scale
adjustments can be detected for repositioning it again}

Stop_Trading_Button_horizontal =
datetime2eltime_s(ScreenEndTime -
(OneMinuteDT * (Stop_Trading_Button_from_Right * (5/Barspacing))) );
// Space horizontally
Stop_Trading_Button_vertical =
ScreenValHighest - ((ScreenValHighest - ScreenValLowest) *
(Stop_Trading_Button_from_Top) );
Stop_Trading_Button_offscreen_Location = ScreenValHighest + 1000;

If Stop_Trading_Button = 0 then begin
Stop_Trading_Button_ON_location =
Text_SetLocation_s(Text_ID_Stop_Trading_ON, Date, Stop_Trading_Button_horizontal,
Stop_Trading_Button_vertical);
value22 = Text_SetBorder(Text_ID_Stop_Trading_ON, True);
value23 = Text_SetBGColor(Text_ID_Stop_Trading_ON, DarkGreen);
value24 = Text_SetColor(Text_ID_Stop_Trading_ON, White);
value25 = Text_SetSize(Text_ID_Stop_Trading_ON, Stop_Trading_Button_Text_Size);
value26 = Text_SetAttribute(Text_ID_Stop_Trading_ON, 1, true);
value27 = Text_SetStyle(Text_ID_Stop_Trading_ON,1, 1);
value28 = Text_SetLocation_s(Text_ID_Stop_Trading_OFF,Date, Time_s,
Stop_Trading_Button_offscreen_Location); // set button off screen
end;

If Stop_Trading_Button = 1 then begin
Stop_Trading_Button_OFF_location = Text_SetLocation_s(Text_ID_Stop_Trading_OFF,
Date, Stop_Trading_Button_horizontal, Stop_Trading_Button_vertical);
value22 = Text_SetBorder(Text_ID_Stop_Trading_OFF, True);
value23 = Text_SetBGColor(Text_ID_Stop_Trading_OFF, DarkRed);
value24 = Text_SetColor(Text_ID_Stop_Trading_OFF, White);
value25 = Text_SetSize(Text_ID_Stop_Trading_OFF, Stop_Trading_Button_Text_Size);
value26 = Text_SetAttribute(Text_ID_Stop_Trading_OFF, 1, true);
value27 = Text_SetStyle(Text_ID_Stop_Trading_OFF,1, 1);
value28 = Text_SetLocation_s(Text_ID_Stop_Trading_ON, Date, Time_s,
Stop_Trading_Button_offscreen_Location);
end;

end; // end of If LastBarOnChart_s then Begin
//

// send Stop Trading on/off status
GVSetNamedFloat("Stop Trading button Fdax A25", Stop_Trading_Button);
// value 1 = off, value 0 is on

==============================================================

END STOP TRADING BUTTON


Return to “MultiCharts”