Moving Average Crossover Watchlist Column for ThinkorSwim

I am trying to add a Custom Column in Watchlist that would indicate when 8 moving exponential crosses 20 moving average exponential..

def mvgcoup = MovingAvgCrossover(length1 = 8, length2 = 20, averageType1 = "EXPONENTIAL", averageType2 = "EXPONENTIAL");

def mvgcodwn = MovingAvgCrossover(length1 = 20, length2 = 8, averageType1 = "EXPONENTIAL", averageType2 = "EXPONENTIAL");

plot buy_ind = mvgcoup;

#AssignBackgroundColor(if mvgcoup then Color.DARK_GREEN else if mvgcodwn then Color.DARK_RED else color.black);

Whats missing is the I would like to paint column as Label " Buy" with "color Green" and append it with "Number of Candles since the condition met"

For eg: Buy : 7 ( 7 candle sticks formed since the last time it gave Buy Signal )

Likewise I would like to add label "Sell" with red color and appended with number of candles since the condition met.

Appreciate your help with AssignBackgroundColor and AssignLabel statements as described above
 
@satyarishi Try this code -
Code:
#choose your aggregation above

def ema1 = expaverage(close,8);
def ema2 = expaverage(close,20);
def crossup = ema1 > ema2;
def crossdn = ema1 < ema2;

def countup = if crossup and !crossup[1] then 1 else countup[1]+1;
def countdn = if crossdn and !crossdn[1] then 1 else countdn[1]+1;

addlabel(1, if crossup then "Buy,  " + countup
         else if crossdn then "Sell,  " + countdn
         else "Equal", color.black);
assignbackgroundcolor(if crossup then color.green
                      else if crossdn then color.red
                      else color.gray);
 
@Pensar - Can you please validate this code ? Its similar concept but on Ichimoku cloud. I am seeing lot of Grey color ticker symbols instead of getting the counted numbers with either L : <count> or S : <count>

Code:
***********
#Ichimoku watchlist
***********
input breakOutBars = 1;
input tenkan_period = 9;
input kijun_period = 26;
input lookBack = 5;

def Tenkan = (Highest(high, tenkan_period) + Lowest(low, tenkan_period)) / 2;
def Kijun = (Highest(high, kijun_period) + Lowest(low, kijun_period)) / 2;
def "Span A" = (Tenkan[kijun_period] + Kijun[kijun_period]) / 2;
def "Span B" = (Highest(high[kijun_period], 2 * kijun_period) + Lowest(low[kijun_period], 2 * kijun_period)) / 2;
def Chikou = close[-kijun_period];

def bullishCloud = "Span A" >= "Span B";
def bearishCloud = "Span B" > "Span A";

def closeCloudDiff = close - "Span B";
def closeCloudDiffLong = if bullishCloud then close - "Span A" else close - "Span B";
def closeCloudDiffShort = if bearishCloud then close - "Span A" else close - "Span B";

def slowDiff = MovingAverage(AverageType.SIMPLE, closeCloudDiff, lookBack);

def underCloud = highest(slowDiff[1], lookBack) < 0;
def overCloud = lowest(slowDiff[1], lookBack) > 0;

def cloudBreakOutLong = lowest(closeCloudDiffLong, breakOutBars) > 0;
def cloudBreakOutShort = highest(closeCloudDiffShort, breakOutBars) < 0;

# this signal finds the long side break outs of price action above the cloud
def signalBreakAboveCloud = (close > "Span A" and bullishCloud and underCloud[breakOutBars] and cloudBreakOutLong and cloudBreakOutLong[1] == 0) or (close > "Span B" and bearishCloud and underCloud[breakOutBars] and cloudBreakOutLong and cloudBreakOutLong[1] == 0);

# this signal finds the short side break downs of price action below the cloud
def signalBreakBelowCloud = (close < "Span A" and bearishCloud and overCloud[breakOutBars] and cloudBreakOutShort and cloudBreakOutShort[1] == 0) or (close < "Span B" and bullishCloud and overCloud[breakOutBars] and cloudBreakOutShort and cloudBreakOutShort[1] == 0);

def countup = if signalBreakAboveCloud and !signalBreakAboveCloud[1] then 1 else countup[1]+1;
def countdn = if signalBreakBelowCloud and !signalBreakBelowCloud[1] then 1 else countdn[1]+1;

addlabel(1, if signalBreakAboveCloud then "L: " + countup
         else if signalBreakBelowCloud then "S: " + countdn
         else "-", color.black);
assignbackgroundcolor(if signalBreakAboveCloud then color.uptick
                      else if signalBreakBelowCloud then color.downtick
                      else color.gray);
***********
 
@satyarishi I looked at the code above . . . I get confused as to what it is trying to do, but it appears that you are looking for breakouts above or below the ichimoku cloud. The below code should give you the breakout/downs and the count of the bars since. If I am wrong, please correct me and post what you want instead. :)
Code:
# Ichimoku Watchlist Column

def tenkan_period = 9;
def kijun_period = 26;

