Moving Average Crossover Watchlist Column for ThinkorSwim

@scottrades If you want to get alerted for new crossovers, all you have to do is create a scanner for your particular crossover condition in the Scanner tab and use this option.

Ut477FT.png


Don't forget to select the timeframe of your choosing. By default, all new scanner will be set to the Daily chart. Note that this method does not prevent ToS from sending delayed alerts. You may see a 3-5 mins delay here and there.
 
Thank you for this contribution.

I prefer simple ma so I changed all of the ema to sma and EXPONENTIAL to SIMPLE. Can you please tell what is wrong here?

Code:
# WalkingBallista SMA Lookback Cross
# https://usethinkscript.com/d/119-moving-average-crossover-watchlist-column-for-thinkorswim

declare lower;

input lookback = 2;
input sma1_len = 5;
input sma2_len = 200;
input averageType = AverageType.SIMPLE;

def sma1 = MovAvgSIMPLE(length=sma1_len);
def sma2 = MovAvgSIMPLE(length=sma2_len);

def bull_cross = sma1 crosses above sma2;
def bear_cross = sma1 crosses below sma2;

def bull_lookback = highest(bull_cross, lookback);
def bear_lookback = highest(bear_cross, lookback);

plot signal = if bull_lookback then 2 else if bear_lookback then 1 else 0;
signal.AssignValueColor(if signal == 2 then Color.Dark_Green else if signal == 1 then Color.Dark_Red else Color.Dark_Orange);
AssignBackgroundCOlor(if signal == 2 then Color.Dark_Green else if signal == 1 then Color.Dark_Red else Color.Dark_Orange);

THANK YOU,
Doug
How may I change this to SIMPLE MA. When highlighting 'AverageType.EXPONENTIAL', the Inspector does not give any choices. I know to change EXPONENTIAL to SIMPLE, but what about the 'ema1_len' inputs?
 
Last edited by a moderator:
Hey @dougn It's been a while, welcome back! Please tell us exactly what you feel you should see and post a picture of what's going on. BTW, there are new relative strength metrics on the IBD page. I didn't care for what I had first created.

Be sure you are putting the above in a custom column by clicking on the little gear at the far right of your watchlist. The above is not a strategy OR a study but goes in the watchlist. The main watchlist, not the little square one on the left. @scottrades , does that help?
 
Hi Markos ... yes the watchlist columns for the EMA crossovers are working fine (Orange, Green, and Red). I was just trying to switch to SMA instead of EMA and the script does not like what I have put in to change. Something to do with the "SIMPLE" but I've tried other variations and just can't get the right combination.
 
@dougn 3 things, if these don't work,come back & someone else will have to work with it: Try full spelling, or try a period if needed.
MovingAverageSimple
MovingAvererage.Simple or
SimpleMovingAverage (dunno, but doubt this one, give it a go if needed)
 
Last edited:
Thank markos you but no luck. Thanks for the suggestions.

If anyone else can take a look I would appreciate it. Thanks
 
Got it ...

Code:
# WalkingBallista SMA Lookback Cross

declare lower;

input lookback = 2;

input sma1_len = 5;

input sma2_len = 200;

input averageType = AverageType.SIMPLE;

def sma1 = reference simplemovingavg(length = sma1_len);

def sma2 = reference simplemovingavg(length = sma2_len);

def bull_cross = sma1 crosses above sma2;

def bear_cross = sma1 crosses below sma2;

def bull_lookback = Highest(bull_cross, lookback);

def bear_lookback = Highest(bear_cross, lookback);

plot signal = if bull_lookback then 2 else if bear_lookback then 1 else 0;

signal.AssignValueColor(if signal == 2 then Color.DARK_GREEN else if signal == 1 then Color.DARK_RED else Color.DARK_ORANGE);

AssignBackgroundColor(if signal == 2 then Color.DARK_GREEN else if signal == 1 then Color.DARK_RED else Color.DARK_ORANGE);
 
