Script for Ultimate Oscillator

A forum for all EdgeRater users

Moderator: Chris White

Post Reply
Import
Posts: 21
Joined: Wed Dec 29, 2010 5:28 pm

Script for Ultimate Oscillator

Post by Import »

I have a script in another language for the Ultimate Oscillator, how can I convert it to Chart Script? Here's the script:

Code: Select all

input fastLength = 7;
input medLength = 14;
input slowLength = 28;

def trRng = TrueRange(high, close, low);

def trRngFast = sum(trRng, fastLength);
def trRngMed = sum(trRng, medLength);
def trRngSlow = sum(trRng, slowLength);

def diff = close - Min(close[1], low);

def diffFast = sum(diff, fastLength);
def diffMed = sum(diff, medLength);
def diffSlow = sum(diff, slowLength);

def factorFast = slowLength / fastLength;
def factorMed = slowLength / medLength;

def valFast = (diffFast / trRngFast) * factorFast;
def valMed = (diffMed / trRngMed) * factorMed;
def valSlow = (diffSlow / trRngSlow);

plot UltOsc = if trRngFast == 0 or trRngMed == 0 or trRngSlow == 0 then 0 
else (valFast + valMed + valSlow) / (factorFast + factorMed + 1);
UltOsc.SetDefaultColor(GetColor(1));
Chris White
Posts: 212
Joined: Mon Nov 29, 2010 9:21 pm

Re: Script for Ultimate Oscillator

Post by Chris White »

There is already an indicator in EdgeRater for the Ultimate Oscillator, it is called 'ULT', and here's the script:

Code: Select all

LC :=REF(C,1);
TL :=MIN(L,LC);
BP :=C-TL;
TR := MAX(H-L,ABS(LC-H),ABS(LC-L));
BPSum1 := MA(BP,N1);
BPSum2 := MA(BP,N2);
BPSum3 := MA(BP,N3);
TRSum1 := MA(TR,N1);
TRSum2 := MA(TR,N2);
TRSum3 := MA(TR,N3);
RawUO :=4*(BPSum1/TRSum1)+2*(BPSum2/TRSum2)+(BPSum3/TRSum3);
(RawUO/(4+2+1))*100,Width2,HighQuality;
This is calculated in a slightly different way to the code you provided but does the same thing. One difference is that it is scaled from 0 to 100 instead of from 0 to 1.

As an example of how to convert the code you provided I have done so and come up with the following script:

Code: Select all

LC:= REF(C,1);
TR:= MAX(LC, H) - MIN(LC, L);

TR1:= SUM(TR, N1);
TR2:= SUM(TR, N2);
TR3:= SUM(TR, N3);

DIFF:= C - MIN(LC, L);

DIFF1:= SUM(DIFF, N1);
DIFF2:= SUM(DIFF, N2);
DIFF3:= SUM(DIFF, N3);

FACTOR1:= N3 / N1;
FACTOR2:= N3 / N2;

VAL1:= (DIFF1 / TR1) * FACTOR1;
VAL2:= (DIFF2 / TR2) * FACTOR2;
VAL3:= DIFF3 / TR3;

Cond1:= TR1 == 0 | TR2 == 0 | TR3 == 0;
ULTOSC: IF(Cond1, 0, (VAL1 + VAL2 + VAL3) / (FACTOR1 + FACTOR2 + 1));

Here's a chart with both the original script indicator 'ULT' and the new script indicator 'ULT2' plotted in a sub area:
The original Ultimate oscillator (ULT) plotted above the script conversion for the Ultimate Oscillator (ULT2)
The original Ultimate oscillator (ULT) plotted above the script conversion for the Ultimate Oscillator (ULT2)
ultimateoscillator.png (26.43 KiB) Viewed 20455 times
canucck
Posts: 19
Joined: Sun Dec 18, 2011 9:00 am

Re: Script for Ultimate Oscillator

Post by canucck »

Damn, you're good! Thanks!! :D
Post Reply