Moving Average Crossover Watchlist Column for ThinkorSwim

BenTen

BenTen

Administrative
Staff
VIP
Warehouse
If anyone uses EMA crossover as a way to identify trend or point of entry/exit, knowing when there is a moving average crossover on your watchlist column can certainly be helpful. Here is a quick snippet that let you do just that.

It includes lookback period so that you can set to X amount of when there is an EMA (exponential moving average) crossover. For example, the default is 5. The column will turn green when there is a bullish crossover within the last 5 bars and vice versa. Orange for neutral.



thinkScript Code

Rich (BB code):
# WalkingBallista EMA Lookback Cross
# https://usethinkscript.com/d/119-moving-average-crossover-watchlist-column-for-thinkorswim

declare lower;

input lookback = 5;
input ema1_len = 10;
input ema2_len = 20;
input averageType = AverageType.EXPONENTIAL;

def ema1 = MovAvgExponential(length=ema1_len);
def ema2 = MovAvgExponential(length=ema2_len);

def bull_cross = ema1 crosses above ema2;
def bear_cross = ema1 crosses below ema2;

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);
The default values for EMAs are 10 and 20. You can change the input to whichever EMA you use on your chart.
 
Last edited:
markos

markos

Well-known member
VIP
Warehouse
@BenTen Now, that is an efficient way of using a watchlist...just scroll!

 
Last edited:
J

jan_angel

New member
VIP
Hi BenTen. This is a great script. How do i customize it to use it for daytrading? I added to my WL, but it is working for a daily timeframe. I would like to watch if there is a MA cross over at 5 minute interval.

Thanks again,

J

 
Last edited:
BenTen

BenTen

Administrative
Staff
VIP
Warehouse
@jan_angel When adding the script to your watchlist, you should be able to select to the timeframe of your liking. Daily is by default.



 
Last edited:
J

jan_angel

New member
VIP
Thank you! that did the trick. Appreciate the quick response.

 
Last edited:
J

jan_angel

New member
VIP
Hi BenTen - i have been using your MA crossover script all this week...and it worked great. However, for some reason, today all day it kept on saying 'loading' in the WL column. Do you have any ideas why? I thought it was TOS issue, but the helpdesk guy was totally helpless. Any info that you can provide will be great. I love this script.

 
Last edited:
BenTen

BenTen

Administrative
Staff
VIP
Warehouse
@jan_angel Hey, I had the same problem for other indicators that I include in the watchlist columns too. It's totally ToS issue. Nothing we can do here ☹

 
Last edited:
J

jan_angel

New member
VIP
Good to know! and thank you again for the super fast reply.

 
Last edited:
M

mkalavitz

New member
Hi Ben,

Thanks for sharing this! I was hunting around on the web today and was led your post here.

I was looking to develop a watchlist column that is color coded very similar (if not exact) to what you have offered. But, I was looking at it from the 'MovingAverageCrossOver' variable.

I am looking to change the color of the column background when for example the 9 EMA crosses the 21. When 9 goes above 21 it is bullish. When 9 goes below 21 it is bearish. I see that I can adjust the ema inputs with your script. But how come if I set of these for 9, 21 and 2 period lookback on a one hour chart, many times the EMA has not actually crossed? It appears to only be a price cross. Am I missing something? I am trying to find a way to turn the column green when the 9/21 actually 'cross'. Bullish above, bearish below. Lookback 2 or 3 bars. Only if they actually cross. Do you have any ideas or am I doing something wrong? Thanks again for your help and sharing!

Mike
 
BenTen

BenTen

Administrative
Staff
VIP
Warehouse
@mkalavitz Post a screenshot of the settings of your watchlist column
 
M

mkalavitz

New member
This is what I am trying to do in the column and have it change the background color like yours does. Green 'above', red 'below', orange neither in the last X bars.

MovingAvgCrossover("length1" = 9, "length2" = 21, "average type1" = "EXPONENTIAL", "average type2" = "EXPONENTIAL") is true within 2 bars
 
M

mkalavitz

New member
I'm trying to figure out how to do this, but not a programmer:

input lookback = 2;
input ema1_len = 10;
input ema2_len = 21;

MovingAvgCrossover(CLOSE,ema1_len,ema2_len,EXPONENTIAL,EXPONENTIAL,above)is true within 'lookback' bars;
green
else orange

MovingAvgCrossover(CLOSE,ema1_len,ema2_len,EXPONENTIAL,EXPONENTIAL,below)is true within 'lookback' bars;
red
else orange
 
