I am trying to recognize a certain pattern in a study (in this case CCI). Specifically, I would like to know when the CCI comes from above 100 and crosses through 0 without "backing up" meaning it has only gone in a down direction from a high above 100.
It was easy to determine when the CCI crosses thru zero. Is there an elegant way to recognize that it also has traveled from +100 down thru zero without having an up bar (or from below -100 to above zero without a down bar)?
here is the code that recognizes the zero crossover.
function main(Length,Source,Symbol,Interval,Upper,Lower,Par ams) {
if(bInit == false){
if(Symbol == null) Symbol = getSymbol();
if(Interval == null) Interval = getInterval();
var vSymbol = Symbol+","+Interval;
xCCI = cci(Length, eval(Source)(sym(vSymbol)));
setShowTitleParameters(eval(Params));
addBand( Upper, PS_DOT, 3, Color.red,"Upper");
addBand( Lower, PS_DOT, 3, Color.lime,"Lower");
addBand(0, PS_SOLID, 2, Color.black,"Zero");
bInit = true;
}
if (xCCI.getValue(-1) < 0 && xCCI.getValue(0) > 0) && {
setBarThickness(2);
setBarFgColor(Color.yellow);
}
else if (xCCI.getValue(-1) > 0 && xCCI.getValue(0) < 0) {
setBarThickness(2);
setBarFgColor(Color.red);
}
else {
setBarThickness(2);
setBarFgColor(Color.blue);
}
return getSeries(xCCI);
}
It was easy to determine when the CCI crosses thru zero. Is there an elegant way to recognize that it also has traveled from +100 down thru zero without having an up bar (or from below -100 to above zero without a down bar)?
here is the code that recognizes the zero crossover.
function main(Length,Source,Symbol,Interval,Upper,Lower,Par ams) {
if(bInit == false){
if(Symbol == null) Symbol = getSymbol();
if(Interval == null) Interval = getInterval();
var vSymbol = Symbol+","+Interval;
xCCI = cci(Length, eval(Source)(sym(vSymbol)));
setShowTitleParameters(eval(Params));
addBand( Upper, PS_DOT, 3, Color.red,"Upper");
addBand( Lower, PS_DOT, 3, Color.lime,"Lower");
addBand(0, PS_SOLID, 2, Color.black,"Zero");
bInit = true;
}
if (xCCI.getValue(-1) < 0 && xCCI.getValue(0) > 0) && {
setBarThickness(2);
setBarFgColor(Color.yellow);
}
else if (xCCI.getValue(-1) > 0 && xCCI.getValue(0) < 0) {
setBarThickness(2);
setBarFgColor(Color.red);
}
else {
setBarThickness(2);
setBarFgColor(Color.blue);
}
return getSeries(xCCI);
}
Comment