Set text_setBGcolor for textbox  [SOLVED]

Questions about MultiCharts and user contributed studies.
evdl
Posts: 401
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 85 times
Been thanked: 124 times

Set text_setBGcolor for textbox

Postby evdl » 12 Sep 2012

Hi

Can someone help me with the problem I have with setting different background colors according 3 conditions.

I would like to have the background of a textbox colored black in case positionprofit = 0. When positionprofit > 0 then the color need to be green and with positionprofit < 0, color red.

This is the code I use to give it one color

Code: Select all

// Create textbox
once begin
textobj_profit_loss = Text_new_s(juliantodate(getappinfo(airightdispdatetime)),
Getappinfo(airightdispdatetime) - oneminute,
getappinfo(aihighestdispvalue) + ((Minmove / PriceScale) * ticksOffSetTop_profit),
Text(headerstr_profit_loss, Boxstr_8,Boxstr_9, Boxstr_10));

// Textbox formatting
value1 = Text_SetStyle(TextObj_profit_loss, 1, 0);
value2 = Text_SetFontName(TextObj_profit_loss, Text_FontName);
value3 = Text_SetBorder(TextObj_profit_loss, Text_DisplayBorder);
value4 = Text_SetSize(TextObj_profit_loss, Text_FontSize);
value5 = Text_SetBGColor(TextObj_profit_loss, black);
value6 = Text_SetColor(TextObj_profit_loss, Text_FontColor);

// Update the textboxs location and text
value7 = Text_SetLocation_s(TextObj_profit_loss,
JulianToDate(GetAppInfo(airightDispDateTime)),
datetime2eltime_s(GetAppInfo(airightDispDateTime) - oneMinute),
GetAppInfo(aihighestDispValue) - ((MinMove / PriceScale) * TicksOffSetTop_profit));
value8 = Text_SetString(TextObj_profit_loss, Text(headerstr_profit_loss, newline, boxStr_8, newline, newline, boxstr_9, newline, boxstr_10));
This I tried to get the three different colors, but I think textbox formatting is not working in a condition?

Code: Select all

If positionprofit > 0 then begin
value1 = Text_SetStyle(TextObj_profit_loss, 1, 0);
value2 = Text_SetFontName(TextObj_profit_loss, Text_FontName);
value3 = Text_SetBorder(TextObj_profit_loss, Text_DisplayBorder);
value4 = Text_SetSize(TextObj_profit_loss, Text_FontSize);
value5 = Text_SetBGColor(TextObj_profit_loss, green);
value6 = Text_SetColor(TextObj_profit_loss, Text_FontColor);
end;

If positionprofit = 0 then begin
value1 = Text_SetStyle(TextObj_profit_loss, 1, 0);
value2 = Text_SetFontName(TextObj_profit_loss, Text_FontName);
value3 = Text_SetBorder(TextObj_profit_loss, Text_DisplayBorder);
value4 = Text_SetSize(TextObj_profit_loss, Text_FontSize);
value5 = Text_SetBGColor(TextObj_profit_loss, black);
value6 = Text_SetColor(TextObj_profit_loss, Text_FontColor);
end;

if positionprofit < 0 then begin
value1 = Text_SetStyle(TextObj_profit_loss, 1, 0);
value2 = Text_SetFontName(TextObj_profit_loss, Text_FontName);
value3 = Text_SetBorder(TextObj_profit_loss, Text_DisplayBorder);
value4 = Text_SetSize(TextObj_profit_loss, Text_FontSize);
value5 = Text_SetBGColor(TextObj_profit_loss, red);
value6 = Text_SetColor(TextObj_profit_loss, Text_FontColor);
end;
The text will work with above code but only with color black (the first color that was seen by MC?)

For value5 I also tried the following:

Code: Select all

value5 = Text_SetBGColor(TextObj_profit_loss, iff(positionprofit > 0, green, red);
This will work for the green and red color of the background, but how do I add a third condition in the iff statement for the situation positionprofit = 0 and then color black.

User avatar
ABC
Posts: 718
Joined: 16 Dec 2006
Location: www.abctradinggroup.com
Has thanked: 125 times
Been thanked: 408 times
Contact:

Re: Set text_setBGcolor for textbox  [SOLVED]

Postby ABC » 12 Sep 2012

Hi evdl,

it's hard to tell from your code, but Text_SetBGColor will work with conditions. You can check with this simple piece of code:

Code: Select all

Inputs:
TestValue (0);

Variables:
TextID1 (-1),
TextID2 (-1);
once
begin
TextID1 = Text_New_S(Date, Time_S, High, "Test");
TextID2 = Text_New_S(Date, Time_S, Low, "Test2");

switch(TestValue)
begin
case = 1: Text_SetBGColor(TextID1, blue);
case = 2: Text_SetBGColor(TextID1, red);
default: Text_SetBGColor(TextID1, black);
end;

if TestValue = 1 then
Text_SetBGColor(TextID2, blue)
else
if TestValue = 2 then
Text_SetBGColor(TextID2, red)
else
Text_SetBGColor(TextID2, black);
end;
Is it possible that your conditions are only checked once or maybe once per trade? Anything that might prevent the conditions being checked at the time you want them to.

Regards,
ABC

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

Re: Set text_setBGcolor for textbox

Postby evdl » 13 Sep 2012

Hi ABC

Your were right about the script only checking the conditions only once. The textbox is only created once and the textbox formatting was below the textbox creating part in the script. So it was also checked once.

Now the textbox formatting part I already had, is moved in front of the textbox creating and the colors are changing according to the conditions.

Thanks for pointing this out.


Return to “MultiCharts”