How to create watch list columns that outputs phrases based on stock indicators


Category:
0
0

Hello Hahn,

Can you design a watchlist column that interprets multiple indicators and outputs a phase?  For example,

These indicators will be

  1. Relative Volume
  2. % Change between the close of the previous candle
  3. RVI (Relative Volatility Index)

 

The conditions shall be

 

  • If the RVI is greater than or equal to 55 and the RELATIVEVOLUMESTDEV is greater than or equal to 2= “Massive volume surging up” (AssignBackgroundColor green)

 

  • If the RVI is greater than or equal to 55 and the RELATIVEVOLUMESTDEV is greater than or equal to 2 and the Close price %Change in last 1 minute is greater than 9%= “HALT WARNING” (AssignBackgroundColor yellow)

 

  •  If the RVI is less than or equal to 55 and the RELATIVEVOLUMESTDEV is greater than or equal to 2= “Massive volume surging down” (AssignBackgroundColor red)

 

Anything else that doesn’t fit these criteria = “none”

Marked as spam
Posted by (Questions: 22, Answers: 63)
Asked on June 23, 2018 11:26 am
192 views
1
Private answer

NOTE: followup questions and comments are to be added using the comment link below the original question or the answer. DO NOT USE THE “Add your Answer” box at the bottom of the thread. That is reserved for new answers to the question.

AddLabel() Method

How to dynamically set the label in a watchlist column. The very same method of adding a label to a chart is the same as we use for the text of a watchlist column. It is named: “AddLabel()”.

We have two prior posts that demonstrate how to dynamically set the text of the AddLabel() method.

One of these is used in a watchlist, but the logic is exactly the same as would be applied to a chart: https://www.hahn-tech.com/ans/trailing-stop-alert-column/

This is one that is applied to a chart: https://www.hahn-tech.com/ans/conditionally-set-color-text-of-chart-label/

RVI Watchlist Column

You have previously posted a request for the RVI changing background colors of a custom watchlist: https://www.hahn-tech.com/ans/relative-volatility-index-rvi-custom-watch-list/

The Solution

So we’ll be using most of that code in the solution for this one.

You did not provide your own code so I will take that to mean you don’t care to learn how to do this and are only looking for the solution. So I will only present the code.

Here is the full code. Screenshot below shows what it looks like.

#---------- RVI Section
input stDevLength = 10;
input averageLength = 14;
input averageType = AverageType.EXPONENTIAL;
def stDevHi = stDev(high, stDevLength);
def stDevLo = stDev(low, stDevLength);
def avgStDevHiUp = MovingAverage(averageType, if high > high[1] then stDevHi else 0, averageLength);
def avgStDevHiDown = MovingAverage(averageType, if high < high[1] then stDevHi else 0, averageLength); def avgStDevLoUp = MovingAverage(averageType, if low > low[1] then stDevLo else 0, averageLength);
def avgStDevLoDown = MovingAverage(averageType, if low < low[1] then stDevLo else 0, averageLength); def rviHi = if avgStDevHiUp + avgStDevHiDown == 0 then 50 else 100 * avgStDevHiUp / (avgStDevHiUp + avgStDevHiDown); def rviLo = if avgStDevLoUp + avgStDevLoDown == 0 then 50 else 100 * avgStDevLoUp / (avgStDevLoUp + avgStDevLoDown); def RVI = (rviHi + rviLo) / 2;
#---------- RelativeVolumeStDev Section
input length = 60;
input numDev = 2.0;
input allowNegativeValues = no;
def rawRelVol = (volume - Average(volume, length)) / StDev(volume, length);
def RelVol = if allowNegativeValues then rawRelVol else Max(0, rawRelVol);
#---------- Percent Change Section
def percentChange = 100 * (close[1] / close - 1);
#---------- Conditions
def up = RVI >= 55.0 and RelVol >= 2 and AbsValue(percentChange) <= 9.0;
def down = RVI <= 55.0 and RelVol >= 2 and AbsValue(percentChange) <= 9.0;
def halt = RVI <= 55.0 and RelVol >= 2 and AbsValue(percentChange) > 9.0;
#---------- Display Text
AddLabel(yes, if up then "Massive volume surging up" else if down then "Massive volume surging down" else if halt then "HALT WARNING" else "None", if up or down or halt then Color.BLACK else Color.CURRENT);
AssignBackgroundColor(if up then Color.GREEN else if down then Color.RED else if halt then Color.YELLOW else Color.CURRENT);

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4079)
Answered on June 23, 2018 4:25 pm
0

The RVI code from the past is perfect, thank you. I will test this now

( at June 23, 2018 4:26 pm)
0

So from further testing the code, there seems to be a requirement that needs to be added that I missed in the original post. Along with the current code, can you please add one more condition as a trigger. The condition that should be added is that the current candle bar candle must have at least 50k shares of volume before any of these are displayed.

Thank you

( at June 26, 2018 2:11 pm)
0

def volumeCondition = volume > 50000;
def up = volumeCondition and RVI >= 55.0 and RelVol >= 2 and AbsValue(percentChange) < = 9.0; def down = volumeCondition and RVI <= 55.0 and RelVol >= 2 and AbsValue(percentChange) < = 9.0; def halt = volumeCondition and RVI <= 55.0 and RelVol >= 2 and AbsValue(percentChange) > 9.0;

( at June 26, 2018 2:33 pm)
0

Im sorry Pete, where do I add this code to the current code already provided?

( at June 26, 2018 2:45 pm)
0

In the section that contains the conditions:
#———- Conditions

You should have been able to see that pretty quick. I only added one new line for the volume condition and then modified the three conditions to include the volume condition. So only one new line of code. The other three lines already existed, “def up”, “def down”, and “def halt”. This should be self evident?

( at June 26, 2018 2:53 pm)
0

Yes, I figured that but I still got the error invalid statement: def at 22:133

( at June 26, 2018 3:11 pm)
0

Ok, I see what happened. When I pasted those lines into the comment box it managed to break them. Have no idea how that is even possible. So I will repeat those lines of code individually, one line at a time and hope they don’t get broken this time.

def volumeCondition = volume > 50000;

def up = volumeCondition and RVI >= 55.0 and RelVol >= 2 and AbsValue(percentChange) <= 9.0;

def down = volumeCondition and RVI <= 55.0 and RelVol >= 2 and AbsValue(percentChange) <= 9.0;

def halt = volumeCondition and RVI <= 55.0 and RelVol >= 2 and AbsValue(percentChange) > 9.0;

( at June 26, 2018 3:31 pm)
0

In fact just to get those lines to code correctly I had to go into the administrative side of the site and man-handle them into place. Wow. Sorry about that. Should be good now.

( at June 26, 2018 3:36 pm)
0

I see I am still getting an error, I have a notepad attachment with the compiled code and errors. below

( at June 26, 2018 4:43 pm)
0
Private answer

Sorry to post here, but I did not know another way to post attachments outside of the main post

Attachments:
Marked as spam
Posted by (Questions: 22, Answers: 63)
Answered on June 26, 2018 4:44 pm
0

Instead of replacing the existing three lines: def up, def down and def halt. You left the originals in place and added the modified versions. The modified versions are meant to replace the originals. There should only be four lines of code under the section marked: #———- Conditions

( at June 26, 2018 4:49 pm)
0

GOLDEN !!!!

( at June 26, 2018 5:06 pm)