Positive Volume Index

ThinkStudy

New member
Anyway to do a Positive Volume Index on TOS that plots a moving average and has customizable inputs?



D4Wpi3h.jpg
[/IMG]

IQwQGR1.jpg
[/IMG]
 
Last edited by a moderator:
Solution
What would the final script look like please? Thanks in advance

The final script with priceclose feild working:


# ########################################################
# Positive Volume Index
# ########################################################

declare lower;

input AvgType = averageType.SIMPLE;
input Length = 50;
input priceclose = close;

def index = compoundValue(1, index[1] + if (volume > volume[1] and priceclose[1] != 0) then 100 * (priceclose - priceclose[1]) / priceclose[1] else 0, 100);

plot PVI = index;
plot AVG = MovingAverage(AvgType, index, Length);
PVI.SetDefaultColor(GetColor(5));
AVG.SetDefaultColor(color.yellow);
Here's what i got, but it doesn't work:

# Positive Volume Index

declare lower;

input AvgType = averageType.SIMPLE;
input Length = 50;
input priceclose = close;

def index = compoundValue(1, index[1] + if (volume > volume[1] and close[1] != 0) then 100 * (close - close[1]) / close[1] else 0, 100);

plot PVI = index;
plot AVG = MovingAverage(AvgType, close, Length);
PVI.SetDefaultColor(GetColor(5));
AVG.SetDefaultColor(color.yellow);
 
Last edited by a moderator:
im not too concerned about having ALL the Moving Average Type input options of Simple, Exponential, Double Exponential, Triple Exponential, Hull, Time Series, Triangular, Variable, VIDYA, Weighted and Welles Wilder. I jsut mainly want a moving average with the Field Inputs of Open, High, Low, Close, hl/2, hl/3, hlcc/4 and ohlc/4 , and the period length input.
 
Last edited by a moderator:
You want an average of index instead of an average of close.
Thank You! That did the trick.

# ########################################################
# Positive Volume Index
# ########################################################

declare lower;

input AvgType = averageType.SIMPLE;
input Length = 50;
input priceclose = close;

def index = compoundValue(1, index[1] + if (volume > volume[1] and close[1] != 0) then 100 * (close - close[1]) / close[1] else 0, 100);

plot PVI = index;
plot AVG = MovingAverage(AvgType, index, Length);
PVI.SetDefaultColor(GetColor(5));
AVG.SetDefaultColor(color.yellow);
 
it doesnt look like the input priceclose feild is working, everything else is working on it though. do you know how to fix that?
priceclose is not used anywhere in the code.

Do you need it to work? If you use open or high or low instead of close does this still give you a useful result? The built in PositiveVolumeIndex study has no option for price type. It always uses close. So I would just delete the input priceclose = close; line.

If you want it to work then everywhere on the line of def index = should be priceclose instead of close.
 
What would the final script look like please? Thanks in advance

Ruby:
# ########################################################
# Positive Volume Index
# ########################################################

declare lower;

input AvgType = averageType.SIMPLE;
input Length = 50;

def index = compoundValue(1, index[1] + if (volume > volume[1] and close[1] != 0) then 100 * (close - close[1]) / close[1] else 0, 100);

plot PVI = index;
plot AVG = MovingAverage(AvgType, index, Length);
PVI.SetDefaultColor(GetColor(5));
AVG.SetDefaultColor(color.yellow);
 
What would the final script look like please? Thanks in advance

The final script with priceclose feild working:


# ########################################################
# Positive Volume Index
# ########################################################

declare lower;

input AvgType = averageType.SIMPLE;
input Length = 50;
input priceclose = close;

def index = compoundValue(1, index[1] + if (volume > volume[1] and priceclose[1] != 0) then 100 * (priceclose - priceclose[1]) / priceclose[1] else 0, 100);

plot PVI = index;
plot AVG = MovingAverage(AvgType, index, Length);
PVI.SetDefaultColor(GetColor(5));
AVG.SetDefaultColor(color.yellow);
 
