Below is what you have coded so far.I'm trying to add this MACD Script to use in a watchlist but it's not working when I copy and paste the script.
I found the steps to this script in a video on youtube
This was an excellent attempt. I wouldn't use this watchlist. It makes gross assumptions such as because it hasn't crossed its average yet, the trend is decreasing.
You need to add logic which looks at whether the trend is sloping up or down: value>value[1] and avg>avg[1]
Find an example here:
https://usethinkscript.com/threads/...chlist-for-thinkorswim.7745/page-6#post-74492
If you fix this, we appreciate if you come back and share.
Ruby:
def fastlength = 12;
def slowlength = 26;
def MACDLength = 9;
def averageType = AverageType.EXPONENTIAL;
def showBreakoutSignals = no;
def ZeroLine = 0;
def Value = MovingAverage (averageType, close, fastlength) – MovingAverage (averageType, close, slowlength);
def Avg = MovingAverage (averageType, Value, MACDLength);
def Diff = Value – Avg;
addlabel (yes,
if value >= zeroline and avg >= zeroline and value crosses below avg within 3 bars then “Cross OB” else
if value <= zeroline and avg <= zeroline and value crosses above avg within 3 bars then “Cross OS” else
if value >= zeroline and avg >= zeroline and value > avg then “Bull Acc” else
if value >= zeroline and avg >= zeroline and value < avg then “Bull Dec” else
if value <= zeroline and avg <= zeroline and value < avg then “Bear Acc” else
if value <= zeroline and avg <= zeroline and value > avg then “Bear Dec” else "_");
AssignBackgroundColor(
if value >= zeroline and avg >= zeroline and value crosses below avg within 3 bars then color.cyan else
if value <= zeroline and avg <= zeroline and value crosses above avg within 3 bars then color.dark_orange else
if value >= zeroline and avg >= zeroline and value > avg then color.lime else
if value >= zeroline and avg >= zeroline and value < avg then color.green else
if value <= zeroline and avg <= zeroline and value < avg then color.red else
if value <= zeroline and avg <= zeroline and value > avg then color.pink else color.light_gray);
Last edited: