Hi,
After struggling for hours (I hope this new documentation will come soon!), I managed to program the Value Chart Indicator.
However, it is now displayed as lines (see attachment), and I would like to display the output as a barchart, with the current values which make up the blue, red and green lines making up the bar.
Please see the formula below, never mind the large amount of comments. This was my first!! Any tips on how to do things more economical, are very welcome! Especially I wasn't able to use study.getValue(ATRStudy.ATR) to use the built-in ATR Study to calculate the 5 day MA. So I did the ATR manually
If anybody can explain to me how I can use the built-in study, that would be most helpful.
Hope to hear from you about the bar chart option.
Cheers,
Edo.
/************************************************** ****************************************
Description: This Indicator plots Value Chart Index, as described by Mark Helweg & David Stendahl, and explained
by René van Mourik in the Dutch magazine: Technische en Kwantitatieve Analyse, november 2002
The Value Chart Index is a statistical indicator, which indicates overbought and oversold situation
Provided By: Edo van der Zouwen. Copyright © 2002
************************************************** ****************************************/
/*
Explanation to the syntaxis:
Variable Axis = 5 day MA of (hi+lo)/2
Volatility Unit = 5 day MA of ATR / 5
Value Chart High = (high - Variable Axis) / Volatility Unit
Value Chart Low = (low - Variable Axis) / Volatility Unit
Value Chart Close = (close - Variable Axis) / Volatility Unit
Contrary to the original description by Helweg & Stendahl, Van Mourik uses ATR to calculate the Volatiliy Unit.
Originally only high and low were used
*/
function preMain() {
setStudyTitle("Value Chart Indicator");
setCursorLabelName("VC high", 0);
setCursorLabelName("VC low", 1);
setCursorLabelName("VC close", 2);
setDefaultBarFgColor(Color.green, 0);
setDefaultBarFgColor(Color.red, 1);
setDefaultBarFgColor(Color.blue, 2);
addBand (8, PS_DOT, 1, Color.grey);
addBand (4, PS_DOT, 1, Color.grey);
addBand (0, PS_DOT, 1, Color.grey);
addBand (-4, PS_DOT, 1, Color.grey);
addBand (-8, PS_DOT, 1, Color.grey);
setPlotType(PLOTTYPE_LINE);
}
function main(nInputLength) {
//Check inputlength - default is 5
if(nInputLength == null)
nInputLength = 5;
//Variable definition
var nLength = nInputLength;
var varAxis = 0.0; //Variable Axis
var volUnit = 0.0; //Volatility Unit
var valChartHigh = 0.0; //Value chart high
var valChartLow = 0.0; //Value chart low
var valChartClose = 0.0; //Value chart close
var dayhigh; //array dayhigh of nLength period
var daylow; //array dayhigh of nLength period
var closey; //array dayhigh of nLength period
var hilo = 0.0; //Range high - low
var hicy = 0.0; //Range hi - close yesterday
var locy = 0.0; //Range lo - close yesterday
var i;
var sumhilo = 0.0;
var sumATR = 0.0;
//Calculation of Variable Axis
//load arrays with values
var dayhigh = getValue("High", 0, -nLength);
var daylow = getValue("Low", 0, -nLength);
var closey = getValue("Close", 0, -nLength-1);
for(i = 0; i < nLength; i++) {
sumhilo += (dayhigh[i] + daylow[i])/2;
}
varAxis = sumhilo / nLength;
//Calculation MA of ATR and volatility Unit
for(i = 0; i < nLength; i++) {
hilo = dayhigh[i] - daylow[i];
hicy = Math.abs(dayhigh[i] - closey[i+1]);
locy = Math.abs(daylow[i] - closey[i+1]);
sumATR += Math.max(hilo, hicy, locy);
}
volUnit = sumATR / Math.pow(nLength, 2);
//Actual Value Chart Index calculation
var valChartHigh = (dayhigh[0] - varAxis) / volUnit;
var valChartLow = (daylow[0] - varAxis) / volUnit;
var valChartClose = (closey[0] - varAxis) / volUnit;
//Output
return new Array(valChartHigh, valChartLow, valChartClose);
}
After struggling for hours (I hope this new documentation will come soon!), I managed to program the Value Chart Indicator.
However, it is now displayed as lines (see attachment), and I would like to display the output as a barchart, with the current values which make up the blue, red and green lines making up the bar.
Please see the formula below, never mind the large amount of comments. This was my first!! Any tips on how to do things more economical, are very welcome! Especially I wasn't able to use study.getValue(ATRStudy.ATR) to use the built-in ATR Study to calculate the 5 day MA. So I did the ATR manually
If anybody can explain to me how I can use the built-in study, that would be most helpful.
Hope to hear from you about the bar chart option.
Cheers,
Edo.
/************************************************** ****************************************
Description: This Indicator plots Value Chart Index, as described by Mark Helweg & David Stendahl, and explained
by René van Mourik in the Dutch magazine: Technische en Kwantitatieve Analyse, november 2002
The Value Chart Index is a statistical indicator, which indicates overbought and oversold situation
Provided By: Edo van der Zouwen. Copyright © 2002
************************************************** ****************************************/
/*
Explanation to the syntaxis:
Variable Axis = 5 day MA of (hi+lo)/2
Volatility Unit = 5 day MA of ATR / 5
Value Chart High = (high - Variable Axis) / Volatility Unit
Value Chart Low = (low - Variable Axis) / Volatility Unit
Value Chart Close = (close - Variable Axis) / Volatility Unit
Contrary to the original description by Helweg & Stendahl, Van Mourik uses ATR to calculate the Volatiliy Unit.
Originally only high and low were used
*/
function preMain() {
setStudyTitle("Value Chart Indicator");
setCursorLabelName("VC high", 0);
setCursorLabelName("VC low", 1);
setCursorLabelName("VC close", 2);
setDefaultBarFgColor(Color.green, 0);
setDefaultBarFgColor(Color.red, 1);
setDefaultBarFgColor(Color.blue, 2);
addBand (8, PS_DOT, 1, Color.grey);
addBand (4, PS_DOT, 1, Color.grey);
addBand (0, PS_DOT, 1, Color.grey);
addBand (-4, PS_DOT, 1, Color.grey);
addBand (-8, PS_DOT, 1, Color.grey);
setPlotType(PLOTTYPE_LINE);
}
function main(nInputLength) {
//Check inputlength - default is 5
if(nInputLength == null)
nInputLength = 5;
//Variable definition
var nLength = nInputLength;
var varAxis = 0.0; //Variable Axis
var volUnit = 0.0; //Volatility Unit
var valChartHigh = 0.0; //Value chart high
var valChartLow = 0.0; //Value chart low
var valChartClose = 0.0; //Value chart close
var dayhigh; //array dayhigh of nLength period
var daylow; //array dayhigh of nLength period
var closey; //array dayhigh of nLength period
var hilo = 0.0; //Range high - low
var hicy = 0.0; //Range hi - close yesterday
var locy = 0.0; //Range lo - close yesterday
var i;
var sumhilo = 0.0;
var sumATR = 0.0;
//Calculation of Variable Axis
//load arrays with values
var dayhigh = getValue("High", 0, -nLength);
var daylow = getValue("Low", 0, -nLength);
var closey = getValue("Close", 0, -nLength-1);
for(i = 0; i < nLength; i++) {
sumhilo += (dayhigh[i] + daylow[i])/2;
}
varAxis = sumhilo / nLength;
//Calculation MA of ATR and volatility Unit
for(i = 0; i < nLength; i++) {
hilo = dayhigh[i] - daylow[i];
hicy = Math.abs(dayhigh[i] - closey[i+1]);
locy = Math.abs(daylow[i] - closey[i+1]);
sumATR += Math.max(hilo, hicy, locy);
}
volUnit = sumATR / Math.pow(nLength, 2);
//Actual Value Chart Index calculation
var valChartHigh = (dayhigh[0] - varAxis) / volUnit;
var valChartLow = (daylow[0] - varAxis) / volUnit;
var valChartClose = (closey[0] - varAxis) / volUnit;
//Output
return new Array(valChartHigh, valChartLow, valChartClose);
}
Comment