Gaussian Rainbow MA Indicator for ThinkorSwim

BenTen

Administrative
Staff member
Staff
VIP
Lifetime
The Gaussian Rainbow indicator is quite popular among Forex traders to help identify trends, retracements, and sideways market. Though, it's nothing special. Just a trend following indicator built from gaussian filtration.

You can use it for short-term, medium term and long term trading. I heard it makes a great companion for scalping along with a momentum indicator or oscillator. Similar to using a single or double MAs, when the stock is trading above the rainbow then we assume it's trading in an uptrend. When the candles are below the rainbow then it's bearish.

A few examples of what the Rainbow indicator looks like:

NkVXGoY.png

rJRides.png


thinkScript Code

Code:
# Gaussian Rainbow
# Eric R
# 11.24.2013

declare upper;

# Study Inputs
input gaussian       = { "ONE", "TWO", "THREE", default "FOUR" };
input data           = HL2;
input length         = 10;
input gaussianOrder  = 3;
input cloud          = yes;

# Definitions
def w;
def beta;
def alpha;

def rbi1;  
def rbi2;  
def rbi3;  
def rbi4;
def rbi5;  
def rbi6;  
def rbi7;  
def rbi8;

# Alpha Calculation
w                = ( 2 * double.Pi / length );
beta             = ( 1 - cos( w ) ) / ( power( 1.414, 2.0 / gaussianOrder ) - 1 );
alpha            = ( -beta + sqRt( beta * beta + 2 * beta) );

# Average Calculations
switch( gaussian ) {

case "ONE":
rbi1         =       alpha * data + ( 1 - alpha ) * rbi1[1];
rbi2         =       alpha * rbi1 + ( 1 - alpha ) * rbi2[1];
rbi3         =       alpha * rbi2 + ( 1 - alpha ) * rbi3[1];
rbi4         =       alpha * rbi3 + ( 1 - alpha ) * rbi4[1];
rbi5         =       alpha * rbi4 + ( 1 - alpha ) * rbi5[1];
rbi6         =       alpha * rbi5 + ( 1 - alpha ) * rbi6[1];
rbi7         =       alpha * rbi6 + ( 1 - alpha ) * rbi7[1];
rbi8         =       alpha * rbi7 + ( 1 - alpha ) * rbi8[1];

case "TWO":
rbi1         =       power( alpha, 2 )     * data    +
2 *      ( 1 - alpha )    * rbi1[1] -
power( 1 - alpha, 2 ) * rbi1[2];

rbi2         =       power( alpha, 2 )     * rbi1    +
2 *      ( 1 - alpha )    * rbi2[1] -
power( 1 - alpha, 2 ) * rbi2[2];

rbi3         =       power( alpha, 2 )     * rbi2    +
2 *      ( 1 - alpha )    * rbi3[1] -
power( 1 - alpha, 2 ) * rbi3[2];

rbi4         =       power( alpha, 2 )     * rbi3    +
2 *      ( 1 - alpha )    * rbi4[1] -
power( 1 - alpha, 2 ) * rbi4[2];

rbi5         =       power( alpha, 2 )     * rbi4    +
2 *      ( 1 - alpha )    * rbi5[1] -
power( 1 - alpha, 2 ) * rbi5[2];

rbi6         =       power( alpha, 2 )     * rbi5    +
2 *      ( 1 - alpha )    * rbi6[1] -
power( 1 - alpha, 2 ) * rbi6[2];

rbi7         =       power( alpha, 2 )     * rbi6    +
2 *      ( 1 - alpha )    * rbi7[1] -
power( 1 - alpha, 2 ) * rbi7[2];

rbi8         =       power( alpha, 2 )     * rbi7    +
2 *      ( 1 - alpha )    * rbi8[1] -
power( 1 - alpha, 2 ) * rbi8[2];

case "THREE":
rbi1        =       power( alpha, 3 )     * data    +
3 *      ( 1 – alpha )    * rbi1[1] -
3 * power( 1 - alpha, 2 ) * rbi1[2] +
power( 1 - alpha, 3 ) * rbi1[3];

rbi2        =       power( alpha, 3 )     * rbi1    +
3 *      ( 1 – alpha )    * rbi2[1] -
3 * power( 1 - alpha, 2 ) * rbi2[2] +
power( 1 - alpha, 3 ) * rbi2[3];

rbi3        =       power( alpha, 3 )     * rbi2    +
3 *      ( 1 – alpha )    * rbi3[1] -
3 * power( 1 - alpha, 2 ) * rbi3[2] +
power( 1 - alpha, 3 ) * rbi3[3];

rbi4        =       power( alpha, 3 )     * rbi3    +
3 *      ( 1 – alpha )    * rbi4[1] -
3 * power( 1 - alpha, 2 ) * rbi4[2] +
power( 1 - alpha, 3 ) * rbi4[3];

rbi5        =       power( alpha, 3 )     * rbi4    +
3 *      ( 1 – alpha )    * rbi5[1] -
3 * power( 1 - alpha, 2 ) * rbi5[2] +
power( 1 - alpha, 3 ) * rbi5[3];

rbi6        =       power( alpha, 3 )     * rbi5    +
3 *      ( 1 – alpha )    * rbi6[1] -
3 * power( 1 - alpha, 2 ) * rbi6[2] +
power( 1 - alpha, 3 ) * rbi6[3];

rbi7        =       power( alpha, 3 )     * rbi6    +
3 *      ( 1 – alpha )    * rbi7[1] -
3 * power( 1 - alpha, 2 ) * rbi7[2] +
power( 1 - alpha, 3 ) * rbi7[3];

rbi8        =       power( alpha, 3 )     * rbi7    +
3 *      ( 1 – alpha )    * rbi8[1] -
3 * power( 1 - alpha, 2 ) * rbi8[2] +
power( 1 - alpha, 3 ) * rbi8[3];

case "FOUR":
rbi1        =       power( alpha, 4 )     * data    +
4 *      ( 1 – alpha )    * rbi1[1] –
6 * power( 1 - alpha, 2 ) * rbi1[2] +
4 * power( 1 - alpha, 3 ) * rbi1[3] -
power( 1 - alpha, 4 ) * rbi1[4];

rbi2        =       power( alpha, 4 )     * rbi1    +
4 *      ( 1 – alpha )    * rbi2[1] –
6 * power( 1 - alpha, 2 ) * rbi2[2] +
4 * power( 1 - alpha, 3 ) * rbi2[3] -
power( 1 - alpha, 4 ) * rbi2[4];

rbi3        =       power( alpha, 4 )     * rbi2    +
4 *      ( 1 – alpha )    * rbi3[1] –
6 * power( 1 - alpha, 2 ) * rbi3[2] +
4 * power( 1 - alpha, 3 ) * rbi3[3] -
power( 1 - alpha, 4 ) * rbi3[4];

rbi4        =       power( alpha, 4 )     * rbi3    +
4 *      ( 1 – alpha )    * rbi4[1] –
6 * power( 1 - alpha, 2 ) * rbi4[2] +
4 * power( 1 - alpha, 3 ) * rbi4[3] -
power( 1 - alpha, 4 ) * rbi4[4];

rbi5        =       power( alpha, 4 )     * rbi4    +
4 *      ( 1 – alpha )    * rbi5[1] –
6 * power( 1 - alpha, 2 ) * rbi5[2] +
4 * power( 1 - alpha, 3 ) * rbi5[3] -
power( 1 - alpha, 4 ) * rbi5[4];

rbi6        =       power( alpha, 4 )     * rbi5    +
4 *      ( 1 – alpha )    * rbi6[1] –
6 * power( 1 - alpha, 2 ) * rbi6[2] +
4 * power( 1 - alpha, 3 ) * rbi6[3] -
power( 1 - alpha, 4 ) * rbi6[4];

rbi7        =       power( alpha, 4 )     * rbi6    +
4 *      ( 1 – alpha )    * rbi7[1] –
6 * power( 1 - alpha, 2 ) * rbi7[2] +
4 * power( 1 - alpha, 3 ) * rbi7[3] -
power( 1 - alpha, 4 ) * rbi7[4];

rbi8        =       power( alpha, 4 )     * rbi7    +
4 *      ( 1 – alpha )    * rbi8[1] –
6 * power( 1 - alpha, 2 ) * rbi8[2] +
4 * power( 1 - alpha, 3 ) * rbi8[3] -
power( 1 - alpha, 4 ) * rbi8[4];
}

