Moving Average Crossover Watchlist Column for ThinkorSwim

Sagar

New member
@BenTen Can we have some instruction regarding how to create the scanner alerts. Do i need to separate the bull and bear in code for scanner alerts. As in this code both are present. Appreciate your help sir.
 

BenTen

Administrative
Staff
VIP
@Sagar This is for your watchlist column. If you want to get alerted for new crossovers all you have to do is create a scanner > save the scanner as a watchlist > Alerts when scan result change...

 

fluentd

New member
Looking for some help with getting the EMA9 crossing the VWAP on 1min? Not sure if I can use this script for that? And the best to be able to add to watchlist and get alerted?
 

satyarishi

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

Pensar

Active member
VIP
@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);
 

satyarishi

New member
VIP
@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);
***********
 

Pensar

Active member
VIP
@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
 

satyarishi

New member
VIP
@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
 

satyarishi

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

SwingIsKing

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

pga0008

Member
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;
 

Similar threads

Top