Moving Average Crossover Watchlist Column for ThinkorSwim

Very nice ty. I added the 9/20 ma watch list also using the hull watchlist and it seems to be a good match especially with 80 liquid stocks.
 

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

@BenTen Is a lookback necessary? Is it possible to just get the status of the latest crossover? Thanks.
@Dixon72 Sure, just go into the settings and change the lookback period. If your question is has it crossed in the last 30 days, then the lookback would be changed to 30. Hope that helps.
 
@markos I bumped the lookback WAY up on the daily, 4hr, 1hr and 15min (like to 100), thinking the watchlists would just update as the crossovers happened, but that doesn't appear to be the case. Instead, it displays the first crossover since the lookback and doesn't update any crossovers since. Any ideas, or am I asking more than the script, or ToS, is capable of? Thanks.
 
@samiranadhikari It is indeed possible to calculate how many bars ago the crossover happened. We can either have a CROSSUP or a CROSSDOWN situation. However since a single watchlist column can only plot a single piece of data, you can't display bars ago that the cross happened for BOTH a CROSSUP and a CROSSDOWN. In order to display both sets of data you would then have to use two watchlist columns to implement this thus taking up valuable real estate space on an already compressed watchlist (such as mine)
 
@BenTen When I change it to 1 or 2, then everything that hasn't had a crossover since the last 1 or 2 days is orange. Would be nice to have a watchlist that reports the current MA status regardless of the lookback. This way the higher timeframes are green (for example) and you're just waiting for the lower timeframes to agree with it for entry.
 
@Rojo Grande You can create a scanner and add it to your watchlist.
How do I get a scan to automatically run? I can only seem to get scans to run manually. Second, how would I tie a scan into an existing watchlist in order to create alert that sends me a notification, like the default price alerts available on the chart?
 
I'm attempting to adapt the EMA code to SMA of 20 crossing 200 on a 2 min chart. Below is what I have. I simply changed ema to sma, etc. Should this code work? BTW, how do I properly add code to posts herein?
 
Here is the simplest form of SMA(20) crosses above SMA(200) scan. Place this directly in the scanner and select the aggregation period you're interested in from the drop down menu. 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

Code:
Average(close, 20) crosses above Average(close, 200)
 
@scottrades if you don't see this add code symbol, use the report button and Ben will find out why it's not showing.
Q9qlHbK.png
 
@BenTen When I change it to 1 or 2, then everything that hasn't had a crossover since the last 1 or 2 days is orange. Would be nice to have a watchlist that reports the current MA status regardless of the lookback. This way the higher timeframes are green (for example) and you're just waiting for the lower timeframes to agree with it for entry.
@Dixon72 and @scottrades I have the following on several timeframes in my Watchlist.
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.

Code:
#HINT: This is a custom watchlist column looking for xx% percent above or below moving average line. \n It provides a visual alert with the percent from MA line where you expect price to revert to the mean by reversing to return to the MA line.

## because this is a watchlist column there is no Edit box.  therefore def could have been used instead of input.  To change type of price and/or type of moving average, click on the word "Inspector" top right of this box and click on the word close or the word AverageType.SIMPLE and the Inspector will show you your other choices.
input price = close;
input length = 20;
input Average_Type = AverageType.SIMPLE;
input percent_from_MA = 1;


## these def or "define a new word to ThinkScript" did not have to be used, but it saved a lot of time and typing later in the code by providing ability to use the new "words" instead of typing the math formula multiple times in different lines later in the code
def Avg = MovingAverage(average_Type, price, length);
def MA_below_price = price > Avg;
def MA_above_price = price < Avg;
def percent_away = if MA_below_price or MA_above_price then (close / avg) - 1 else 0;

def oversold = percent_away * 100 <= percent_from_MA * (-1);
def overbought = percent_away * 100 >= (Percent_from_MA);

### AddLabel needs (1) condition to trigger it to be visible or the word yes if always visible, (2) text to appear in quotes + data to appear in the label, (3) color for the label which can be static color or can be dynamic using if __ then __ else ___
AddLabel(yes, if oversold then " below " + AsPercent(percent_away) else if overbought then " above " + AsPercent(percent_away) else AsPercent(percent_away), color.BLACK);
AssignBackgroundColor(if oversold then color.DARK_ORANGE else if overbought then color.GREEN else color.LIGHT_GRAY);

# end code ------------------
 
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:
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?
 
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.
 
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.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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