Last edited by a moderator:
Folks, changing the moving average type is not so complicated. The following code fragment uses SMA. If you wish to change that to an EMA, just go into the user interface and change the input selector "averageType" to one of the choices offered there.

Code:
input averageType = AverageType.SIMPLE;
plot MovAvg = MovingAverage(averageType, Fundamental(price, period = aggregationPeriod), length);
 
@tomsk I'm only here for the easy stuff. I don't multitask like you. If you don't mind, ask Paris to stop in and see what this young fella is building here.
Anything different happening in your time zone this New Years?
 
It's possible I have the terminology for aggregation wrong, e.g. if I set aggregation to D would I not be scanning for all instances over the past day?
If you have D selected, it would be for how many days are called for at the Input.
input sma1_len = 5; would be for 5 days, If 5 min is selected it would be a 25 minute sma length. Hope that helps.
 
@tomsk I'm only here for the easy stuff. I don't multitask like you. If you don't mind, ask Paris to stop in and see what this young fella is building here.
Anything different happening in your time zone this New Years?

@markos You're much too kind. As a matter of fact I will be meeting Paris in Vladivostok over the New Year and will indeed mention to him my experiences here. Think he is still tied up with some of his mid term projects though. I wasn't aware of Ben's adventures until he shared that little tidbit from you recently. Have a great new year celebration ahead!
 
Funny ... but it is hard to admit that I simply cannot combine these characters to get the desired result even though the answers are provided here in plain English.

This simple script is not changing to SMA regardless of the variations I throw at it. Please help again.

declare upper;
input price = close;
input displace = 0;

input EMALength1 = 9;
input EMALength2 = 20;

plot upper = ExpAverage(data = price[-displace], length = EMALength1);
upper.SetDefaultColor(Color.RED);
plot lower = ExpAverage(data = price[-displace], length = EMALength2);
lower.SetDefaultColor(Color.BLUE);
AddCloud(upper,lower);

Thank you,
Doug
 
Funny ... but it is hard to admit that I simply cannot combine these characters to get the desired result even though the answers are provided here in plain English.

This simple script is not changing to SMA regardless of the variations I throw at it. Please help again.

declare upper;
input price = close;
input displace = 0;

input EMALength1 = 9;
input EMALength2 = 20;

plot upper = ExpAverage(data = price[-displace], length = EMALength1);
upper.SetDefaultColor(Color.RED);
plot lower = ExpAverage(data = price[-displace], length = EMALength2);
lower.SetDefaultColor(Color.BLUE);
AddCloud(upper,lower);

Thank you,
Doug


@dougn Since you're still stuck I MODIFIED your code to a generic moving average type so that it can be selected to SIMPLE, EXPONENTIAL, WILDERS, HULL etc via the user interface. I have made it so that SIMPLE moving average has been selected. Your earlier code used the call ExpAverage() which is to calculate Exponential Moving Average and so won't work for a Simple Moving Average.

Compare this code with your earlier code, so that you can use this as a learning opportunity. You were also missing a few parameters in your AddCloud() statement - that was also fixed

Code:
# Moving Average Dual
# tomsk
# 1.2.2020

input price = close;

input averageType = AverageType.SIMPLE;
input displace = 0;
input Length1 = 9;
input Length2 = 20;

plot fast = MovingAverage(averageType, price[-displace], length1);
fast.SetDefaultColor(Color.RED);

plot slow = MovingAverage(averageType, price[-displace], length2);
slow.SetDefaultColor(Color.BLUE);

AddCloud(fast,slow, color.green, color.red);
# End Moving Average Dual
 
You're very welcome, it's a very simple starter script for those wishing to learn/dabble in ThinkScript
 
Hey. I was seeing if there was any way to build a custom watchlist column of a 9ema and 26 ema line..to where when 9 crosses over 26...the column turns green and vice versa on the one minute aggregation period. thanks!!
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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