This is my version of the Chaikin volume oscillator. One added feature I've been experimenting with has been a cumulative net change counter, reporting the positive area of the indicator divided by the negative area. It would seem that this would be a meaningful short-hand report, similar to advance/decline and upvol/downvol ratios. Except that I don't know what period the enclosed code is using! Also, I'm wondering how to specify that the counter should begin at the start of the U.S. trading day, rather than whatever it is it uses whenever it is reloaded...
/************************************************** ******************
Title: Chaikin Oscillator for eSignal 7.x
By: Chris D. Kryza (Divergence Software, Inc.)
Email: [email protected]
Incept: 09/08/2003
Version: 1.0.0
================================================== ===================
Fix History:
09/08/2003 - Initial Release
1.0.0
================================================== ===================
Project Description:
Calculates the Chaikin Oscillator which is the difference between
two exponential averages of the accumulation/distribution line.
If you come across any fixes or have any ideas on how to spruce it up, I
would appreciate it if you would let me know ([email protected]).
Dislaimer: For educational purposes only! Obviously, no guarantees
whatsoever and use at your own risk.
************************************************** ********************/
//Global Variables
var grID = 0;
var nBarCount = 0;
var nAD = 0;
var nADCum = 0;
var nCoeff1 = 0;
var nCoeff2 = 0;
var nEMA1 = 0;
var nEMA2 = 0;
var Num = 0;
var vSignal = 0;
var lateHigh = 0;
var lateLow = 0;
var highBoundary = 0;
var lowBoundary = 0;
var testSum = 0;
var testSum2 = 0;
var histSig = 0;
var bInitialized = false;
var accumltr = 0;
var aFPArray = new Array();
var aADArray = new Array();
var aEMA1 = new Array();
var aEMA2 = new Array();
var aSigArray = new Array(5);
//== PreMain function required by eSignal to set things up
function preMain() {
var x;
var y;
setPriceStudy(false);
setStudyTitle("ChaikMy");
setCursorLabelName("Chaikin", 0);
setDefaultBarFgColor(Color.purple,0);
setDefaultBarFgColor(Color.paleyellow,1);
setDefaultBarFgColor(Color.RGB(0,192,160),2);
setDefaultBarFgColor(Color.RGB(0,192,160),3);
setPlotType( PLOTTYPE_DOT, 0);
setPlotType( PLOTTYPE_LINE, 1);
setPlotType( PLOTTYPE_DOT, 2);
setPlotType( PLOTTYPE_HISTOGRAM, 3);
setDefaultBarThickness( 1, 0 );
setDefaultBarThickness( 1, 1 );
setDefaultBarThickness( 1, 2 );
setDefaultBarThickness( 1, 23);
addBand( 0, PS_DASH, 2, Color.RGB(192,60,60), -10 );
grID = 0;
//initialize formula parameters
x=0;
aFPArray[x] = new FunctionParameter( "Fast", FunctionParameter.NUMBER);
with( aFPArray[x] ) {
setLowerLimit( 1 );
setUpperLimit( 50 );
setDefault( 3 );
}
x++;
aFPArray[x] = new FunctionParameter( "Slow", FunctionParameter.NUMBER);
with( aFPArray[x] ) {
setLowerLimit( 1 );
setUpperLimit( 120 );
setDefault( 10 );
}
x++;
aFPArray[x] = new FunctionParameter( "LineColor", FunctionParameter.COLOR);
with( aFPArray[x] ) {
setDefault( Color.purple );
}
x++;
aFPArray[x] = new FunctionParameter( "LineThickness", FunctionParameter.NUMBER);
with( aFPArray[x] ) {
setLowerLimit( 1 );
setUpperLimit( 20 );
setDefault( 1 );
}
for ( x=0; x<10; x++ ) {
aADArray[x] = 0.0;
aEMA1[x] = 0.0;
aEMA2[x] = 0.0;
}
for ( y=0; y<5; y++ ) {
aSigArray[y] = 0.0;
}
}
//== Main processing function
function main( Fast, Slow, LineColor, LineThickness ) {
var x;
//script is initializing
if ( getBarState() == BARSTATE_ALLBARS ) {
return null;
}
if ( bInitialized == false ) {
nCoeff1 = 2 / (Fast+1);
nCoeff2 = 2 / (Slow+1);
setDefaultBarFgColor( LineColor, 0 );
setDefaultBarThickness( LineThickness, 0 );
bInitialized = true;
}
//called on each new bar
if ( getBarState() == BARSTATE_NEWBAR ) {
nBarCount++;
aADArray.pop();
aADArray.unshift( 0 );
aEMA1.pop();
aEMA1.unshift( nEMA1 );
aEMA2.pop();
aEMA2.unshift( nEMA2 );
aSigArray.pop();
aSigArray.unshift( vSignal);
nADCum += nAD;
}
testSum = aSigArray[0] + 600000.0;
testSum2 = aSigArray[0] - 600000.0;
if((vSignal > 0.0 ) && (vSignal > testSum)) {
alertFunction(1);
setDefaultBarFgColor(Color.lime,1);
setDefaultBarThickness( 4, 1 );
} else if ((vSignal > highBoundary ) && (vSignal < testSum)) {
alertFunction(0);
setDefaultBarFgColor(Color.RGB(255,157,255),1);
setDefaultBarThickness( 4, 1 );
} else {
setDefaultBarFgColor(Color.paleyellow,1);
setDefaultBarThickness( 1, 1 );
}
if(vSignal > lateHigh ) lateHigh = vSignal;
highBoundary = .4 * lateHigh;
if(vSignal < lateLow ) lateLow = vSignal;
lowBoundary = .4 * lateLow;
nAD = ( volume() * ( (( close()-low() ) - ( high()-close() )) / ( high()-low() ) ) );
if ( isNaN( nAD ) )
nAD = 0;
aADArray[0] = nADCum + nAD;
nEMA1 = ( aADArray[0] * nCoeff1 ) + ( aEMA1[0] * ( 1.0-nCoeff1 ) );
nEMA2 = ( aADArray[0] * nCoeff2 ) + ( aEMA2[0] * ( 1.0-nCoeff2 ) );
vSignal = nEMA1 - nEMA2 ;
histSig = vSignal;
time = getHour()*100+getMinute()*1;
if (time > 625)
accumltr = accumltr + vSignal;
/*
debugPrintln();
debugPrintln("time: " + time);
debugPrintln("Net Chaikin (in Ms): " + formatPriceNumber(accumltr/1000000));
debugPrintln("vSignal:" + vSignal);
debugPrintln("nBarCount:" + nBarCount);
*/
// "TIB1")
if (accumltr/1000000 >= 0)
drawTextRelative(2,-100," "+formatPriceNumber(accumltr/1000000)+"M",Color.lime,null,Text.BOLD|Text.VCENTE R,"Arial",20,30);
else
drawTextRelative(2,-100," "+formatPriceNumber(accumltr/1000000)+"M",Color.RGB(192,0,120),null,Text.BOLD|T ext.VCENTER,"Arial",20,30);
if (vSignal < 0) {
setDefaultBarFgColor(Color.RGB(192,0,75),3);
} else {
setDefaultBarFgColor(Color.RGB(0,180,180),3);
}
if ( nBarCount > Slow ) {
return new Array( highBoundary, vSignal, lowBoundary, histSig );
}
}
/*************************************************
SUPPORT FUNCTIONS
**************************************************/
//== gID function assigns unique identifier to graphic/text routines
function gID() {
grID ++;
return( grID );
}
/*
function alertFunction(Num) {
if(Num == 1) {
Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\Applause.wav");
Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\Applause.wav");
} else {
Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\Glassbrk.wav");
Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\Glassbrk.wav");
}
}
*/
/************************************************** ******************
Title: Chaikin Oscillator for eSignal 7.x
By: Chris D. Kryza (Divergence Software, Inc.)
Email: [email protected]
Incept: 09/08/2003
Version: 1.0.0
================================================== ===================
Fix History:
09/08/2003 - Initial Release
1.0.0
================================================== ===================
Project Description:
Calculates the Chaikin Oscillator which is the difference between
two exponential averages of the accumulation/distribution line.
If you come across any fixes or have any ideas on how to spruce it up, I
would appreciate it if you would let me know ([email protected]).
Dislaimer: For educational purposes only! Obviously, no guarantees
whatsoever and use at your own risk.
************************************************** ********************/
//Global Variables
var grID = 0;
var nBarCount = 0;
var nAD = 0;
var nADCum = 0;
var nCoeff1 = 0;
var nCoeff2 = 0;
var nEMA1 = 0;
var nEMA2 = 0;
var Num = 0;
var vSignal = 0;
var lateHigh = 0;
var lateLow = 0;
var highBoundary = 0;
var lowBoundary = 0;
var testSum = 0;
var testSum2 = 0;
var histSig = 0;
var bInitialized = false;
var accumltr = 0;
var aFPArray = new Array();
var aADArray = new Array();
var aEMA1 = new Array();
var aEMA2 = new Array();
var aSigArray = new Array(5);
//== PreMain function required by eSignal to set things up
function preMain() {
var x;
var y;
setPriceStudy(false);
setStudyTitle("ChaikMy");
setCursorLabelName("Chaikin", 0);
setDefaultBarFgColor(Color.purple,0);
setDefaultBarFgColor(Color.paleyellow,1);
setDefaultBarFgColor(Color.RGB(0,192,160),2);
setDefaultBarFgColor(Color.RGB(0,192,160),3);
setPlotType( PLOTTYPE_DOT, 0);
setPlotType( PLOTTYPE_LINE, 1);
setPlotType( PLOTTYPE_DOT, 2);
setPlotType( PLOTTYPE_HISTOGRAM, 3);
setDefaultBarThickness( 1, 0 );
setDefaultBarThickness( 1, 1 );
setDefaultBarThickness( 1, 2 );
setDefaultBarThickness( 1, 23);
addBand( 0, PS_DASH, 2, Color.RGB(192,60,60), -10 );
grID = 0;
//initialize formula parameters
x=0;
aFPArray[x] = new FunctionParameter( "Fast", FunctionParameter.NUMBER);
with( aFPArray[x] ) {
setLowerLimit( 1 );
setUpperLimit( 50 );
setDefault( 3 );
}
x++;
aFPArray[x] = new FunctionParameter( "Slow", FunctionParameter.NUMBER);
with( aFPArray[x] ) {
setLowerLimit( 1 );
setUpperLimit( 120 );
setDefault( 10 );
}
x++;
aFPArray[x] = new FunctionParameter( "LineColor", FunctionParameter.COLOR);
with( aFPArray[x] ) {
setDefault( Color.purple );
}
x++;
aFPArray[x] = new FunctionParameter( "LineThickness", FunctionParameter.NUMBER);
with( aFPArray[x] ) {
setLowerLimit( 1 );
setUpperLimit( 20 );
setDefault( 1 );
}
for ( x=0; x<10; x++ ) {
aADArray[x] = 0.0;
aEMA1[x] = 0.0;
aEMA2[x] = 0.0;
}
for ( y=0; y<5; y++ ) {
aSigArray[y] = 0.0;
}
}
//== Main processing function
function main( Fast, Slow, LineColor, LineThickness ) {
var x;
//script is initializing
if ( getBarState() == BARSTATE_ALLBARS ) {
return null;
}
if ( bInitialized == false ) {
nCoeff1 = 2 / (Fast+1);
nCoeff2 = 2 / (Slow+1);
setDefaultBarFgColor( LineColor, 0 );
setDefaultBarThickness( LineThickness, 0 );
bInitialized = true;
}
//called on each new bar
if ( getBarState() == BARSTATE_NEWBAR ) {
nBarCount++;
aADArray.pop();
aADArray.unshift( 0 );
aEMA1.pop();
aEMA1.unshift( nEMA1 );
aEMA2.pop();
aEMA2.unshift( nEMA2 );
aSigArray.pop();
aSigArray.unshift( vSignal);
nADCum += nAD;
}
testSum = aSigArray[0] + 600000.0;
testSum2 = aSigArray[0] - 600000.0;
if((vSignal > 0.0 ) && (vSignal > testSum)) {
alertFunction(1);
setDefaultBarFgColor(Color.lime,1);
setDefaultBarThickness( 4, 1 );
} else if ((vSignal > highBoundary ) && (vSignal < testSum)) {
alertFunction(0);
setDefaultBarFgColor(Color.RGB(255,157,255),1);
setDefaultBarThickness( 4, 1 );
} else {
setDefaultBarFgColor(Color.paleyellow,1);
setDefaultBarThickness( 1, 1 );
}
if(vSignal > lateHigh ) lateHigh = vSignal;
highBoundary = .4 * lateHigh;
if(vSignal < lateLow ) lateLow = vSignal;
lowBoundary = .4 * lateLow;
nAD = ( volume() * ( (( close()-low() ) - ( high()-close() )) / ( high()-low() ) ) );
if ( isNaN( nAD ) )
nAD = 0;
aADArray[0] = nADCum + nAD;
nEMA1 = ( aADArray[0] * nCoeff1 ) + ( aEMA1[0] * ( 1.0-nCoeff1 ) );
nEMA2 = ( aADArray[0] * nCoeff2 ) + ( aEMA2[0] * ( 1.0-nCoeff2 ) );
vSignal = nEMA1 - nEMA2 ;
histSig = vSignal;
time = getHour()*100+getMinute()*1;
if (time > 625)
accumltr = accumltr + vSignal;
/*
debugPrintln();
debugPrintln("time: " + time);
debugPrintln("Net Chaikin (in Ms): " + formatPriceNumber(accumltr/1000000));
debugPrintln("vSignal:" + vSignal);
debugPrintln("nBarCount:" + nBarCount);
*/
// "TIB1")
if (accumltr/1000000 >= 0)
drawTextRelative(2,-100," "+formatPriceNumber(accumltr/1000000)+"M",Color.lime,null,Text.BOLD|Text.VCENTE R,"Arial",20,30);
else
drawTextRelative(2,-100," "+formatPriceNumber(accumltr/1000000)+"M",Color.RGB(192,0,120),null,Text.BOLD|T ext.VCENTER,"Arial",20,30);
if (vSignal < 0) {
setDefaultBarFgColor(Color.RGB(192,0,75),3);
} else {
setDefaultBarFgColor(Color.RGB(0,180,180),3);
}
if ( nBarCount > Slow ) {
return new Array( highBoundary, vSignal, lowBoundary, histSig );
}
}
/*************************************************
SUPPORT FUNCTIONS
**************************************************/
//== gID function assigns unique identifier to graphic/text routines
function gID() {
grID ++;
return( grID );
}
/*
function alertFunction(Num) {
if(Num == 1) {
Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\Applause.wav");
Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\Applause.wav");
} else {
Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\Glassbrk.wav");
Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\Glassbrk.wav");
}
}
*/
Comment