# Plots
plot ga1             = rbi1;
plot ga2             = rbi2;
plot ga3             = rbi3;
plot ga4             = rbi4;
plot ga5             = rbi5;
plot ga6             = rbi6;
plot ga7             = rbi7;
plot ga8             = rbi8;

# Look and Feel
ga1.assignValueColor( color.MAGENTA );
ga2.assignValueColor( color.PLUM );
ga3.assignValueColor( color.BLUE );
ga4.assignValueColor( color.CYAN );
ga5.assignValueColor( color.GREEN );
ga6.assignValueColor( color.YELLOW );
ga7.assignValueColor( color.DARK_ORANGE );
ga8.assignValueColor( color.RED );

ga1.hideTitle();
ga2.hideTitle();
ga3.hideTitle();
ga4.hideTitle();
ga5.hideTitle();
ga6.hideTitle();
ga7.hideTitle();
ga8.hideTitle();

# Cloud Plots
addCloud( if cloud == yes then ga1 else double.NaN, ga8, color.RED, color.BLACK );
addCloud( if cloud == yes then ga1 else double.NaN, ga7, color.DARK_ORANGE, color.BLACK );
addCloud( if cloud == yes then ga1 else double.NaN, ga6, color.YELLOW, color.YELLOW );
addCloud( if cloud == yes then ga1 else double.NaN, ga5, color.GREEN, color.GREEN );
addCloud( if cloud == yes then ga1 else double.NaN, ga4, color.BLUE, color.BLUE );
addCloud( if cloud == yes then ga1 else double.NaN, ga3, color.PLUM, color.PLUM );

Shareable Link

https://tos.mx/GK5TrQ
 

Attachments

  • NkVXGoY.png
    NkVXGoY.png
    227.9 KB · Views: 301
  • rJRides.png
    rJRides.png
    211.7 KB · Views: 309

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

He made it quite pretty. Biggest problem is that moving ave's lag but at least longer term it could help keep someone on trend as you've alluded to.
 
