Moving Average Crossover Watchlist Column for ThinkorSwim

M

mkalavitz

New member
Hi Ben,
Looking at the attached image, you can see that I (in the last 15 minutes) received a green cross over signal for SNAP and SHAK and a red cross over for NFLX. Do you know why the SNAP and NFLX signals came in late, while the SHAK came in great? I have lookback set at 1 for an hourly chart cross over.



thx
Mike
 
D

Dman

New member
This became a study not a watchlist, how to add to watchlist? thanks
 
Last edited:
BenTen

BenTen

Administrative
Staff
VIP
@Dman There should be an option called Custom Quotes under your list of watchlist items. Select one of the custom quotes and paste the code in there.
 
J007RMC

J007RMC

Active member
2019 Donor
Warehouse
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.
 
D

Dixon72

New member
Warehouse
@BenTen Is a lookback necessary? Is it possible to just get the status of the latest crossover? Thanks.
 
markos

markos

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

Dixon72

New member
Warehouse
@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.
 
S

samiranadhikari

Member
Is it possible to display additional parameter like crossing 'how many bars ago' in the green or red box
 
T

tomsk

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

Dixon72

New member
Warehouse
@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.
 
S

scottrades

New member
@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?
 
S

scottrades

New member
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?
 
T

tomsk

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

markos

Well-known member
VIP
@scottrades if you don't see this add code symbol, use the report button and Ben will find out why it's not showing.
 
markos

markos

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

Top