markos

markos

Well-known member
VIP
Warehouse
@mkalavitz welcome to useThinkScript. If you are using a 1 hour chart and you want to know when a 9 period EMA crosses something else, you will be 9 Hours behind. Does that make sense? Maybe I'm messed up. I Dunno...
Please post a screen shot of something that you want. Also, your watchlist column.
 
M

mkalavitz

New member
Hi Guys. Simply trying to come up with code that will show this Exponential Moving Average Cross Over, 9/21 on an hourly chart. If a bullish cross over occurred in the last 2 bars the cell is green. If a bearish cross over occurred in the last 2 bars the cell is red. If no cross over has occurred in the last 2 hours, orange.

In the indicator on this chart, I simply used the
'MovingAvgCrossover' study set to (CLOSE, 5, 13, EXPONENTIAL, EXPONENTIAL, above)
'MovingAvgCrossover' study set to (CLOSE, 5, 13, EXPONENTIAL, EXPONENTIAL, below)

I just want the cell in the watchlist to go to the appropriate color if either of the above have occurred in the last two bars. Any ideas?



thx
Mike
 
Last edited by a moderator:
BenTen

BenTen

Administrative
Staff
VIP
Warehouse
@mkalavitz I do not see any issues with this watchlist column. I plugged the code into the watchlist, change it to my desired EMAs (in this case, I changed it to 9 and 21 just like you wanted), and adjust the timeframe to hourly). I also changed the lookback period to 2 (since that's what you also wanted).

Here is my result. Orange = neutral because there hasn't been any crossover between the two EMAs within the last 2 bars on the hourly chart.

 
M

mkalavitz

New member
Hey Ben. I think this is good! I looked a little closer and maybe I am just being extra picky. Sometimes when I look at the watchlist it shows a cross color and then when I compare to the appropriate chart with indicators, the cross has not yet officially happened. Very close, but not there yet. This must just be because of math or the chart updates?

Also, I want to know exactly when a cross happens on a 1 hour chart. Is this script looking at the 'close' for that time frame or the 'current price'? What could I substitute 'crosses' with to mean 'equal or greater than' for bull_cross and 'equal or less than' for bear_cross on the current price.

Awesome man! Thanks!

MK
 
T

TrueDepth

New member
Hi BenTen - i have been using your MA crossover script all this week...and it worked great. However, for some reason, today all day it kept on saying 'loading' in the WL column. Do you have any ideas why? I thought it was TOS issue, but the helpdesk guy was totally helpless. Any info that you can provide will be great. I love this script.
I have been getting a lot of loading too. Might be the massive number people coming from Robin Hood to ThinkorSwim. It is a shame too, because a few months ago, my watch-list and scans became lightning fast, and barely any loading at all. Now it is going back to "loading", but still not as bad as it used to be.
 
Rojo Grande

Rojo Grande

New member
Can this be made into a chart alert with sound instead of color? Maybe a bell for a bull alert and a ring for a bear alert? How's this?

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

declare lower;

input lookback = 5;
input ema1_len = 10;
input ema2_len = 20;
input averageType = AverageType.EXPONENTIAL;

def ema1 = MovAvgExponential(length=ema1_len);
def ema2 = MovAvgExponential(length=ema2_len);

def bull_cross = ema1 crosses above ema2;
def bear_cross = ema1 crosses below ema2;

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;

Alert(1, "Buy", Alert.BAR, Sound.BELL);
Alert(2, "Sell", Alert.BAR, Sound.RING);
 
Last edited:
BenTen

BenTen

Administrative
Staff
VIP
Warehouse
@TrueDepth Could be that you have a huge watchlist? Or your lookback period is too far back?

@Rojo Grande You can create a scanner and add it to your watchlist.
 
M

mkalavitz

New member
Hi Ben. Do you know if there is a way to add to your script to give a 'Pre-Bullish' or a 'Pre-Bearish' alert on these crossovers? See the image below.

Many times I find that if the price action (candles body) crosses both of the EMA's, the averages generally do end up crossing several bars later. This would allow me to speculate ahead of time before the cross actually occurs. Here are the bars that I would like to get alerted on (see image below). I think it is just an addition to the script you have already created. Use 'green' which should be brighter than your dark_green setting to indicate a bullish candle stick body crossing both averages with the price above both averages. and 'red' which is brighter than the current dark_red which would indicate a pre-bearish candle stick body crossing both averages with the price being below both averages.



Thanks
Mike
 
Last edited by a moderator:

Top