Question, is it possible to add the option to displace the averages?
here is the displaced version
Code:
# Gaussian Rainbow
# Eric R
# 11.24.2013

declare upper;

# Study Inputs
input gaussian       = { "ONE", "TWO", "THREE", default "FOUR" };
input data           = HL2;
input length         = 10;
input Displace =1;
input gaussianOrder  = 3;
input cloud          = yes;

# Definitions
def w;
def beta;
def alpha;

def rbi1; 
def rbi2; 
def rbi3; 
def rbi4;
def rbi5; 
def rbi6; 
def rbi7; 
def rbi8;

# Alpha Calculation
w                = ( 2 * double.Pi / length );
beta             = ( 1 - cos( w ) ) / ( power( 1.414, 2.0 / gaussianOrder ) - 1 );
alpha            = ( -beta + sqRt( beta * beta + 2 * beta) );

# Average Calculations
switch( gaussian ) {

case "ONE":
rbi1         =       (alpha * data + ( 1 - alpha ) * rbi1[1]);
rbi2         =       (alpha * rbi1 + ( 1 - alpha ) * rbi2[1] );;
rbi3         =       (alpha * rbi2 + ( 1 - alpha ) * rbi3[1] );;
rbi4         =       (alpha * rbi3 + ( 1 - alpha ) * rbi4[1] );;
rbi5         =       (alpha * rbi4 + ( 1 - alpha ) * rbi5[1] );;
rbi6         =       (alpha * rbi5 + ( 1 - alpha ) * rbi6[1] );;
rbi7         =       (alpha * rbi6 + ( 1 - alpha ) * rbi7[1] );;
rbi8         =       (alpha * rbi7 + ( 1 - alpha ) * rbi8[1] );;

case "TWO":
rbi1         =       (power( alpha, 2 )     * data    +
2 *      ( 1 - alpha )    * rbi1[1] -
power( 1 - alpha, 2 ) * rbi1[2] );;

rbi2         =       (power( alpha, 2 )     * rbi1    +
2 *      ( 1 - alpha )    * rbi2[1] -
power( 1 - alpha, 2 ) * rbi2[2] );;

rbi3         =       (power( alpha, 2 )     * rbi2    +
2 *      ( 1 - alpha )    * rbi3[1] -
power( 1 - alpha, 2 ) * rbi3[2] );;

rbi4         =       (power( alpha, 2 )     * rbi3    +
2 *      ( 1 - alpha )    * rbi4[1] -
power( 1 - alpha, 2 ) * rbi4[2] );;

rbi5         =       (power( alpha, 2 )     * rbi4    +
2 *      ( 1 - alpha )    * rbi5[1] -
power( 1 - alpha, 2 ) * rbi5[2] );;

rbi6         =       (power( alpha, 2 )     * rbi5    +
2 *      ( 1 - alpha )    * rbi6[1] -
power( 1 - alpha, 2 ) * rbi6[2] );;

rbi7         =       (power( alpha, 2 )     * rbi6    +
2 *      ( 1 - alpha )    * rbi7[1] -
power( 1 - alpha, 2 ) * rbi7[2] );;

rbi8         =       (power( alpha, 2 )     * rbi7    +
2 *      ( 1 - alpha )    * rbi8[1] -
power( 1 - alpha, 2 ) * rbi8[2] );;

case "THREE":
rbi1        =       power( alpha, 3 )     * data    +
3 *      ( 1 – alpha )    * rbi1[1] -
3 * power( 1 - alpha, 2 ) * rbi1[2] +
power( 1 - alpha, 3 ) * rbi1[3];;

rbi2        =       (power( alpha, 3 )     * rbi1    +
3 *      ( 1 – alpha )    * rbi2[1] -
3 * power( 1 - alpha, 2 ) * rbi2[2] +
power( 1 - alpha, 3 ) * rbi2[3] );;

rbi3        =       (power( alpha, 3 )     * rbi2    +
3 *      ( 1 – alpha )    * rbi3[1] -
3 * power( 1 - alpha, 2 ) * rbi3[2] +
power( 1 - alpha, 3 ) * rbi3[3] );;

rbi4        =       (power( alpha, 3 )     * rbi3    +
3 *      ( 1 – alpha )    * rbi4[1] -
3 * power( 1 - alpha, 2 ) * rbi4[2] +
power( 1 - alpha, 3 ) * rbi4[3] );;

rbi5        =       (power( alpha, 3 )     * rbi4    +
3 *      ( 1 – alpha )    * rbi5[1] -
3 * power( 1 - alpha, 2 ) * rbi5[2] +
power( 1 - alpha, 3 ) * rbi5[3] );;

rbi6        =       (power( alpha, 3 )     * rbi5    +
3 *      ( 1 – alpha )    * rbi6[1] -
3 * power( 1 - alpha, 2 ) * rbi6[2] +
power( 1 - alpha, 3 ) * rbi6[3] );;

rbi7        =       (power( alpha, 3 )     * rbi6    +
3 *      ( 1 – alpha )    * rbi7[1] -
3 * power( 1 - alpha, 2 ) * rbi7[2] +
power( 1 - alpha, 3 ) * rbi7[3] );;

rbi8        =      ( power( alpha, 3 )     * rbi7    +
3 *      ( 1 – alpha )    * rbi8[1] -
3 * power( 1 - alpha, 2 ) * rbi8[2] +
power( 1 - alpha, 3 ) * rbi8[3] );;

case "FOUR":
rbi1        =       (power( alpha, 4 )     * data    +
4 *      ( 1 – alpha )    * rbi1[1] –
6 * power( 1 - alpha, 2 ) * rbi1[2] +
4 * power( 1 - alpha, 3 ) * rbi1[3] -
power( 1 - alpha, 4 ) * rbi1[4] );;

rbi2        =       (power( alpha, 4 )     * rbi1    +
4 *      ( 1 – alpha )    * rbi2[1] –
6 * power( 1 - alpha, 2 ) * rbi2[2] +
4 * power( 1 - alpha, 3 ) * rbi2[3] -
power( 1 - alpha, 4 ) * rbi2[4] );;

rbi3        =       (power( alpha, 4 )     * rbi2    +
4 *      ( 1 – alpha )    * rbi3[1] –
6 * power( 1 - alpha, 2 ) * rbi3[2] +
4 * power( 1 - alpha, 3 ) * rbi3[3] -
power( 1 - alpha, 4 ) * rbi3[4] );;

rbi4        =       (power( alpha, 4 )     * rbi3    +
4 *      ( 1 – alpha )    * rbi4[1] –
6 * power( 1 - alpha, 2 ) * rbi4[2] +
4 * power( 1 - alpha, 3 ) * rbi4[3] -
power( 1 - alpha, 4 ) * rbi4[4] );;

rbi5        =       (power( alpha, 4 )     * rbi4    +
4 *      ( 1 – alpha )    * rbi5[1] –
6 * power( 1 - alpha, 2 ) * rbi5[2] +
4 * power( 1 - alpha, 3 ) * rbi5[3] -
power( 1 - alpha, 4 ) * rbi5[4] );;

rbi6        =       (power( alpha, 4 )     * rbi5    +
4 *      ( 1 – alpha )    * rbi6[1] –
6 * power( 1 - alpha, 2 ) * rbi6[2] +
4 * power( 1 - alpha, 3 ) * rbi6[3] -
power( 1 - alpha, 4 ) * rbi6[4] );;

rbi7        =       (power( alpha, 4 )     * rbi6    +
4 *      ( 1 – alpha )    * rbi7[1] –
6 * power( 1 - alpha, 2 ) * rbi7[2] +
4 * power( 1 - alpha, 3 ) * rbi7[3] -
power( 1 - alpha, 4 ) * rbi7[4] );;

rbi8        =       (power( alpha, 4 )     * rbi7    +
4 *      ( 1 – alpha )    * rbi8[1] –
6 * power( 1 - alpha, 2 ) * rbi8[2] +
4 * power( 1 - alpha, 3 ) * rbi8[3] -
power( 1 - alpha, 4 ) * rbi8[4] );;
}

