Moving Average Crossover Watchlist Column for ThinkorSwim

Pensar

Well-known member
VIP
@wilmanv - The EMA is already in the code, written as "expaverage()". Unless you mean something else? To change the length of the EMA, adjust the input value. To display the watchlist column on different timeframes at the same time, it will be necessary to save multiple columns and change the aggregation of each to your choice using the built-in options.
 

drewski408

New member
VIP
Thanks! I was not able to get "plot" to work but I used "addlabel" and I now have what I need.
Could you share the final code please. I tried to modify but didn't seem to work this is what I had
Thanks! I was not able to get "plot" to work but I used "addlabel" and I now have what I need.
Could you please share the final code or show what I have wrong. I tried making the change to "addlabel" as well but did not work
Code:
#Watchlist Column
#displays green when in an uptrend, red when in a down trend and black when no trend apparent.



addlabel condition_up =ExpAverage(close[20],34) < ExpAverage(close[15],34)
and
ExpAverage(close[15],34) < ExpAverage(close[10],34)
and
ExpAverage(close[10],34) < ExpAverage(close[5],34)
and
ExpAverage(close[3],34) < ExpAverage(close,34);

addlabel condition_down =ExpAverage(close[20],34) > ExpAverage(close[15],34)
and
ExpAverage(close[15],34)> ExpAverage(close[10],34)
and
ExpAverage(close[10],34) > ExpAverage(close[5],34)
and
ExpAverage(close[3],34) > ExpAverage(close,34);

AssignBackgroundColor(if condition_up then color.green
                      else if condition_down then color.red
                      else color.gray);
# end code
 

drewski408

New member
VIP
@Andygray8 Your code works fine... Did you create a Custom Column in your Watchlist and add it to the Watchlist...??? Check out column test2...

1hXvIWx.jpg
Hi how can I make it so I can get color background for the RSI value like you have? Thanks
 

rad14733

Well-known member
VIP
Hi how can I make it so I can get color background for the RSI value like you have? Thanks

Here you go...

Ruby:
def length = 14;
def ob = 70;
def os = 30;
def price = close;

def rsi = RSI("length" = length, "over bought" = ob, "over sold" = os, "price" = price, "average type" = AverageType.WILDERS)."RSI";

plot rsiValue = Round(rsi, 0);

AssignBackgroundColor(if rsiValue < os then color.dark_green else if rsiValue > ob then color.dark_red else color.dark_gray);
 

Big Ed

New member
When on a specific time frame and lets say I choose 7 as my lookback and on the 7th bar back it crossed up but on the 2nd bar it's crossed down I want it to give me the results for the newest bar not the oldest bar but I still want to be able to look further back than 2 days. How can I write the code to do that? I want the latest results with no matter how far I look back. The way this code is written it gives the furthest results back first
 

DelrayDad

New member
Hi - amazing script, it does a lot for people, thank you for it and all you're doing to help people. I was intersted in asking a question. I promise I read the whole thread before posting.


Like several others I experienced the issue where the Column didn't show the "last" crossover and tended to stay Orange. I've made basic adjustments to the Lookback time but none seem to really pick up the last cross over.

the only modifications I made were:

input lookback = 96
input ema1_len = 13
input ema1_len = 25

but in the image displayed for MSFT you see the bar is green but the 13 EMA had crossed below the 25 EMA some time in the past (33 bars ago). I did read that the columns only update every 3 - 7 minutes. But I am wondering if I did something wrong here. Any help would be greatly appreciated.

The code:

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

declare lower;

input lookback = 96;
input ema1_len = 13;
input ema2_len = 25;
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);


zxR1ENw.jpg
 

DelrayDad

New member
@DelrayDad Why are you looking back 96 bars on a 15m chart...??? That's about 24 hours or just shy of 4 days worth of trading...
Apologies for my poor communication.

I moved it that far back trying to test it and see where I was going wrong. Why it wasnt changing color due to the most recent crossover. If the 13EMA crossed above the 25EMA 45 minutes ago, I want it to be green, until the 13EMA crosses back below the 25EMA.


Basically what I am seeing is the lookback goes all the way to the lookback number and uses that for its value, it doesnt see to use the most recent crossover. I'd like it to look back but use the most recent crossover as the value.
 
Last edited:

Angry_Raven

New member
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.

DQJCTgG.png


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.

In case you don't want to check for moving average crossover but price moving above or below a specific moving average, you can use the alternative code below.

This script will highlight the column green if the current stock price is above the 200 simple moving average. If the price is below the 200 SMA, the column will turn red.

Code:
input price = close;
input length = 200;
input displace = 0;

plot SMA = Average(price[-displace], length);
AssignBackgroundColor(if price > SMA then color.dark_green else color.dark_red);
Would it be possible for someone to make me a custom column that tracks how long I have been in a position for please?
 

AnimalMother

New member
VIP
Hello traders. I have been looking for a while for a code that would indicate if a stock is above, below or inside the Ichimoku cloud for any time frame and tick charts serving as a watchlist column. If any of you guys know the code for it, or could point me in the right direction, it would be greatly appreciated it. Also, if there is no such code, would any of you guys be willing to take on this task? I think it would be a great tool to have. Thank you.
 
Last edited:

Similar threads

Top