Disappearing Moving Average for ThinkorSwim

Gymini

New member
The guy from Trading Rush just made his own moving average that disappears in a range market to cut out false signals: Source code of the "Trading Rush Moving Average" (the one that disappears in range markets) that was tested 100 Times in the latest Trading Rush video:

Just wanted to share in case someone wanted to convert to thinkscript:

Original Source Code By Trading Rush (for TradingView) starts below this line:

Code:
//Created by Trading Rush

// © Trading Rush

//@version=4

study(title="Trading Rush Moving Average", shorttitle="TR EMA", overlay=true, resolution="")

len = 200

src = close

ema1 = ema(src, len)

maColor = if(close[5] > ema1[5] and close[10] > ema1[10] and close[15] > ema1[15] and close[20] > ema1[20] and close[30] > ema1[30] and close[40] > ema1[40] and close[50] > ema1[50] and close > ema1)

    [URL='http://color.green/']color.green[/URL]

else if(close[5] < ema1[5] and close[10] < ema1[10] and close[15] < ema1[15] and close[20] < ema1[20] and close[30] < ema1[30] and close[40] < ema1[40] and close[50] < ema1[50] and close < ema1)

    [URL='http://color.red/']color.red[/URL]

else

    [URL='https://color.new/']color.new[/URL](color.white, 100)



plot(ema1, title="TR EMA", color=maColor, linewidth=4)
 
Solution
I don't necessarily agree with definitions of 'green' or 'red' in this indicator. However, we all are always looking for ways to have cleaner charts so providing the logic behind 'disappearing' lines has some educational value.
CIxN44G.png

Ruby:
# Trading Rush Moving Average TR EMA
# Created by Trading Rush version4

DefineGlobalColor("NoColor", CreateColor(221, 221, 221)) ;
input len = 200 ;
input src = close ;
plot ema1 = ExpAverage(src, len);

ema1.assignValueColor(
         if (close[5] > ema1[5] and close[10] > ema1[10] and close[15] > ema1[15] and close[20] > ema1[20] and close[30] > ema1[30] and close[40] > ema1[40] and close[50] > ema1[50] and close > ema1) then color.green

    else if (close[5] < ema1[5]...

Pensar

Well-known member
VIP
@Gymini Here is a very rough draft I quickly tossed together. There's nothing magic about this indicator (or any other indicator for that matter) but you can look at it and make your own decision. Its simply a 200 period moving average that sometimes does'nt plot on the chart.

Code:
def avg = expaverage(close,200);
def up = (close[5] > avg[5] and close[10] > avg[10] and close[15] > avg[15] and close[20] > avg[20] and close[30] > avg[30] and close[40] > avg[40] and close[50] > avg[50] and close > avg);
def dn = (close[5] < avg[5] and close[10] < avg[10] and close[15] < avg[15] and close[20] < avg[20] and close[30] < avg[30] and close[40] < avg[40] and close[50] < avg[50] and close < avg);

plot ema = if up or dn then avg else double.nan;
ema.assignvaluecolor(if up then color.green else color.red);
 

MerryDay

Administrative
Staff member
Staff
VIP
I don't necessarily agree with definitions of 'green' or 'red' in this indicator. However, we all are always looking for ways to have cleaner charts so providing the logic behind 'disappearing' lines has some educational value.
CIxN44G.png

Ruby:
# Trading Rush Moving Average TR EMA
# Created by Trading Rush version4

DefineGlobalColor("NoColor", CreateColor(221, 221, 221)) ;
input len = 200 ;
input src = close ;
plot ema1 = ExpAverage(src, len);

ema1.assignValueColor(
         if (close[5] > ema1[5] and close[10] > ema1[10] and close[15] > ema1[15] and close[20] > ema1[20] and close[30] > ema1[30] and close[40] > ema1[40] and close[50] > ema1[50] and close > ema1) then color.green

    else if (close[5] < ema1[5] and close[10] < ema1[10] and close[15] < ema1[15] and close[20] < ema1[20] and close[30] < ema1[30] and close[40] < ema1[40] and close[50] < ema1[50] and close < ema1) then color.red else GlobalColor("NoColor"));

ema1.SetLineWeight(2);
This is a little bit of a case of smoke and mirrors. The moving average line does not actually 'disappear'. The RGB line color is set to be equal to the background color of the chart.

To find out the RGB values of your chart background:
  1. Click on Settings
  2. Click on Appearance
  3. Click on Background
  4. Click on More
  5. Click on RGB
Write down the first 3 numbers. Change the Global Color "No Color" settings to equal those numbers.
v1Ufm5w.png

HTH
 
Solution

Similar threads

Top