Setting the color of all text labels on a chart to one color  [SOLVED]

Questions about MultiCharts and user contributed studies.
PD Quig
Posts: 144
Joined: 27 Apr 2010
Location: San Jose
Has thanked: 51 times
Been thanked: 8 times

Setting the color of all text labels on a chart to one color

Postby PD Quig » 17 Sep 2012

The Text_SetColor function requires a text ID to set the color of an object, but my code draws two lines every day with price labels for each line. I'm looking for the easiest way to make all these labels blue instead of the default cyan.

This code below changes only the first day's labels after which the text color reverts to cyan:

Code: Select all

if time = PlotTime then begin

   Plot_high = RangeHigh;
   Plot_low  = RangeLow;

   // Draw lines
   
   High_line   =   TL_new(Date,Time,Plot_high,Date,EndTime,Plot_high);
            Tl_setstyle(High_line,tool_solid);
            Tl_setcolor(High_line, blue);
   Low_line   =    TL_new(Date,Time,Plot_low,Date,EndTime,Plot_low);
            Tl_setstyle(Low_line,tool_solid);
            Tl_setcolor(Low_line, blue);

   // Plot text

   High_text   =   Text_new(Date,TextOffsetTime,Plot_high,numtostr(Plot_high,decimals));
            Text_SetColor(1, blue);
   Low_text   =   Text_new(Date,TextOffsetTime,Plot_low ,numtostr(Plot_low,decimals));
            Text_SetColor(2, blue);
end;



The picture shows one label blue and the other cyan...which is a pain to read.

Thanks in advance for any ideas,

PDQ
Attachments
2012-09-17_1318.png
2012-09-17_1318.png (10 KiB) Viewed 246 times

User avatar
TJ
Posts: 6521
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 957 times
Been thanked: 1883 times

Re: Setting the color of all text labels on a chart to one c

Postby TJ » 17 Sep 2012

The error is in these lines. Check your object ID.

Code: Select all

High_text   =   Text_new(Date,TextOffsetTime,Plot_high,numtostr(Plot_high,decimals));
            Text_SetColor(1, blue);
   Low_text   =   Text_new(Date,TextOffsetTime,Plot_low ,numtostr(Plot_low,decimals));
            Text_SetColor(2, blue);

PD Quig
Posts: 144
Joined: 27 Apr 2010
Location: San Jose
Has thanked: 51 times
Been thanked: 8 times

Re: Setting the color of all text labels on a chart to one c

Postby PD Quig » 17 Sep 2012

I guess I wasn't clear: there are two text label objects IDs per day (High_text and Low_text). If the chart has ten days of data, there will be twenty text objects. If the chart has 30 days of data there will be sixty text objects. The objective is to set all the text objects to color=blue when the number of objects is dynamic depending upon how many days of data are present in the chart. Maybe the text ID has to be a variable and I have to do a loop? That would be a pain in the @ss solution for such a simple requirement. I was hoping I was missing something obvious...hopefully I still am.

User avatar
TJ
Posts: 6521
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 957 times
Been thanked: 1883 times

Re: Setting the color of all text labels on a chart to one c

Postby TJ » 17 Sep 2012

PD Quig wrote:I guess I wasn't clear: there are two text label objects IDs per day (High_text and Low_text). If the chart has ten days of data, there will be twenty text objects. If the chart has 30 days of data there will be sixty text objects. The objective is to set all the text objects to color=blue when the number of objects is dynamic depending upon how many days of data are present in the chart. Maybe the text ID has to be a variable and I have to do a loop? That would be a pain in the @ss solution for such a simple requirement. I was hoping I was missing something obvious...hopefully I still am.


Where did you get the "1" from for this line?

Text_SetColor(1, blue);

PD Quig
Posts: 144
Joined: 27 Apr 2010
Location: San Jose
Has thanked: 51 times
Been thanked: 8 times

Re: Setting the color of all text labels on a chart to one c

Postby PD Quig » 17 Sep 2012

It was arbitrary: the Text_SetColor function requires two input parameters, ID and color. I didn't find any other function or sample code showing how to set the color for all text objects. Seems like it ought to be easy.

