MACD with Breakout Signals Indicator for ThinkorSwim


Here is a MACD indicator with breakout signals that shows the beginning of a downtrend or uptrend. For me, the arrows act as a bearish or bullish sign that I sometimes use as buy or sell signals.

thinkScript Code

Rich (BB code):
Archive Name: MACD_withBreakoutSignals_InvTools
Archive Section: Momentum 
Suggested Tos Name: MACD_withBreakoutSignals_InvTools 
Archive Date: 5.13.2018 
Archive Notes:  
"" indicates an addition by the Archivist 

#Number Two MACD with Breakout Signals  [email protected]

declare lower;

input fastLength = 8;

input slowLength = 17;

input MACDLength = 9;

input AverageType = {SMA, default EMA};

plot Diff = MACD(fastLength, slowLength, MACDLength, AverageType).Diff;




Diff.DefineColor("Positive and Up", Color.GREEN);

Diff.DefineColor("Positive and Down", Color.DARK_GREEN);

Diff.DefineColor("Negative and Down", Color.RED);

Diff.DefineColor("Negative and Up", Color.DARK_RED);

Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.Color("Positive and Up") else Diff.Color("Positive and Down") else if Diff < Diff[1] then Diff.Color("Negative and Down") else Diff.Color("Negative and Up"));

plot zeroline = 0;


def crossedb = Crosses(diff, 0, CrossingDirection.BELOW);

plot crossbelow = if crossedb then crossedb-1 else double.NaN;



def crossedu = Crosses(diff, 0, CrossingDirection.above);

plot crossabove = if crossedu then crossedu-1 else double.NaN;




Shareable Link
Last edited:


New member
@BenTen I’m new to the group and I’m really appreciating yours and everyone else’s thoughts and scripts. Thank you. Let’s make some $$$$$!!!!

Last edited:


New member
@jimothy Visually different but signals should still be the same. The script above, however, uses different inputs.

Hi Ben,

Is there a way to get the arrows to: 1) display on the upper chart and (2) be displayed below the relevant candles?

I tried to update the code to do this, but the arrows plot in various places on the upper chart because they are using the histogram line.

Thank you!


@KevinSammy There is already an indicator in ThinkorSwim called MACDHistogramCrossover. It does pretty much the same and also plot arrows on your upper chart. You can add it via the Studies section or copy the code below.

# TD Ameritrade IP Company, Inc. (c) 2009-2020

#wizard input: crossingType
#wizard text: Inputs: fast length:
#wizard input: fastLength
#wizard text: slow length:
#wizard input: slowLength
#wizard text: macd length:
#wizard input: MACDLength
#wizard text: average type:
#wizard input: AverageType

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
input crossingType = {default "Positive to Negative", "Negative to Positive"};

def Diff = MACD(fastLength, slowLength, MACDLength, averageType).Diff;

plot signal = crosses(Diff, 0, crossingType == CrossingType."Negative to Positive");

signal.DefineColor("Negative to Positive", GetColor(2));
signal.DefineColor("Positive to Negative", GetColor(3));
signal.AssignValueColor(if crossingType == CrossingType."Negative to Positive" then signal.color("Negative to Positive") else signal.color("Positive to Negative"));

signal.SetPaintingStrategy(if crossingType == CrossingType."Negative to Positive"
    then PaintingStrategy.BOOLEAN_ARROW_UP
    else PaintingStrategy.BOOLEAN_ARROW_DOWN);
Awesome bro, Can you suggest me an indicator script that would alert me when the MACD line crosses the Signal line. Would be even better if the alert is displayed as text on the chart!

Similar threads