# Plots
plot ga1             = rbi1[Displace];
plot ga2             = rbi2[Displace];
plot ga3             = rbi3[Displace];
plot ga4             = rbi4[Displace];
plot ga5             = rbi5[Displace];
plot ga6             = rbi6[Displace];
plot ga7             = rbi7[Displace];
plot ga8             = rbi8[Displace];

# Look and Feel
ga1.assignValueColor( color.MAGENTA );
ga2.assignValueColor( color.PLUM );
ga3.assignValueColor( color.BLUE );
ga4.assignValueColor( color.CYAN );
ga5.assignValueColor( color.GREEN );
ga6.assignValueColor( color.YELLOW );
ga7.assignValueColor( color.DARK_ORANGE );
ga8.assignValueColor( color.RED );

ga1.hideTitle();
ga2.hideTitle();
ga3.hideTitle();
ga4.hideTitle();
ga5.hideTitle();
ga6.hideTitle();
ga7.hideTitle();
ga8.hideTitle();

# Cloud Plots
addCloud( if cloud == yes then ga1 else double.NaN, ga8, color.RED, color.BLACK );
addCloud( if cloud == yes then ga1 else double.NaN, ga7, color.DARK_ORANGE, color.BLACK );
addCloud( if cloud == yes then ga1 else double.NaN, ga6, color.YELLOW, color.YELLOW );
addCloud( if cloud == yes then ga1 else double.NaN, ga5, color.GREEN, color.GREEN );
addCloud( if cloud == yes then ga1 else double.NaN, ga4, color.BLUE, color.BLUE );
addCloud( if cloud == yes then ga1 else double.NaN, ga3, color.PLUM, color.PLUM );
 
Could you share your settings that makes it leading?
The poster asked if there was a way to displace the averages.

I provided a way by displacing the plotted averages
IE:
# Plots
plot ga1 = rbi1[Displace];
plot ga2 = rbi2[Displace];
plot ga3 = rbi3[Displace];
plot ga4 = rbi4[Displace];
plot ga5 = rbi5[Displace];
plot ga6 = rbi6[Displace];
plot ga7 = rbi7[Displace];
plot ga8 = rbi8[Displace];

How you use this is up to you?

Moving them to the right, you can catch more of movement, move them to the left, you will run into a delay of data because it will need to wait until the next bar is formed before it will calculate a value
 
