Close Price of Specific Ticker

rjacobse7

New member
Hi all,

I'm trying to write ThinkScript code for a %B indicator that is based on the close of the VIX. The indicator is fairly similar to the BollingerPercentB indicator given by ToS, but I wanted to make some modifications.

Firstly, I wanted the indicator to only take into account VIX. That is, regardless of which chart I am on/ showing, the study is only calculating from/for the VIX. Here's the code I have thus far:
Code:
``````declare lower;

input averageType = AverageType.SIMPLE;
input openPrice = open;
input displace = 0;
input length = 20;
input Num_Dev_Dn = -1.5;
input Num_Dev_up = 1.5;
input market = {default "VIX"};

### Error Here
input closePrice = close(market); #Error Here
### Error Here

def upperBand = BollingerBands(closePrice, displace, length, Num_Dev_Dn, Num_Dev_up, averageType).UpperBand;
def lowerBand = BollingerBands(closePrice, displace, length, Num_Dev_Dn, Num_Dev_up, averageType).LowerBand;

plot PercentB = (closePrice - lowerBand) / (upperBand - lowerBand) * 100;
plot ZeroLine = 0;
plot HalfLine = 50;
plot UnitLine = 100;

PercentB.DefineColor("None", Color.GRAY);
PercentB.DefineColor("0.1 Bound", Color.ORANGE);
PercentB.DefineColor("0.05 Bound", Color.DARK_GREEN);
PercentB.DefineColor("0 Bound", Color.GREEN);

PercentB.AssignValueColor(if PercentB > 10 then PercentB.Color("None")
else if PercentB <= 10 and PercentB > 5 then PercentB.Color("0.1 Bound")
else if PercentB <= 5 and PercentB > 0 then PercentB.Color("0.05 Bound")
else PercentB.Color("0 Bound"));

PercentB.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
PercentB.SetLineWeight(1);``````

and obviously there is an error when I try to set the closePrice to be for VIX only. I've checked out the thinkscript learning center but haven't been able to get much from it. Any suggestions on how this is possible?

This snippet will do:

`def ticker = close("VIX");`

Not the exact question you're looking for?

87k+ Posts
249 Online

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?