Moving Average Crossover Watchlist Column for ThinkorSwim

T

tomsk

Well-known member
VIP
Warehouse
Funny ... but it is hard to admit that I simply cannot combine these characters to get the desired result even though the answers are provided here in plain English.

This simple script is not changing to SMA regardless of the variations I throw at it. Please help again.

declare upper;
input price = close;
input displace = 0;

input EMALength1 = 9;
input EMALength2 = 20;

plot upper = ExpAverage(data = price[-displace], length = EMALength1);
upper.SetDefaultColor(Color.RED);
plot lower = ExpAverage(data = price[-displace], length = EMALength2);
lower.SetDefaultColor(Color.BLUE);
AddCloud(upper,lower);

Thank you,
Doug

@dougn Since you're still stuck I MODIFIED your code to a generic moving average type so that it can be selected to SIMPLE, EXPONENTIAL, WILDERS, HULL etc via the user interface. I have made it so that SIMPLE moving average has been selected. Your earlier code used the call ExpAverage() which is to calculate Exponential Moving Average and so won't work for a Simple Moving Average.

Compare this code with your earlier code, so that you can use this as a learning opportunity. You were also missing a few parameters in your AddCloud() statement - that was also fixed

Code:
# Moving Average Dual
# tomsk
# 1.2.2020

input price = close;

input averageType = AverageType.SIMPLE;
input displace = 0;
input Length1 = 9;
input Length2 = 20;

plot fast = MovingAverage(averageType, price[-displace], length1);
fast.SetDefaultColor(Color.RED);

plot slow = MovingAverage(averageType, price[-displace], length2);
slow.SetDefaultColor(Color.BLUE);

AddCloud(fast,slow, color.green, color.red);
# End Moving Average Dual
 
T

tomsk

Well-known member
VIP
Warehouse
You're very welcome, it's a very simple starter script for those wishing to learn/dabble in ThinkScript
 
T

tradeking313

New member
Hey. I was seeing if there was any way to build a custom watchlist column of a 9ema and 26 ema line..to where when 9 crosses over 26...the column turns green and vice versa on the one minute aggregation period. thanks!!
 
T

tomsk

Well-known member
VIP
Warehouse
@tradeking313 See if this watchlist works for you. It's after trading hours now so I can't test in a live environment, but from minimal testing on my end, it should work

Code:
# EMA Crossover Watchlist
# tomsk
# 1.11.2020

def ema1 = ExpAverage(close,9);
def ema2 = ExpAverage(close,26);

def crossOver = if ema1 crosses above ema2 then 1 else if ema1 crosses below ema2 then -1 else 0;
AddLabel(1, if crossOver == 1 then "Up" else if crossOver == -1 then "Down" else "  ", Color.BLACK);
AssignBackgroundColor(if crossOver == 1 then Color.GREEN else if crossOver == -1 then Color.RED else Color.BLACK);
# EMA Crossover Watchlist
 

Top