This is a question for BenTen, are the pink horizontal Lines, hand drawn support & resistance, or are they some sort of formulary?
 
The Gaussian Rainbow indicator is quite popular among Forex traders to help identify trends, retracements, and sideways market. Though, it's nothing special. Just a trend following indicator built from gaussian filtration.

You can use it for short-term, medium term and long term trading. I heard it makes a great companion for scalping along with a momentum indicator or oscillator. Similar to using a single or double MAs, when the stock is trading above the rainbow then we assume it's trading in an uptrend. When the candles are below the rainbow then it's bearish.

A few examples of what the Rainbow indicator looks like:

NkVXGoY.png

rJRides.png


thinkScript Code

Code:
# Gaussian Rainbow
# Eric R
# 11.24.2013

declare upper;

# Study Inputs
input gaussian       = { "ONE", "TWO", "THREE", default "FOUR" };
input data           = HL2;
input length         = 10;
input gaussianOrder  = 3;
input cloud          = yes;

# Definitions
def w;
def beta;
def alpha;

def rbi1; 
def rbi2; 
def rbi3; 
def rbi4;
def rbi5; 
def rbi6; 
def rbi7; 
def rbi8;

# Alpha Calculation
w                = ( 2 * double.Pi / length );
beta             = ( 1 - cos( w ) ) / ( power( 1.414, 2.0 / gaussianOrder ) - 1 );
alpha            = ( -beta + sqRt( beta * beta + 2 * beta) );

# Average Calculations
switch( gaussian ) {

case "ONE":
rbi1         =       alpha * data + ( 1 - alpha ) * rbi1[1];
rbi2         =       alpha * rbi1 + ( 1 - alpha ) * rbi2[1];
rbi3         =       alpha * rbi2 + ( 1 - alpha ) * rbi3[1];
rbi4         =       alpha * rbi3 + ( 1 - alpha ) * rbi4[1];
rbi5         =       alpha * rbi4 + ( 1 - alpha ) * rbi5[1];
rbi6         =       alpha * rbi5 + ( 1 - alpha ) * rbi6[1];
rbi7         =       alpha * rbi6 + ( 1 - alpha ) * rbi7[1];
rbi8         =       alpha * rbi7 + ( 1 - alpha ) * rbi8[1];

case "TWO":
rbi1         =       power( alpha, 2 )     * data    +
2 *      ( 1 - alpha )    * rbi1[1] -
power( 1 - alpha, 2 ) * rbi1[2];

rbi2         =       power( alpha, 2 )     * rbi1    +
2 *      ( 1 - alpha )    * rbi2[1] -
power( 1 - alpha, 2 ) * rbi2[2];

rbi3         =       power( alpha, 2 )     * rbi2    +
2 *      ( 1 - alpha )    * rbi3[1] -
power( 1 - alpha, 2 ) * rbi3[2];

rbi4         =       power( alpha, 2 )     * rbi3    +
2 *      ( 1 - alpha )    * rbi4[1] -
power( 1 - alpha, 2 ) * rbi4[2];

rbi5         =       power( alpha, 2 )     * rbi4    +
2 *      ( 1 - alpha )    * rbi5[1] -
power( 1 - alpha, 2 ) * rbi5[2];

rbi6         =       power( alpha, 2 )     * rbi5    +
2 *      ( 1 - alpha )    * rbi6[1] -
power( 1 - alpha, 2 ) * rbi6[2];

rbi7         =       power( alpha, 2 )     * rbi6    +
2 *      ( 1 - alpha )    * rbi7[1] -
power( 1 - alpha, 2 ) * rbi7[2];

rbi8         =       power( alpha, 2 )     * rbi7    +
2 *      ( 1 - alpha )    * rbi8[1] -
power( 1 - alpha, 2 ) * rbi8[2];

case "THREE":
rbi1        =       power( alpha, 3 )     * data    +
3 *      ( 1 – alpha )    * rbi1[1] -
3 * power( 1 - alpha, 2 ) * rbi1[2] +
power( 1 - alpha, 3 ) * rbi1[3];

rbi2        =       power( alpha, 3 )     * rbi1    +
3 *      ( 1 – alpha )    * rbi2[1] -
3 * power( 1 - alpha, 2 ) * rbi2[2] +
power( 1 - alpha, 3 ) * rbi2[3];

rbi3        =       power( alpha, 3 )     * rbi2    +
3 *      ( 1 – alpha )    * rbi3[1] -
3 * power( 1 - alpha, 2 ) * rbi3[2] +
power( 1 - alpha, 3 ) * rbi3[3];

rbi4        =       power( alpha, 3 )     * rbi3    +
3 *      ( 1 – alpha )    * rbi4[1] -
3 * power( 1 - alpha, 2 ) * rbi4[2] +
power( 1 - alpha, 3 ) * rbi4[3];

rbi5        =       power( alpha, 3 )     * rbi4    +
3 *      ( 1 – alpha )    * rbi5[1] -
3 * power( 1 - alpha, 2 ) * rbi5[2] +
power( 1 - alpha, 3 ) * rbi5[3];

rbi6        =       power( alpha, 3 )     * rbi5    +
3 *      ( 1 – alpha )    * rbi6[1] -
3 * power( 1 - alpha, 2 ) * rbi6[2] +
power( 1 - alpha, 3 ) * rbi6[3];

rbi7        =       power( alpha, 3 )     * rbi6    +
3 *      ( 1 – alpha )    * rbi7[1] -
3 * power( 1 - alpha, 2 ) * rbi7[2] +
power( 1 - alpha, 3 ) * rbi7[3];

rbi8        =       power( alpha, 3 )     * rbi7    +
3 *      ( 1 – alpha )    * rbi8[1] -
3 * power( 1 - alpha, 2 ) * rbi8[2] +
power( 1 - alpha, 3 ) * rbi8[3];

case "FOUR":
rbi1        =       power( alpha, 4 )     * data    +
4 *      ( 1 – alpha )    * rbi1[1] –
6 * power( 1 - alpha, 2 ) * rbi1[2] +
4 * power( 1 - alpha, 3 ) * rbi1[3] -
power( 1 - alpha, 4 ) * rbi1[4];

rbi2        =       power( alpha, 4 )     * rbi1    +
4 *      ( 1 – alpha )    * rbi2[1] –
6 * power( 1 - alpha, 2 ) * rbi2[2] +
4 * power( 1 - alpha, 3 ) * rbi2[3] -
power( 1 - alpha, 4 ) * rbi2[4];

rbi3        =       power( alpha, 4 )     * rbi2    +
4 *      ( 1 – alpha )    * rbi3[1] –
6 * power( 1 - alpha, 2 ) * rbi3[2] +
4 * power( 1 - alpha, 3 ) * rbi3[3] -
power( 1 - alpha, 4 ) * rbi3[4];

rbi4        =       power( alpha, 4 )     * rbi3    +
4 *      ( 1 – alpha )    * rbi4[1] –
6 * power( 1 - alpha, 2 ) * rbi4[2] +
4 * power( 1 - alpha, 3 ) * rbi4[3] -
power( 1 - alpha, 4 ) * rbi4[4];

rbi5        =       power( alpha, 4 )     * rbi4    +
4 *      ( 1 – alpha )    * rbi5[1] –
6 * power( 1 - alpha, 2 ) * rbi5[2] +
4 * power( 1 - alpha, 3 ) * rbi5[3] -
power( 1 - alpha, 4 ) * rbi5[4];

rbi6        =       power( alpha, 4 )     * rbi5    +
4 *      ( 1 – alpha )    * rbi6[1] –
6 * power( 1 - alpha, 2 ) * rbi6[2] +
4 * power( 1 - alpha, 3 ) * rbi6[3] -
power( 1 - alpha, 4 ) * rbi6[4];

rbi7        =       power( alpha, 4 )     * rbi6    +
4 *      ( 1 – alpha )    * rbi7[1] –
6 * power( 1 - alpha, 2 ) * rbi7[2] +
4 * power( 1 - alpha, 3 ) * rbi7[3] -
power( 1 - alpha, 4 ) * rbi7[4];

rbi8        =       power( alpha, 4 )     * rbi7    +
4 *      ( 1 – alpha )    * rbi8[1] –
6 * power( 1 - alpha, 2 ) * rbi8[2] +
4 * power( 1 - alpha, 3 ) * rbi8[3] -
power( 1 - alpha, 4 ) * rbi8[4];
}