Solution
Hi I've been trying to write code for this scanner. Specifically for when the 1. PVI has reversed direction and showing an inflection point positive . 2. This happens underneath the AVG line. 3. The PVI is not crossed up over the avg line 4. The average has a positive slope over the past 5 bars.

It runs but it gives mixed results and is driving me crazy!!!

script posvolume {
# Positive Volume Index
# ########################################################



# ########################################################
# Positive Volume Index
# ########################################################

declare lower;

input AvgType = averageType.SIMPLE;
input Length = 50;
input priceclose = close;

def index = compoundValue(1, index[1] + if (volume > volume[1] and priceclose[1] != 0) then 100 * (priceclose - priceclose[1]) / priceclose[1] else 0, 100);

plot PVI = index;
plot AVG = MovingAverage(AvgType, index, Length);
PVI.SetDefaultColor(GetColor(5));
AVG.SetDefaultColor(color.yellow);

}

input AvgType = AverageType.EXPONENTIAL;
input Length = 30;
input priceclose = close;

def index = CompoundValue(1, index[1] + if (volume > volume[1] and priceclose[1] != 0) then 100 * (priceclose - priceclose[1]) / priceclose[1] else 0, 100);

def PVI = index;
def AVG = MovingAverage(AvgType, index, Length);


def condition1 = Between(posvolume("length" = 30)."PVI", 0.99 * posvolume("length" = 30)."AVG", posvolume("length" = 30)."AVG") within 1 bar;
def condition2 = posvolume("length" = 30)."PVI" > posvolume("length" = 30)."PVI"[1] within 1 bar;

def condition3 = PVI[1] < AVG within 1 bar;

plot example = condition1 and condition2 and condition3 within 1 bar;
 
Hi I've been trying to write code for this scanner. Specifically for when the 1. AVG has reversed direction and showing an inflection point positive and positive slope for at least 2 bars. I also want to incorporate rsi and scan for when rsi is under the avg given the first condition is true. IS IT POSSIBLE TO REPLACE PVI WITH RSI ON THE STUDY???

THIS IS WHAT IM TALKING ABOUT VISUALLY FOR THE AVG LINE



input AvgType = AverageType.EXPONENTIAL;
input Length = 30;
input priceclose = close;

def index = CompoundValue(1, index[1] + if (volume > volume[1] and priceclose[1] != 0) then 100 * (priceclose - priceclose[1]) / priceclose[1] else 0, 100);

def PVI = index;
def AVG = MovingAverage(AvgType, index, Length);



def condition2 = posvolume("length" = 30)."avg" > posvolume("length" = 30)."avg"[1] within 1 bar;

def condition3 = RSI < AVG within 1 bar; (OBVIOUSLY I KNOW THIS WONT WORK BUT THIS IS THE CONDITION I WANT TO CODE FOR INCLUDED IN MY SCANNER AND STUDY)

plot example = condition2 and condition3 is true within 1 bar;
 
Last edited:
Hi I've been trying to write code for this scanner. Specifically for when the 1. avg has reversed direction and showing an inflection point positive and postive slope for at least 2 bars. I also want to incorporate rsi and scan for when rsi is under the avg given the first condition is true.

THIS IS WHAT IM TALKING ABOUT VISUALLY FOR THE AVG LINE
It runs but it gives mixed results and is driving me crazy!!!

script posvolume {
# Positive Volume Index
# ########################################################



# ########################################################
# Positive Volume Index
# ########################################################

declare lower;

input AvgType = averageType.SIMPLE;
input Length = 50;
input priceclose = close;

def index = compoundValue(1, index[1] + if (volume > volume[1] and priceclose[1] != 0) then 100 * (priceclose - priceclose[1]) / priceclose[1] else 0, 100);

plot PVI = index;
plot AVG = MovingAverage(AvgType, index, Length);
PVI.SetDefaultColor(GetColor(5));
AVG.SetDefaultColor(color.yellow);

}

