Moving Average Crossover Watchlist Column for ThinkorSwim

S

scottrades

New member
I have the following on several timeframes in my Watchlist.
Once created/added to my 'Studies', it is not available to select as a column. I notice that none of my custom scripts are available to me in the list of studies.

Edit: I figured this one out. For others benefit...you need to add the script code via Custom Quotes/Custom 1, etc.
To get the scan to run automatically (every 3 minutes approx) save the watchlist as a scan, found in menu on upper right.
Further info is in the Education Tab in ThinkorSwim.
From the Menu in my Watchlist, I do not have the option to save the watchlist as a scan. There's only an option to 'Create scan query'.
 
Last edited:
S

scottrades

New member
On a 2 minute aggregation I was unable to obtain any results on the S&P 500 so you may have to vary your scan parameters
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?
 
markos

markos

Well-known member
VIP
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?
Have you had your free tour? Write down 5-10 questions that you want an answer to and during the tour you can ask them.
Otherwise, all questions can be answered in the TOS manual or in our Tutorial sections.
 
S

scottrades

New member
Have you had your free tour? Write down 5-10 questions that you want an answer to and during the tour you can ask them.
Otherwise, all questions can be answered in the TOS manual or in our Tutorial sections.
The TOS manual nor TOS Education have a definition of aggregation. The 'Manual' actually says nothing about aggregation and TOS Education states... "Aggregation period constants define a specific aggregation period for your studies and strategies. The period length varies from one minute to option expiration". I have read several of our Tutorials, such as 'How to use the TOS Scanner', which are all great, but there was no definition. in the tutorial I cited, it indicates to set the aggregation period, but does not actually tell me how that affects the scanner. I'm just speculating here, but maybe a yes or no to my question would suffice. Thanks.
 
BenTen

BenTen

Administrative
Staff
VIP
@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.



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.
 
S

scottrades

New member
@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.
Got it, thank you.
 
S

scottrades

New member
@Dixon72 and @scottrades I have the following on several timeframes in my Watchlist.
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?
 
dougn

dougn

Member
2019 Donor
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:
markos

markos

Well-known member
VIP
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?
 
dougn

dougn

Member
2019 Donor
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.
 
markos

markos

Well-known member
VIP
@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:
dougn

dougn

Member
2019 Donor
Thank markos you but no luck. Thanks for the suggestions.

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

dougn

Member
2019 Donor
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:
T

tomsk

Well-known member
VIP
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);
 
markos

markos

Well-known member
VIP
@tomsk Shucks Tom, that would be too easy. (duh, i never thought of it) 🤣 Pass the sake, I need another drink!!
 
T

tomsk

Well-known member
VIP
@markos Nothing to it, after a while it's all routine. Best to you
 
markos

markos

Well-known member
VIP
@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

markos

Well-known member
VIP
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.
 
T

tomsk

Well-known member
VIP
@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!
 
dougn

dougn

Member
2019 Donor
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
 

Top