Floating Text Box on Chart  [SOLVED]

Questions about MultiCharts and user contributed studies.
brunor
Posts: 65
Joined: 11 Feb 2013
Has thanked: 24 times
Been thanked: 6 times

Floating Text Box on Chart  [SOLVED]

Postby brunor » 10 Aug 2015

I use "NumToStr(vRSI2,2)" as part of the code for a floating text box (on chart) to display a calculated value. Is it possible to display text such as "BUY" in a floating text box if conditions are met?
Appreciate any feedback.
Bruno

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

Re: Floating Text Box on Chart

Postby TJ » 10 Aug 2015

I use "NumToStr(vRSI2,2)" as part of the code for a floating text box (on chart) to display a calculated value. Is it possible to display text such as "BUY" in a floating text box if conditions are met?
Appreciate any feedback.
Bruno
Please post your code.
Adding the text is easy... sometimes it depends on how you code.

brunor
Posts: 65
Joined: 11 Feb 2013
Has thanked: 24 times
Been thanked: 6 times

Re: Floating Text Box on Chart

Postby brunor » 10 Aug 2015

Hi TJ ... Appreciate your help.
Here is the code used to plot a calculated value (code was posted by another member of this forum and works perfectly, but was modified to display ATR):

Code: Select all

Inputs:
LeftPosition (0.1),
TopPOsition(0.95),
IndRange(14);
Vars:
recalcpersist vValue1(0),
recalcpersist vMostLeftDateTime(0),
recalcpersist vMostRightDateTime(0),
recalcpersist vHighestDispValue(0),
recalcpersist vLowestDispValue(0),
recalcpersist vRangeDateTime(0),
recalcpersist vRSI(0);

vRSI = AvgTrueRange(IndRange);

//RecalcLastBarAfter(0.5);
//
vMostLeftDateTime = GetAppInfo(aiLeftDispDateTime);
vMostRightDateTime = GetAppInfo(aiRightDispDateTime);
vHighestDispValue = GetAppInfo(aiHighestDispValue);
vLowestDispValue = GetAppInfo(aiLowestDispValue);
// Draws first time TextBox1
once vValue1=Text_New_Dt((vMostLeftDateTime+LeftPosition),((vHighestDispValue-vLowestDispValue)*TopPOsition+ vLowestDispValue)," ATR: " + NumToStr(vRSI,2) + " ");
// Formats TextBox1
text_setborder(vValue1,false);
text_setColor(vValue1,black);
text_setBGColor(vValue1,white);
text_lock(vValue1,TRUE);
// Redraws TextBox1 on recalc or tick
Text_SetLocation_DT(vValue1,(vMostLeftDateTime+LeftPosition),((vHighestDispValue-vLowestDispValue)*TopPOsition+ vLowestDispValue));
// Updates string of TextBox1
text_setstring(vValue1," ATR: " + NumToStr(vRSI,2) + " ");
Text_SetLocation_DT(vValue1,(vMostLeftDateTime+LeftPosition),((vHighestDispValue-vLowestDispValue)*TopPOsition+ vLowestDispValue));
Here is my unsuccesful attempt to plot text:

Code: Select all

Inputs:
LeftPosition (0.1),
TopPOsition(0.95),
IndRange(14);
Vars:
recalcpersist vValue1(0),
recalcpersist vMostLeftDateTime(0),
recalcpersist vMostRightDateTime(0),
recalcpersist vHighestDispValue(0),
recalcpersist vLowestDispValue(0),
recalcpersist vRangeDateTime(0),
recalcpersist vRSI(0);

vRSI = (Use Your own Formula Here);


Condition1 = Average(vRSI,3)> Average(vRSI,5) and vRSI> 0;
Condition2 = Average(vRSI,3)< Average(vRSI,5) and vRSI< 0;
Condition3 = Average(Close,10) > Average(Close,20);
Condition4 = Average(Close,10) < Average(Close,20);

Plot1(IFFString(Condition1 and Condition3,"BUY",IFFString(Condition2 and Condition4,"SELL","")));

//
//RecalcLastBarAfter(0.5);
//
//
vMostLeftDateTime = GetAppInfo(aiLeftDispDateTime);
vMostRightDateTime = GetAppInfo(aiRightDispDateTime);
vHighestDispValue = GetAppInfo(aiHighestDispValue);
vLowestDispValue = GetAppInfo(aiLowestDispValue);
// Draws first time TextBox1
once vValue1=Text_New_Dt((vMostLeftDateTime+LeftPosition),((vHighestDispValue-vLowestDispValue)*TopPOsition+ vLowestDispValue)," ATR: " + NumToStr(Plot1,0) + " ");
// Formats TextBox1
text_setborder(vValue1,false);
text_setColor(vValue1,black);
text_setBGColor(vValue1,white);
text_lock(vValue1,TRUE);
// Redraws TextBox1 on recalc or tick
Text_SetLocation_DT(vValue1,(vMostLeftDateTime+LeftPosition),((vHighestDispValue-vLowestDispValue)*TopPOsition+ vLowestDispValue));
// Updates string of TextBox1
text_setstring(vValue1," ATR: " + NumToStr(Plot1,0) + " ");
Text_SetLocation_DT(vValue1,(vMostLeftDateTime+LeftPosition),((vHighestDispValue-vLowestDispValue)*TopPOsition+ vLowestDispValue));

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

