Reference to this link...
View the VIDYA (black line in EBAY..., the incorrect one has the black one on the last bars close (first file ), where it should be at the lower level. (Second file).
Maybe calc should stop on the previous bar, I mean the second to last bar on the right hand side of the chart...
Please help
CODE****************
var AbsCMO = 0.0;
var CurrentBar = 0;
var VIDYA = 0.0;
var VIDYA_1 = 0.0;
var lastbar = 0;
function preMain()
{
setPriceStudy(true);
setStudyTitle("IansVIDYA");
setCursorLabelName("VIDYA", 0);
setDefaultBarFgColor(Color.black, 0);
}
function main(Length, Smooth)
{
if (Length == null) { Length = 20; }//5 min 12, 2 min 20
if (Smooth == null) { Smooth = 10; }//5 min 5, 2 min 10
if (lastbar != getValue("rawtime",0)) {
CurrentBar += 1;
VIDYA_1 = VIDYA;
}
var BarState = getBarState();
var UP = 0.0;
var DN = 0.0;
var UpSum = 0.0;
var DnSum = 0.0;
// var Close = getValue("Close", 0, -(Length + 2));
var i;
for (i = 0; i > 0-(Length-1); i--) {
if (close(i) > close(i-1)) { UP = (close(i) - close(i-1)); } else { UP = 0.0; }
if (close(i) < close(i-1)) { DN = (Math.abs(close(i) - close(i-1))); } else { DN = 0.0; }
UpSum += UP;
DnSum += DN;
// debugPrintln("Vidya : ["+i+"] "+UpSum+" : "+DnSum);
}
// debugPrintln("Vidya : "+UpSum+" : "+DnSum);
if ((UpSum+DnSum) > 0) { AbsCMO = Math.abs((UpSum-DnSum)/(UpSum+DnSum)) ; }
var SC= 2/(Smooth+1);
if (CurrentBar <= Length) { VIDYA = close(); } else { VIDYA = (SC * AbsCMO * close()) + ((1 - (SC * AbsCMO)) * VIDYA_1); }
if (BarState == BARSTATE_NEWBAR) { VIDYA_1 = VIDYA; }
return VIDYA;
}
View the VIDYA (black line in EBAY..., the incorrect one has the black one on the last bars close (first file ), where it should be at the lower level. (Second file).
Maybe calc should stop on the previous bar, I mean the second to last bar on the right hand side of the chart...
Please help
CODE****************
var AbsCMO = 0.0;
var CurrentBar = 0;
var VIDYA = 0.0;
var VIDYA_1 = 0.0;
var lastbar = 0;
function preMain()
{
setPriceStudy(true);
setStudyTitle("IansVIDYA");
setCursorLabelName("VIDYA", 0);
setDefaultBarFgColor(Color.black, 0);
}
function main(Length, Smooth)
{
if (Length == null) { Length = 20; }//5 min 12, 2 min 20
if (Smooth == null) { Smooth = 10; }//5 min 5, 2 min 10
if (lastbar != getValue("rawtime",0)) {
CurrentBar += 1;
VIDYA_1 = VIDYA;
}
var BarState = getBarState();
var UP = 0.0;
var DN = 0.0;
var UpSum = 0.0;
var DnSum = 0.0;
// var Close = getValue("Close", 0, -(Length + 2));
var i;
for (i = 0; i > 0-(Length-1); i--) {
if (close(i) > close(i-1)) { UP = (close(i) - close(i-1)); } else { UP = 0.0; }
if (close(i) < close(i-1)) { DN = (Math.abs(close(i) - close(i-1))); } else { DN = 0.0; }
UpSum += UP;
DnSum += DN;
// debugPrintln("Vidya : ["+i+"] "+UpSum+" : "+DnSum);
}
// debugPrintln("Vidya : "+UpSum+" : "+DnSum);
if ((UpSum+DnSum) > 0) { AbsCMO = Math.abs((UpSum-DnSum)/(UpSum+DnSum)) ; }
var SC= 2/(Smooth+1);
if (CurrentBar <= Length) { VIDYA = close(); } else { VIDYA = (SC * AbsCMO * close()) + ((1 - (SC * AbsCMO)) * VIDYA_1); }
if (BarState == BARSTATE_NEWBAR) { VIDYA_1 = VIDYA; }
return VIDYA;
}
Comment