def Tenkan = (Highest(high, tenkan_period) + Lowest(low, tenkan_period)) / 2;
def Kijun = (Highest(high, kijun_period) + Lowest(low, kijun_period)) / 2;
def "Span A" = (Tenkan[kijun_period] + Kijun[kijun_period]) / 2;
def "Span B" = (Highest(high[kijun_period], 2 * kijun_period) + Lowest(low[kijun_period], 2 * kijun_period)) / 2;

def below = close < "Span A" and close < "Span B";
def above = close > "Span A" and close > "Span B";

def countup = if above and !above[1] then 1 else countup[1]+1;
def countdn = if below and !below[1] then 1 else countdn[1]+1;

addlabel(1, if above then "L: " + countup
         else if below then "S: " + countdn
         else "-", color.black);
assignbackgroundcolor(if above then color.uptick
                      else if below then color.downtick
                      else color.gray);

# end code
 
@Pensar - Can you please let me know why the same strategy isn't working for VWAP value. Here is the code

#Price crosses above VWAP

def vwapValue = vwap();

def crossingAbove = close > vwapValue;
def crossingBelow = close < vwapValue;

def countup = if crossingAbove and !crossingAbove[1] then 1 else countup[1]+1;
def countdn = if crossingBelow and !crossingBelow[1] then 1 else countdn[1]+1;

addlabel(1, if crossingAbove then "👍: " + countup
else if crossingBelow then "👎: " + countdn
else "-", if crossingAbove then color.uptick else if crossingBelow then color.downtick else color.black);


Am using this as column in the watch list - and Set the time frame as 1min. I am not getting the counts right. Appreciate your help
 
@Pensar

i THINK I found the issue. Changed the line
from
def vwapValue = vwap();
to
def vwapValue = reference vwap();

Seems to have done the trick. Pls validate ?
 
I'm very new to Thinkscript and I pulled together the code below using pieces from different sources. In theory this is a simple code that will turn a cell in a custom column in a TOS watchlist to green if in an uptrend, red in a downtrend, and black otherwise. I want to be able to sort on this column so I can see all the trending stocks in my watchlist. When I add this code to the thinkscript editor it appears to be okay. None of the text is highlighted in red indicating the syntax is wrong but the OK button is greyed out. So either my code is wrong or there is something I'm not doing within the editor. Thanks in advance for any help with this code.

Code:
#Watchlist Column
#displays green when in an uptrend, red when in a down trend and black when no trend apparent.



def 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);

def 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
 
Hello All

How do i add this script to the watch list so that it turns green with the cross over happens. I want to use it on a 5min chart looking back 1 dev so i can see when my top 10 stocks hit the crossover.

Code:
# Mobius

input price = close;
input fastLength = 9;
input slowLength = 21;
input averageType = AverageType.EXPONENTIAL;

plot FastMA = MovingAverage(averageType, price, fastLength);
plot SlowMA = MovingAverage(averageType, price, slowLength);
FastMA.AssignValueColor(if FastMA > SlowMA then color.green else color.red);
SlowMA.AssignValueColor(if FastMA > SlowMA then color.green else color.red);

plot ArrowUp = if FastMA crosses above SlowMA
               then low
               else double.nan;
     ArrowUP.SetPaintingStrategy(PaintingStrategy.Arrow_UP);
     ArrowUP.SetLineWeight(3);
     ArrowUP.SetDefaultColor(Color.Green);
plot ArrowDN = if FastMA crosses below SlowMA
               then high
               else double.nan;
     ArrowDN.SetPaintingStrategy(PaintingStrategy.Arrow_DOWN);
     ArrowDN.SetLineWeight(3);
     ArrowDN.SetDefaultColor(Color.Red);
Alert(ArrowUp, " ", Alert.Bar, Sound.Chimes);
Alert(ArrowDN, " ", Alert.Bar, Sound.Bell);
def countUP = if FastMA crosses above SlowMA
              then 1
              else if FastMA > SlowMA
                   then countUP[1] + 1
              else if ArrowDN
                   then 0
                   else countUP[1];
AddLabel(1, "Count UP = " + countUP, color.white);
def CrossBar = if FastMA crosses SlowMa
               then barNumber()
               else double.nan;
AddChartBubble(barNumber() == HighestAll(CrossBar), FastMA, "Cross Over", color.cyan);
# End Codeata = close;
 
Isn't there a way to get a column on the watchlist that indicates whether or not the crossover has taken place?

I'm slightly confused after reading your comments. Can you clarify what you're trying to do?
 
I'm slightly confused after reading your comments. Can you clarify what you're trying to do?
So I've got that Ema8/Sma20 crossover working on the chart. I have a watchlist that I'd like to scan for these crosses. It looks like you can add a column on the watchlist that gives a color indicating whether or not one has taken place? Was I reading that one post of yours correctly that had the EMA cross example?
 
I'm slightly confused after reading your comments. Can you clarify what you're trying to do?
Also I was hearing noises on the desktop app but was wondering if there's a repository or list that keeps the cross alerts. On my watchlist there was no indication that any of the tickers were triggering a cross alert...
 
@Andygray8 Yes, you're looking at the correct script. The EMA crossover column will show green if there is a bullish crossover within the last 5 bars...Red if there is a bearish crossover within the last 5 bars.

The watchlist column does not trigger any alerts. It must have came from one of your indicators.
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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