Moving Average Crossover Watchlist Column for ThinkorSwim

S

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

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

 
F

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?
 
S

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
 
P

Pensar

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

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);
***********
 
P

Pensar

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
 
S

satyarishi

New member
VIP
@Pensar I was looking for additional conformational conditions. But you are Spot on. Code you gave above fits my needs. THANK YOU !
 
Top