# Plots
plot ga1             = rbi1;
plot ga2             = rbi2;
plot ga3             = rbi3;
plot ga4             = rbi4;
plot ga5             = rbi5;
plot ga6             = rbi6;
plot ga7             = rbi7;
plot ga8             = rbi8;

# Look and Feel
ga1.assignValueColor( color.MAGENTA );
ga2.assignValueColor( color.PLUM );
ga3.assignValueColor( color.BLUE );
ga4.assignValueColor( color.CYAN );
ga5.assignValueColor( color.GREEN );
ga6.assignValueColor( color.YELLOW );
ga7.assignValueColor( color.DARK_ORANGE );
ga8.assignValueColor( color.RED );

ga1.hideTitle();
ga2.hideTitle();
ga3.hideTitle();
ga4.hideTitle();
ga5.hideTitle();
ga6.hideTitle();
ga7.hideTitle();
ga8.hideTitle();

# Cloud Plots
addCloud( if cloud == yes then ga1 else double.NaN, ga8, color.RED, color.BLACK );
addCloud( if cloud == yes then ga1 else double.NaN, ga7, color.DARK_ORANGE, color.BLACK );
addCloud( if cloud == yes then ga1 else double.NaN, ga6, color.YELLOW, color.YELLOW );
addCloud( if cloud == yes then ga1 else double.NaN, ga5, color.GREEN, color.GREEN );
addCloud( if cloud == yes then ga1 else double.NaN, ga4, color.BLUE, color.BLUE );
addCloud( if cloud == yes then ga1 else double.NaN, ga3, color.PLUM, color.PLUM );

Shareable Link

https://tos.mx/GK5TrQ
can someone make the scan for up/down signal?
 
here is the displaced version
Code:
# Gaussian Rainbow
# Eric R
# 11.24.2013

declare upper;

# Study Inputs
input gaussian       = { "ONE", "TWO", "THREE", default "FOUR" };
input data           = HL2;
input length         = 10;
input Displace =1;
input gaussianOrder  = 3;
input cloud          = yes;

