I wanna to build a study for myself.
The detail of this study is trying to find out a series sequence green bars or red bars in which the spread of high and low prices is greater than 0.60, and highlight all these bars.
the following is a part of my code only for catching the green bars:
function preMain(){
setPriceStudy(true);
var NumBar=null;
}
function main(){
if(close(0)<open(0)&& close(-1)>open(-1)) {
var i=0;
while(close(i)<open(i)){
i-=1;
}
NumBar=i;
var xSpread= Math.max(high(0),high(-1))- Math.min(low(NumBar),low(NumBar+1));
if (xSpread>=0.60){
var i=NumBar;
while(i<=0){
setBarBgColor(Color.darkgreen,i);
i+=1;
}
}
}
}
Can someone help and tell me where is the problem?
PS: Because I'm a beginner of coding, so there may be some idiot mistakes in my codes. Don't laugh at me~
The detail of this study is trying to find out a series sequence green bars or red bars in which the spread of high and low prices is greater than 0.60, and highlight all these bars.
the following is a part of my code only for catching the green bars:
function preMain(){
setPriceStudy(true);
var NumBar=null;
}
function main(){
if(close(0)<open(0)&& close(-1)>open(-1)) {
var i=0;
while(close(i)<open(i)){
i-=1;
}
NumBar=i;
var xSpread= Math.max(high(0),high(-1))- Math.min(low(NumBar),low(NumBar+1));
if (xSpread>=0.60){
var i=NumBar;
while(i<=0){
setBarBgColor(Color.darkgreen,i);
i+=1;
}
}
}
}
Can someone help and tell me where is the problem?
PS: Because I'm a beginner of coding, so there may be some idiot mistakes in my codes. Don't laugh at me~