How does the Ultimate Oscillator work? What are its components?
Announcement
Collapse
No announcement yet.
Ultimate Oscillator
Collapse
X
-
Hmmm,
I pulled it up ok, but regardless, here is the code for the Ultimate Oscillator from that post.
PHP Code:function preMain(){
setStudyTitle("Ultimate Oscillator");
setCursorLabelName("UO");
addBand(70,PS_SOLID,1,Color.red);
addBand(50,PS_SOLID,1,Color.yellow);
addBand(30,PS_SOLID,1,Color.green);
}
function main(Period_short,Period_med,Period_long){
if(Period_short == null || Period_med == null || Period_long == null){
Period_short = 7;
Period_med = 14;
Period_long = 28;
}
var vMaxPeriod = Math.max(Math.max(Period_short, Period_med), Period_long);
/*TR (True Range is the higher of
1.) Today's High - Today's Low;
2.) Today's High - Yesterday's Close;
3.) Yesterday's Close - Today's Low.*/
var TR, TL, BP
var TH_TL = 0;
var TH_YC = 0;
var YC_TL = 0;
var vLows = low(0, -(vMaxPeriod+1));
var vCloses = close(0, -(vMaxPeriod+1));
var vHighs = high(0, -(vMaxPeriod+1));
var sumBP_short = 0;
var sumBP_med = 0;
var sumBP_long = 0;
var sumTR_short = 0;
var sumTR_med = 0;
var sumTR_long = 0;
for(i=0;i<vMaxPeriod;i++){
TL = Math.min(vLows[i], vCloses[i+1]);
BP = vCloses[i] - TL;
TH_TL = vHighs[i] - vLows[i];
TH_YC = vHighs[i] - vCloses[i+1];
YC_TL = vCloses[i+1] - vLows[i];
TR = Math.max(TH_TL,TH_YC);
TR = Math.max(TR,YC_TL);
if(i < Period_short) {
sumBP_short +=BP;
sumTR_short +=TR;
}
if(i < Period_med) {
sumBP_med +=BP;
sumTR_med +=TR;
}
if(i < Period_long) {
sumBP_long +=BP;
sumTR_long +=TR;
}
}
var RUO = 4*(sumBP_short/sumTR_short) + 2*(sumBP_med/sumTR_med) + (sumBP_long/sumTR_long);
return (RUO/(4+2+1))*100;
}
Comment
Comment