In the following code, why is it that the High/Low lines are drawn only once for the last bar? It seems that it would do it for every bar. (It does what I want but I don't understand). Thanks.
function preMain() {
setPriceStudy(true);
}
var vtime
var vHigh;
var vLow;
var BarCntr = 0;
function main() {
if (getBarState() == BARSTATE_NEWBAR) {
BarCntr +=1;
vHigh = high();
vLow = low();
debugPrint("Bar=" + BarCntr + " Max=" + vHigh + " Min=" + vLow + "\n");
for (i = 0; i < 20; ++i) {
vHigh = Math.max(high(-i), vHigh);
vLow = Math.min(low(-i), vLow);
}
drawLineRelative(-20, vHigh, 0, vHigh, PS_SOLID, 2, Color.red, "High");
drawLineRelative(-20, vLow, 0, vLow, PS_SOLID, 2, Color.green, "Low");
}
}
function preMain() {
setPriceStudy(true);
}
var vtime
var vHigh;
var vLow;
var BarCntr = 0;
function main() {
if (getBarState() == BARSTATE_NEWBAR) {
BarCntr +=1;
vHigh = high();
vLow = low();
debugPrint("Bar=" + BarCntr + " Max=" + vHigh + " Min=" + vLow + "\n");
for (i = 0; i < 20; ++i) {
vHigh = Math.max(high(-i), vHigh);
vLow = Math.min(low(-i), vLow);
}
drawLineRelative(-20, vHigh, 0, vHigh, PS_SOLID, 2, Color.red, "High");
drawLineRelative(-20, vLow, 0, vLow, PS_SOLID, 2, Color.green, "Low");
}
}
Comment