Hi, i have been trying to understand loops and trying to get the efs to draw a line from the highest high in 'n' number of bars looking backwards. This works but for some reason it is also drawing a line underneath almost like it should be on a 'non price study'.
Anyway here is my script and also i have shown image or the error:
function preMain(){
setPriceStudy(true);
setShowCursorLabel(false);
}
function main() {
var Source = high(); // these are used as parameters for study
var Length = 100; // this is bars to look backwards
var vValue = Source.getValue(0);
var barIndex = 0;
for(var i = 0; i < Length; i++) {
vValue = Math.max(vValue, Source.getValue(-i));
if(vValue == Source.getValue(-i)){
barIndex = getCurrentBarIndex()-i;
drawLineRelative(barIndex, high(barIndex), 0, high(barIndex), PS_SOLID, 1, Color.red, "line1");
}
}
return barIndex;
}
Anyway here is my script and also i have shown image or the error:
function preMain(){
setPriceStudy(true);
setShowCursorLabel(false);
}
function main() {
var Source = high(); // these are used as parameters for study
var Length = 100; // this is bars to look backwards
var vValue = Source.getValue(0);
var barIndex = 0;
for(var i = 0; i < Length; i++) {
vValue = Math.max(vValue, Source.getValue(-i));
if(vValue == Source.getValue(-i)){
barIndex = getCurrentBarIndex()-i;
drawLineRelative(barIndex, high(barIndex), 0, high(barIndex), PS_SOLID, 1, Color.red, "line1");
}
}
return barIndex;
}
Comment