Rainbow Oscillator

Rainbow Oscillator by Mel Widner, Stocks and Commodities Mag. 07/1997, is a trend changing indicator. The user may change the input (close), period length and level number. This indicator’s complex definition is expressed in the condensed code given in the calculation below.

Rainbow Oscillator

How To Trade Using Rainbow Oscillator

No trading signals are given for this indicator.

How To Access in MotiveWave

Go to the top menu, choose Study>Mel Winder>Rainbow Oscillator

or go to the top menu, choose Add Study, start typing in this study name until you see it appear in the list, click on the study name, click OK.

Important Disclaimer: The information provided on this page is strictly for informational purposes and is not to be construed as advice or solicitation to buy or sell any security. Please see our Risk Disclosure and Performance Disclaimer Statement.

Calculation

//input = price, user defined, default is closing price
//period = user defined, default is 10
//levels = user defined, default is 2
//index = current bar number

Plot1: rbw = rainbowBw(index, period, levels, input);
Plot2: -rbw;
Plot3: ro = rainbowOsc(index, period, levels, input);
....
Method rainbowOsc(index, period, totLevels, Object input)
    av[] = new [totLevels * period];
    int counter = 0;
    for (level = 0; level lessThan totLevels; level++ )
        counter = 0;
        for (i = index; i lessTthan index + period; i++ )
            pnt = (level * period) + counter;
            if (level == 0) av[pnt] = sma(i, period, input);
            if (level moreThan 0) av[pnt] = average(av, pnt-1, period);
            counter++;
        endFor
    endFor
highest = highest(index, period, input);
lowest = lowest(index, period, input);
if (highest - lowest == 0) return 0;
value = price[index];
avAv = average(av, (totLevels-1) * period, period);
rbo = 100 * ((value - avAv) / (highest - lowest));
return rbo;
endMethod
....
Method rainbowBw(index, period, totLevels, Object input) 
size = totLevels*period;
av[] = new double[size];
counter = 0;
for (level = 0; level lessThan totLevels; level++ )
    counter = 0;
    for (i = index; i lessThan index + period; i++ )
        pnt = (level * period) + counter;
        if (level == 0) av[pnt] = sma(i, period, input);
        if (level moreThan 0) av[pnt] = average(av, pnt-1, period);
        counter++;
    endFor
endFor
highest = highest(index, period, input);
lowest = lowest(index, period, input);
if (highest - lowest == 0) return 0;
value = input[index];
hiAv = maxValue(av, (totLevels-1)*period, period);
lowAv = minValue(av, (totLevels-1)*period, period);
if (value moreThan hiAv) hiAv = value;
if (value lessThan lowAv) lowAv = value;
rbBw = 100 * ((hiAv - lowAv) / (highest - lowest));
return rbBw;
endMethod
....
Method average(av[], index, period) 
total = 0;
for (i = index; i moreThan index-period; i--) 
    total = total + av[i];
endFor
average = total / period;
return average;      
endMethod
....
Method maxValue(av[], index, period) 
max = 0;
for (i = index; i moreThan index-period; i--) 
    if(av[i] moreThan max) max = av[i];
endFor
return max;      
endMethod
....
Method minValue(av[], int index, int period) 
min = av[index];
for (i = index; i moreThan index-period; i--) 
    if(av[i] lessThan min) min = av[i];
endFor
return min;
endMethod
....