Re: Floating Text Box on Chart

Postby JoshM » 10 Aug 2015

Here is my unsuccesful attempt to plot text:
At first glance, the required code is there. What makes this an "unsuccessful attempt"? Please be specific, that makes helping easier. :)

brunor
Posts: 65
Joined: 11 Feb 2013
Has thanked: 24 times
Been thanked: 6 times

Re: Floating Text Box on Chart

Postby brunor » 10 Aug 2015

Hi Josh. The text box plot is always "0" ... regardless of conditions.

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

Re: Floating Text Box on Chart

Postby JoshM » 12 Aug 2015

The text box plot is always "0" ... regardless of conditions.
You're using NumToStr() to convert the value of Plot1 to a string in the script. However, Plot1 is not set to a number but is a string. I'd suggest using a string variable and using that variable to set Plot1 and the text box (so no NumToStr). For instance:

Code: Select all

myText = IFFString(Condition1 and Condition3, "BUY",
IFFString(Condition2 and Condition4, "SELL",
""));

Plot1(myText);
And then the text box:

Code: Select all

once vValue1=Text_New_Dt((vMostLeftDateTime+LeftPosition),((vHighestDispValue-vLowestDispValue)*TopPOsition+ vLowestDispValue)," ATR: " + myText + " ");

(...)

text_setstring(vValue1," ATR: " + myText + " ");
By the way, there seems to be a logical error in your script: your text box says "ATR: ", but the value it attempts to plot is not the ATR but instead the text "BUY" or "SELL". Perhaps this is what you intended, but just saying in case you looked over it.

brunor
Posts: 65
Joined: 11 Feb 2013
Has thanked: 24 times
Been thanked: 6 times

Re: Floating Text Box on Chart

Postby brunor » 12 Aug 2015

Hi Josh.
Your suggestion worked perfectly. I used "myText" and didn't require the use of "Plot1". I also removed "recalcpersist" from the variable vRSI(0) ... this was preventing the variable from updating.
I am very grateful for your assistance. Here is the final code:

Code: Select all

Inputs:
LeftPosition (0.1),
TopPOsition(0.95);

Vars:
recalcpersist vValue1(0),
recalcpersist vMostLeftDateTime(0),
recalcpersist vMostRightDateTime(0),
recalcpersist vHighestDispValue(0),
recalcpersist vLowestDispValue(0),
recalcpersist vRangeDateTime(0),
recalcpersist string myText("---"),

vRSI(0);
vRSI = Custom Formula;

Condition1 = Average(vRSI,3)> Average(vRSI,5) and vRSI> 0;
Condition2 = Average(vRSI,3)< Average(vRSI,5) and vRSI< 0;
Condition3 = Average(Close,10) > Average(Close,20);
Condition4 = Average(Close,10) < Average(Close,20);
Condition5 = Condition1 and condition3;
Condition6 = Condition2 and condition4;

myText = IFFString(Condition5,"BUY",IFFString(Condition6,"SELL","- - -"));

//RecalcLastBarAfter(0.5);
//
vMostLeftDateTime = GetAppInfo(aiLeftDispDateTime);
vMostRightDateTime = GetAppInfo(aiRightDispDateTime);
vHighestDispValue = GetAppInfo(aiHighestDispValue);
vLowestDispValue = GetAppInfo(aiLowestDispValue);
// Draws first time TextBox1
once vValue1=Text_New_Dt((vMostLeftDateTime+LeftPosition),((vHighestDispValue-vLowestDispValue)*TopPOsition+ vLowestDispValue)," SIGNAL: " + myText);
// Formats TextBox1
text_setborder(vValue1,false);
text_setColor(vValue1,black);
text_setBGColor(vValue1,white);
text_lock(vValue1,TRUE);
// Redraws TextBox1 on recalc or tick
Text_SetLocation_DT(vValue1,(vMostLeftDateTime+LeftPosition),((vHighestDispValue-vLowestDispValue)*TopPOsition+ vLowestDispValue));
// Updates string of TextBox1
text_setstring(vValue1," SIGNAL: " + myText);
Text_SetLocation_DT(vValue1,(vMostLeftDateTime+LeftPosition),((vHighestDispValue-vLowestDispValue)*TopPOsition+ vLowestDispValue));


Return to “MultiCharts”