 # Need help with Volume index indicator

#### lmk99

##### Member
VIP
Hello all,

I would like to scan for the negative volume index trendline being above the positive volume index trendline (as shown in the below image where the cursor crosshair is): The intuitive way to do this would be to simply scan for the NegativeVolumeIndex value being higher than the PositiveVolumeIndex value but that won't work apparently, because even though the negative trendline is charting above the positive trendline, the actual value for the negative trendline is smaller (85.8219 vs. 95.7026). I don't understand how the math is working to make that the case*, so I don't understand how to make this scan work.

Does anyone know how this could be done?

*Edit: On further thought I guess the reason (that the absolute value can be lower while the trendline can be higher than the other index's trendline) is that these index trendlines are showing relative changes over time instead of absolute values.

Last edited:

#### BenTen

Staff member
Staff
VIP
I see that you combined both indicators by dragging them into one section. This is not the right way to do it.

Here is the code which plots the Negative and Positive Index.

Code:
``````declare lower;

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

plot PVI = pos_index;
PVI.SetDefaultColor(GetColor(5));

def neg_index = compoundValue(1, neg_index + if (volume < volume and close != 0) then 100 * (close - close) / close else 0, 100);

plot NVI = neg_index;`````` #### lmk99

##### Member
VIP
I see that you combined both indicators by dragging them into one section. This is not the right way to do it.

Here is the code which plots the Negative and Positive Index.

Code:
``````declare lower;

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

plot PVI = pos_index;
PVI.SetDefaultColor(GetColor(5));

def neg_index = compoundValue(1, neg_index + if (volume < volume and close != 0) then 100 * (close - close) / close else 0, 100);

plot NVI = neg_index;`````` Thanks for your reply. I can't explain why but when I do it the "wrong way" by combining them into one section, it gives me a more usable signal when I look for the negative volume line being above the positive volume line (by contrast when I plot them as one study using the code you provided, the same bars don't show the negative trendline above the positive trendline).

Maybe it's just an idiosyncracy of how I am trading but for my purposes I actually need a scan that can identify when the negative vol index line is appearing above the pos vol index line in the situation that the studies are plotting as they do when combined into one section. Do you know if it's possible?

#### BenTen

Staff member
Staff
VIP
@lmk99 It's the "wrong way" because when you drag-n-drop two indicators into one lower section, they create a scaling issue, you'll notice then when you zoom in and out of your chart.

In addition to using the script I shared with you, there is an alternative. Go to your scanner and set up a condition like this: #### lmk99

##### Member
VIP
Hi, allow me to clarify, I want to scan for this situation: In this situation, I want to scan for "the positive volume index absolute value may (or may not) be higher than the negative volume index absolute value, but when the studies scale in a funky way because of being combined into one lower chart, the negative volume index trendline is above the positive volume index trendline."

If I did a scan using what you suggested, the situation of the above screenshot would not be picked up by the scanner because the negative volume index absolute value is in fact less than the positive volume index absolute value.

#### BenTen

Staff member
Staff
VIP
@lmk99 That is what I meant by doing it the "wrong way."

In reality, it never happened. But because you combined them into one lower section, the scaling gets mixed up, and now it's displaying the data incorrectly. I hope that helps.

#### lmk99

##### Member
VIP
@lmk99 That is what I meant by doing it the "wrong way."

In reality, it never happened. But because you combined them into one lower section, the scaling gets mixed up, and now it's displaying the data incorrectly. I hope that helps.

I know it never happened in reality, but for some reason I can't explain, it's actually a useful signal when I'm trading to look for this illusory "negative volume index trendline is above positive volume index trendline" signal. The real version of this (that is not a scaling illusion) is not a comparably useful signal. Odd, I know. Still, if it's possible then I'd like to scan for this illusory pattern that shows due to the scaling error.

#### BenTen

Staff member
Staff
VIP
@lmk99 It's not possible because value A was never higher than value B and vice versa. Best of luck.

#### lmk99

##### Member
VIP
@lmk99 It's not possible because value A was never higher than value B and vice versa. Best of luck.

I thought it might be possible if the scaling error was mathematically definable in some way, and could therefore be included in the scan formula to accordingly give the illusory trendline value instead of the real value. I guess whether it is theoretically possible or not, the scaling error would be difficult to mathematically define if it's not already a known definition that someone figured out before for some reason. Thanks for your replies and trying to help, I appreciate it and have a better understanding of the problem. All the best.

#### lmk99

##### Member
VIP
@lmk99 It's not possible because value A was never higher than value B and vice versa. Best of luck.

Just wanted to let you know that the scaling error was showing the neg vol index line above the pos vol index line incorrectly, but in a way that was predictable, i.e. that visual was happening with the scaling error specifically when the neg volume index value was increasing and the pos vol index value was decreasing over the same period. So that is the condition that I needed to describe in the scan, and your suggestion for how to make the scan was very useful for implementing that. Thanks again! Best wishes.

• BenTen