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
Floating Text Box on Chart [SOLVED]
- TJ
- Posts: 7742
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2222 times
Re: Floating Text Box on Chart
Please post your code.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
Adding the text is easy... sometimes it depends on how you code.
Re: Floating Text Box on Chart
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):
Here is my unsuccesful attempt to plot text:
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));
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));
- 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
At first glance, the required code is there. What makes this an "unsuccessful attempt"? Please be specific, that makes helping easier.Here is my unsuccesful attempt to plot text:
- 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
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:The text box plot is always "0" ... regardless of conditions.
Code: Select all
myText = IFFString(Condition1 and Condition3, "BUY",
IFFString(Condition2 and Condition4, "SELL",
""));
Plot1(myText);
Code: Select all
once vValue1=Text_New_Dt((vMostLeftDateTime+LeftPosition),((vHighestDispValue-vLowestDispValue)*TopPOsition+ vLowestDispValue)," ATR: " + myText + " ");
(...)
text_setstring(vValue1," ATR: " + myText + " ");
Re: Floating Text Box on Chart
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:
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));