User avatar
TJ
Posts: 6521
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 957 times
Been thanked: 1883 times

Re: Setting the color of all text labels on a chart to one c

Postby TJ » 17 Sep 2012

PD Quig wrote:It was arbitrary: the Text_SetColor function requires two input parameters, ID and color. I didn't find any other function or sample code showing how to set the color for all text objects. Seems like it ought to be easy.

The computer can read your mind.
But you must let it read your mind.
If you put a "1" there, the computer would assume your meant ID=1 and go change the color of that text to blue.

What is the ID for the High text?
What is the ID for the Low text?
These users thanked the author TJ for the post:
PD Quig

User avatar
TJ
Posts: 6521
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 957 times
Been thanked: 1883 times

Re: Setting the color of all text labels on a chart to one c

Postby TJ » 17 Sep 2012

PD Quig wrote:I guess I wasn't clear: there are two text label objects IDs per day (High_text and Low_text). If the chart has ten days of data, there will be twenty text objects. If the chart has 30 days of data there will be sixty text objects. The objective is to set all the text objects to color=blue when the number of objects is dynamic depending upon how many days of data are present in the chart. Maybe the text ID has to be a variable and I have to do a loop? That would be a pain in the @ss solution for such a simple requirement. I was hoping I was missing something obvious...hopefully I still am.


There might be 60 text objects,
but there will only be 2 TEXT IDs, high_text and low_text. (dynamic)
These users thanked the author TJ for the post:
PD Quig

PD Quig
Posts: 144
Joined: 27 Apr 2010
Location: San Jose
Has thanked: 51 times
Been thanked: 8 times

Re: Setting the color of all text labels on a chart to one c

Postby PD Quig » 17 Sep 2012

I borrowed this code. I have done very little coding for drawing and text objects and all based on the same borrowed code. When I do a Format Objects>Drawings I see text objects numbered up to 68. I thought the "Number" property of that grid referred to the ID of the text object. Apparently not so?

Anyway, the complete code for the plotting section is below. I'm not sure how to get the IDs for High_text and Low_text. I thought he assigned the IDs automatically as he created the text objects. I'm obviously confused and I appreciate your patience.



//***************************************************************
// plot lines and text section
//*****************************************************************

variables:
Decimals ($DecOfPriceScale),
Plot_high (0),
Plot_low (0),
Low_line (-1),
OR_Bar (-1),
High_Line (-1),
High_text (-1),
Low_text (-1);

if time = PlotTime then begin

Plot_high = RangeHigh;
Plot_low = RangeLow;

// Draw lines

High_line = TL_new(Date,Time,Plot_high,Date,EndTime,Plot_high);
Tl_setstyle(High_line,tool_solid);
Tl_setcolor(High_line, blue);
Low_line = TL_new(Date,Time,Plot_low,Date,EndTime,Plot_low);
Tl_setstyle(Low_line,tool_solid);
Tl_setcolor(Low_line, blue);

// Plot text

High_text = Text_new(Date,TextOffsetTime,Plot_high,numtostr(Plot_high,decimals));
Text_SetColor(1, blue);
Low_text = Text_new(Date,TextOffsetTime,Plot_low ,numtostr(Plot_low,decimals));
Text_SetColor(1, blue);
end;

PD Quig
Posts: 144
Joined: 27 Apr 2010
Location: San Jose
Has thanked: 51 times
Been thanked: 8 times

Re: Setting the color of all text labels on a chart to one c  [SOLVED]

Postby PD Quig » 17 Sep 2012

Never mind...D'oh!

I finally de-fogged and saw what you meant: use High_text and Low_text as the IDs

Thanks, TJ!

User avatar
TJ
Posts: 6521
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 957 times
Been thanked: 1883 times

Re: Setting the color of all text labels on a chart to one c

Postby TJ » 17 Sep 2012

PD Quig wrote:Never mind...D'oh!

I finally de-fogged and saw what you meant: use High_text and Low_text as the IDs

Thanks, TJ!

OK !


Return to “MultiCharts”