The code below seems straightforward, but obviously I must be missing something. Take a look at the huge numbers in the debugPrintln output:
function preMain() {
setPriceStudy(false);
setStudyTitle("_testVol");
}
var red = 0;
var lime = 0;
var pryce = 0;
var pryceB = 0;
var nLength = null;
var diff2 = null;
var bInit = false;
var currVol = 0;
var myVol = 0;
function main()
{
if(bInit == false) {
if (diff2 == null) diff2 = new Array(nLength+1);
lime = 0;
red = 0;
bInit = true;
}
// on each new tick ...
lastVol = currVol;
currVol = volume(0);
if(lastVol > currVol)
// this is a new bar
myVol = (currVol/1000).toFixed(0); // this for what is both a new bar AND a new tick
else if(lastVol < currVol)
// we're on the same bar and it's a new tick
myVol = (currVol - lastVol).toFixed(0); // the volume to save is the difference between the current and preceding tick
// debugPrintln("myVol " +myVol);
/*
if(lastVol != currVol || pryceB != pryce);
debugPrintln("change ");
debugPrintln();
*/
pryceB = pryce; // put last tick's price into oldPrice var
pryce = close(0);
// debugPrintln("pryceB " +pryceB);
if(close(0) < pryceB) {// if new close is now lesss than the old close
red = myVol + red; // (myVol/1000).toFixed(1);
lastRed = true;
lastLime = false;
}
if(close(0) > pryceB) {// if new tick's close is more than the last tick's
lime = myVol + lime; // (myVol/1000).toFixed(1);
lastLime = true;
lastRed = false;
}
if(close(0) == pryceB && lastVol != currVol ) {// if new tick's close is equal to the last tick's
if(lastRed)
red = myVol + red; // (myVol/1000).toFixed(1);
if(lastLime)
lime = myVol + lime; // (myVol/1000).toFixed(1);
}
diff2[0] = lime - red;
// debugPrintln("myVol "+myVol);
debugPrintln("lime " +lime);
debugPrintln("red " + red);
// debugPrintln("diff2[0] " +diff2[0]);
debugPrintln();
return;
}
function preMain() {
setPriceStudy(false);
setStudyTitle("_testVol");
}
var red = 0;
var lime = 0;
var pryce = 0;
var pryceB = 0;
var nLength = null;
var diff2 = null;
var bInit = false;
var currVol = 0;
var myVol = 0;
function main()
{
if(bInit == false) {
if (diff2 == null) diff2 = new Array(nLength+1);
lime = 0;
red = 0;
bInit = true;
}
// on each new tick ...
lastVol = currVol;
currVol = volume(0);
if(lastVol > currVol)
// this is a new bar
myVol = (currVol/1000).toFixed(0); // this for what is both a new bar AND a new tick
else if(lastVol < currVol)
// we're on the same bar and it's a new tick
myVol = (currVol - lastVol).toFixed(0); // the volume to save is the difference between the current and preceding tick
// debugPrintln("myVol " +myVol);
/*
if(lastVol != currVol || pryceB != pryce);
debugPrintln("change ");
debugPrintln();
*/
pryceB = pryce; // put last tick's price into oldPrice var
pryce = close(0);
// debugPrintln("pryceB " +pryceB);
if(close(0) < pryceB) {// if new close is now lesss than the old close
red = myVol + red; // (myVol/1000).toFixed(1);
lastRed = true;
lastLime = false;
}
if(close(0) > pryceB) {// if new tick's close is more than the last tick's
lime = myVol + lime; // (myVol/1000).toFixed(1);
lastLime = true;
lastRed = false;
}
if(close(0) == pryceB && lastVol != currVol ) {// if new tick's close is equal to the last tick's
if(lastRed)
red = myVol + red; // (myVol/1000).toFixed(1);
if(lastLime)
lime = myVol + lime; // (myVol/1000).toFixed(1);
}
diff2[0] = lime - red;
// debugPrintln("myVol "+myVol);
debugPrintln("lime " +lime);
debugPrintln("red " + red);
// debugPrintln("diff2[0] " +diff2[0]);
debugPrintln();
return;
}
Comment