Combined TMO and Gaussian Rainbow. I'm obsessed with TMO.
Code:
# TMO ((T)rue (M)omentum (O)scilator)
# Mobius
# V01.05.2018
# hint: TMO calculates momentum using the delta of price. Giving a much better picture of trend, tend reversals and divergence than momentum oscillators using price.
# Fluideng:9/3/22 Combined TMO Gaussian Rainbow.
declare lower;
input length = 14;
input calcLength = 5;
input smoothLength = 3;
def o = open;
def c = close;
input gaussian = { "ONE", "TWO", "THREE", default "FOUR" };
def data = fold i = 0 to length
with s
do s + (if c > getValue(o, i)
then 1
else if c < getValue(o, i)
then - 1
else 0);
plot zero = if isNaN(c) then double.nan else 0;
zero.SetDefaultColor(Color.gray);
zero.hideBubble();
zero.hideTitle();
plot ob = if isNaN(c) then double.nan else round(length * .7);
ob.SetDefaultColor(Color.gray);
ob.HideBubble();
ob.HideTitle();
plot os = if isNaN(c) then double.nan else -round(length * .7);
os.SetDefaultColor(Color.gray);
os.HideBubble();
os.HideTitle();
addCloud(ob, length, color.light_red, color.light_red, no);
addCloud(-length, os, color.light_green, color.light_green);
# End Code TMO
#input length = 10;
input Displace = 0;
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.RED );
addCloud( if cloud == yes then ga1 else double.NaN, ga7, color.DARK_ORANGE, color.DARK_ORANGE );
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 );
addCloud( if cloud == yes then ga1 else double.NaN, ga2, color.MAGENTA, color.MAGENTA );
#bar color
def Long1 = ga1 > ga2 and ga1 > ga3 and ga1 > ga4 and ga1 > ga5 and ga1 > ga6 and ga1 > ga7 and ga1 > ga8;# and OPEN >= AvgExp;
def Long = long1;
def SHORT1 = ga1 < ga2 and ga1 < ga3 and ga1 < ga4 and ga1 < ga5 and ga1 < ga6 and ga1 < ga7 and ga1 < ga8;# and OPEN <= AvgExp;
def Short = short1;
def notSorL = ga1 > ga2 and ga1 < ga2;
### Bar Color
input PaintBars = yes;
AssignPriceColor(if PaintBars and SHORT then Color.RED else if PaintBars and LONG then Color.GREEN else if paintbars then Color.white else Color.CURRENT);