# Definitions
def w;
def beta;
def alpha;

def rbi1;
def rbi2;
def rbi3;
def rbi4;
def rbi5;
def rbi6;
def rbi7;
def rbi8;

# Alpha Calculation
w                = ( 2 * double.Pi / length );
beta             = ( 1 - cos( w ) ) / ( power( 1.414, 2.0 / gaussianOrder ) - 1 );
alpha            = ( -beta + sqRt( beta * beta + 2 * beta) );

# Average Calculations
switch( gaussian ) {

case "ONE":
rbi1         =       (alpha * data + ( 1 - alpha ) * rbi1[1]);
rbi2         =       (alpha * rbi1 + ( 1 - alpha ) * rbi2[1] );;
rbi3         =       (alpha * rbi2 + ( 1 - alpha ) * rbi3[1] );;
rbi4         =       (alpha * rbi3 + ( 1 - alpha ) * rbi4[1] );;
rbi5         =       (alpha * rbi4 + ( 1 - alpha ) * rbi5[1] );;
rbi6         =       (alpha * rbi5 + ( 1 - alpha ) * rbi6[1] );;
rbi7         =       (alpha * rbi6 + ( 1 - alpha ) * rbi7[1] );;
rbi8         =       (alpha * rbi7 + ( 1 - alpha ) * rbi8[1] );;

case "TWO":
rbi1         =       (power( alpha, 2 )     * data    +
2 *      ( 1 - alpha )    * rbi1[1] -
power( 1 - alpha, 2 ) * rbi1[2] );;

rbi2         =       (power( alpha, 2 )     * rbi1    +
2 *      ( 1 - alpha )    * rbi2[1] -
power( 1 - alpha, 2 ) * rbi2[2] );;

rbi3         =       (power( alpha, 2 )     * rbi2    +
2 *      ( 1 - alpha )    * rbi3[1] -
power( 1 - alpha, 2 ) * rbi3[2] );;

rbi4         =       (power( alpha, 2 )     * rbi3    +
2 *      ( 1 - alpha )    * rbi4[1] -
power( 1 - alpha, 2 ) * rbi4[2] );;

rbi5         =       (power( alpha, 2 )     * rbi4    +
2 *      ( 1 - alpha )    * rbi5[1] -
power( 1 - alpha, 2 ) * rbi5[2] );;

rbi6         =       (power( alpha, 2 )     * rbi5    +
2 *      ( 1 - alpha )    * rbi6[1] -
power( 1 - alpha, 2 ) * rbi6[2] );;

rbi7         =       (power( alpha, 2 )     * rbi6    +
2 *      ( 1 - alpha )    * rbi7[1] -
power( 1 - alpha, 2 ) * rbi7[2] );;

rbi8         =       (power( alpha, 2 )     * rbi7    +
2 *      ( 1 - alpha )    * rbi8[1] -
power( 1 - alpha, 2 ) * rbi8[2] );;

case "THREE":
rbi1        =       power( alpha, 3 )     * data    +
3 *      ( 1 – alpha )    * rbi1[1] -
3 * power( 1 - alpha, 2 ) * rbi1[2] +
power( 1 - alpha, 3 ) * rbi1[3];;

rbi2        =       (power( alpha, 3 )     * rbi1    +
3 *      ( 1 – alpha )    * rbi2[1] -
3 * power( 1 - alpha, 2 ) * rbi2[2] +
power( 1 - alpha, 3 ) * rbi2[3] );;

rbi3        =       (power( alpha, 3 )     * rbi2    +
3 *      ( 1 – alpha )    * rbi3[1] -
3 * power( 1 - alpha, 2 ) * rbi3[2] +
power( 1 - alpha, 3 ) * rbi3[3] );;

rbi4        =       (power( alpha, 3 )     * rbi3    +
3 *      ( 1 – alpha )    * rbi4[1] -
3 * power( 1 - alpha, 2 ) * rbi4[2] +
power( 1 - alpha, 3 ) * rbi4[3] );;

rbi5        =       (power( alpha, 3 )     * rbi4    +
3 *      ( 1 – alpha )    * rbi5[1] -
3 * power( 1 - alpha, 2 ) * rbi5[2] +
power( 1 - alpha, 3 ) * rbi5[3] );;

rbi6        =       (power( alpha, 3 )     * rbi5    +
3 *      ( 1 – alpha )    * rbi6[1] -
3 * power( 1 - alpha, 2 ) * rbi6[2] +
power( 1 - alpha, 3 ) * rbi6[3] );;

rbi7        =       (power( alpha, 3 )     * rbi6    +
3 *      ( 1 – alpha )    * rbi7[1] -
3 * power( 1 - alpha, 2 ) * rbi7[2] +
power( 1 - alpha, 3 ) * rbi7[3] );;

rbi8        =      ( power( alpha, 3 )     * rbi7    +
3 *      ( 1 – alpha )    * rbi8[1] -
3 * power( 1 - alpha, 2 ) * rbi8[2] +
power( 1 - alpha, 3 ) * rbi8[3] );;

case "FOUR":
rbi1        =       (power( alpha, 4 )     * data    +
4 *      ( 1 – alpha )    * rbi1[1] –
6 * power( 1 - alpha, 2 ) * rbi1[2] +
4 * power( 1 - alpha, 3 ) * rbi1[3] -
power( 1 - alpha, 4 ) * rbi1[4] );;

rbi2        =       (power( alpha, 4 )     * rbi1    +
4 *      ( 1 – alpha )    * rbi2[1] –
6 * power( 1 - alpha, 2 ) * rbi2[2] +
4 * power( 1 - alpha, 3 ) * rbi2[3] -
power( 1 - alpha, 4 ) * rbi2[4] );;

rbi3        =       (power( alpha, 4 )     * rbi2    +
4 *      ( 1 – alpha )    * rbi3[1] –
6 * power( 1 - alpha, 2 ) * rbi3[2] +
4 * power( 1 - alpha, 3 ) * rbi3[3] -
power( 1 - alpha, 4 ) * rbi3[4] );;

rbi4        =       (power( alpha, 4 )     * rbi3    +
4 *      ( 1 – alpha )    * rbi4[1] –
6 * power( 1 - alpha, 2 ) * rbi4[2] +
4 * power( 1 - alpha, 3 ) * rbi4[3] -
power( 1 - alpha, 4 ) * rbi4[4] );;

rbi5        =       (power( alpha, 4 )     * rbi4    +
4 *      ( 1 – alpha )    * rbi5[1] –
6 * power( 1 - alpha, 2 ) * rbi5[2] +
4 * power( 1 - alpha, 3 ) * rbi5[3] -
power( 1 - alpha, 4 ) * rbi5[4] );;

rbi6        =       (power( alpha, 4 )     * rbi5    +
4 *      ( 1 – alpha )    * rbi6[1] –
6 * power( 1 - alpha, 2 ) * rbi6[2] +
4 * power( 1 - alpha, 3 ) * rbi6[3] -
power( 1 - alpha, 4 ) * rbi6[4] );;

rbi7        =       (power( alpha, 4 )     * rbi6    +
4 *      ( 1 – alpha )    * rbi7[1] –
6 * power( 1 - alpha, 2 ) * rbi7[2] +
4 * power( 1 - alpha, 3 ) * rbi7[3] -
power( 1 - alpha, 4 ) * rbi7[4] );;

rbi8        =       (power( alpha, 4 )     * rbi7    +
4 *      ( 1 – alpha )    * rbi8[1] –
6 * power( 1 - alpha, 2 ) * rbi8[2] +
4 * power( 1 - alpha, 3 ) * rbi8[3] -
power( 1 - alpha, 4 ) * rbi8[4] );;
}

