Disappearing Moving Average for ThinkorSwim

Gymini

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] and close[10] < ema1[10] and...
@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);
 

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

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

as none of the tos codes have 17 lines, i'm going to assume you tried to load the code from post #1, which is for tradingview, not thinkscript.

here are some steps to help with your issue.
.... slow down and read all of a post slowly. Although this is a thinkscript forum, people post other codes and ask for them to be converted.
post 1 includes code for trading view, not thinkscript.
' Original Source Code By Trading Rush (for TradingView) starts below this line:'

Code created for one application won't run in another usually. It has to be converted.

try the code from post2 or post3.

.... when asking questions, please form complete sentences and mention the post number or add a link to it.

getting a link to a post.
Each post has a number in the top right corner. If you click on that number, the Web address will update and the page will reload with that post at the top. This updated link can be used to take you right to that post
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
232 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