input AvgType = AverageType.EXPONENTIAL;
input Length = 30;
input priceclose = close;

def index = CompoundValue(1, index[1] + if (volume > volume[1] and priceclose[1] != 0) then 100 * (priceclose - priceclose[1]) / priceclose[1] else 0, 100);

def PVI = index;
def AVG = MovingAverage(AvgType, index, Length);



def condition2 = posvolume("length" = 30)."avg" > posvolume("length" = 30)."avg"[1] within 1 bar;

def condition3 = RSI < AVG within 1 bar;

plot example = condition2 and condition3 is true within 1 bar;
 
Ruby:
# ########################################################
# Positive Volume Index
# ########################################################

declare lower;

input AvgType = averageType.SIMPLE;
input Length = 50;

def index = compoundValue(1, index[1] + if (volume > volume[1] and close[1] != 0) then 100 * (close - close[1]) / close[1] else 0, 100);

plot PVI = index;
plot AVG = MovingAverage(AvgType, index, Length);
PVI.SetDefaultColor(GetColor(5));
AVG.SetDefaultColor(color.yellow);
Hi, I have a question, when the Volume goes below Moving average, does it mean the momentum is decreasing and Bears are getting nervous?
 
Hi Conmayne, you have two moving averages and the their inputs named the same, I believe they should be different, input and input1,....


I adjusted That was a typo and thinkscript bug it does when adding that code to the scanner. My intentions are positive reversal of the AVG vol line (yellow) and and rsi that is under the Yellow line on the same study. I have no use for the PVI line(red)
 
Hi I've been trying to write code for this scanner. Specifically for when the 1. AVG has reversed direction and showing an inflection point positive and positive slope for at least 2 bars. I also want to incorporate rsi and scan for when rsi is under the avg given the first condition is true. IS IT POSSIBLE TO REPLACE PVI WITH RSI ON THE STUDY???

THIS IS WHAT IM TALKING ABOUT VISUALLY FOR THE AVG LINE



input AvgType = AverageType.EXPONENTIAL;
input Length = 30;
input priceclose = close;

def index = CompoundValue(1, index[1] + if (volume > volume[1] and priceclose[1] != 0) then 100 * (priceclose - priceclose[1]) / priceclose[1] else 0, 100);

def PVI = index;
def AVG = MovingAverage(AvgType, index, Length);



def condition2 = posvolume("length" = 30)."avg" > posvolume("length" = 30)."avg"[1] within 1 bar;

def condition3 = RSI < AVG within 1 bar; (OBVIOUSLY I KNOW THIS WONT WORK BUT THIS IS THE CONDITION I WANT TO CODE FOR INCLUDED IN MY SCANNER AND STUDY)

plot example = condition2 and condition3 is true within 1 bar;



UPDATE:

Solved my first problem it seems with this code:



input AvgType = AverageType.EXPONENTIAL;
input Length = 30;
input priceclose = close;

def index = CompoundValue(1, index[1] + if (volume > volume[1] and priceclose[1] != 0) then 100 * (priceclose - priceclose[1]) / priceclose[1] else 0, 100);

def PVI = index;
def AVG = MovingAverage(AvgType, index, Length);


#def condition1 = Between(posvolume("length" = 30)."PVI", 0.99 * posvolume("length" = 30)."AVG", posvolume("length" = 30)."AVG") within 1 bar;
#def condition2 = posvolume("length" = 30)."PVI" > posvolume("length" = 30)."PVI"[1] within 1 bar;

def condition3 = Avg[2] > avg[1] and avg[1] < avg[0];



plot scan = condition3 is true within 1 bars ;


NOW:

Im trying to figure out how to use rsi in place of PVI. PVI is needed for the calcualtion of AVG it seems so thats my dilemna.
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
261 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

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?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top