# Plots
plot ga1             = rbi1[Displace];
plot ga2             = rbi2[Displace];
plot ga3             = rbi3[Displace];
plot ga4             = rbi4[Displace];
plot ga5             = rbi5[Displace];
plot ga6             = rbi6[Displace];
plot ga7             = rbi7[Displace];
plot ga8             = rbi8[Displace];

# Look and Feel
ga1.assignValueColor( color.MAGENTA );
ga2.assignValueColor( color.PLUM );
ga3.assignValueColor( color.BLUE );
ga4.assignValueColor( color.CYAN );
ga5.assignValueColor( color.GREEN );
ga6.assignValueColor( color.YELLOW );
ga7.assignValueColor( color.DARK_ORANGE );
ga8.assignValueColor( color.RED );

ga1.hideTitle();
ga2.hideTitle();
ga3.hideTitle();
ga4.hideTitle();
ga5.hideTitle();
ga6.hideTitle();
ga7.hideTitle();
ga8.hideTitle();

# Cloud Plots
addCloud( if cloud == yes then ga1 else double.NaN, ga8, color.RED, color.BLACK );
addCloud( if cloud == yes then ga1 else double.NaN, ga7, color.DARK_ORANGE, color.BLACK );
addCloud( if cloud == yes then ga1 else double.NaN, ga6, color.YELLOW, color.YELLOW );
addCloud( if cloud == yes then ga1 else double.NaN, ga5, color.GREEN, color.GREEN );
addCloud( if cloud == yes then ga1 else double.NaN, ga4, color.BLUE, color.BLUE );
addCloud( if cloud == yes then ga1 else double.NaN, ga3, color.PLUM, color.PLUM );
sorry to say I added the code its not Displaced
what do i do to displace the moving averages i plugged in the new code, but its still the same as before, am i to put a number at the {displace}? if so where i dont code i want to use this thing but as an EMA
 
Last edited by a moderator:
sorry to say I added the code its not Displaced
what do i do to displace the moving averages i plugged in the new code, but its still the same as before, am i to put a number at the {displace}? if so where i dont code i want to use this thing but as an EMA
It is displaced by 1 bar! to adjust the inputs /click on the beaker/ click on the gear/the inputs will appear/ scroll down to where displace appears and make your choice/ then click ok and apply. As for the EMA part of your question, This indicator is not coded for regular types of moving averages.

Please read the code! Your choice is to use 1 alpha, 2 alpha's, 3 alpha's, or 4 alpha's
 
The rainbow indicator shows just how much lag there is in using Moving Averages. By using a displaced Ma "Positive Numbers", you move the rainbow to the right. By using "Negative Numbers" you move the Rainbow to the left. Be forewarned that this practice also does not plot on the most recent bar or bars that you displace to the left!
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
293 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top