Ultimate MACD Indicator for ThinkorSwim

horserider

Well-known member
VIP
Here is a MACD indicator for ThinkorSwim. It uses a color coded MACD line to show changes. There is a moving average of the MACD signal line. And MACD bands to show volatility. The signal would be the cross of MACD (Green/RED) and signal line (White). A photo is also below to give tips on trading the indicator. The lengths can be adjusted to suit your trading. (Since the below photo zero line was added)

Image-9999999999.jpg


Original post is below with updated standard code.

F8KbJxf.jpg


Any questions just ask.

Here is the code. Code updated to current version:

Code:
#
# Ultimate MACD by Horserider 8/30/2019
# Standard version
# Also have short and long term versions. Can accomplish all three by just adjusting inputs to fit your trading style.
# Standard MACD 12,26,9 BB length 20.
# Short term MACD 6, 13, 6 BB length 5.
# Long term MACD 48, 104, 36 BB length 20.
# Added zero line on suggestion of Ahmar824 1/12/2019.

declare lower;
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input AverageTypeMACD = {SMA, default EMA, Wilders};

input price = close;
input displace = 0;

def MACD_Data = MACD(fastLength = fastLength, slowLength = slowLength, MACDLength = MACDLength);
plot MACD_Line = MACD_Data;

MACD_Line.DefineColor("Up", Color.GREEN);
MACD_Line.DefineColor("Down", Color.RED);
MACD_Line.DefineColor("Even", Color.WHITE);
MACD_Line.AssignValueColor(if MACD_Line > MACD_Line[1] then MACD_Line.Color("Up") else (if MACD_Line == MACD_Line[1] then MACD_Line.Color("Even") else MACD_Line.Color("Down")));
MACD_Line.SetLineWeight(3);

plot zero = 0;
zero.setDefaultColor(color.LIGHT_ORANGE);
zero.setLineWeight (1) ;

def Value;
plot Avg;
switch (AverageTypeMACD) {
case SMA:
    Value = Average(price, fastLength) - Average(price, slowLength);
    Avg = Average(Value, MACDLength);
case EMA:
    Value = ExpAverage(price, fastLength) - ExpAverage(price, slowLength);
    Avg = ExpAverage(Value, MACDLength);

case Wilders:
    Value = WildersAverage(price, fastLength) - WildersAverage(price, slowLength);
    Avg = ExpAverage(Value, MACDLength);
}
Avg.SetDefaultColor(Color.WHITE);


#plot BB;
#Bollinger BandsSMA,EMA
input AverageTypeBB = {default SMA, EMA, HMA};
input displaceBB = 0;
input lengthBB = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;

plot upperBand;
plot lowerBand;
def midline;

switch (AverageTypeBB) {
case SMA:
    upperBand = reference BollingerBands(MACD_Line, displaceBB, lengthBB, Num_Dev_Dn, Num_Dev_up).UpperBand;
    lowerBand = reference BollingerBands(MACD_Line, displaceBB, lengthBB, Num_Dev_Dn, Num_Dev_up).LowerBand;
    midline   = reference BollingerBands(MACD_Line, displaceBB, lengthBB, Num_Dev_Dn, Num_Dev_up).Midline;
case EMA:
    upperBand = reference BollingerBands(MACD_Line, displaceBB, lengthBB, Num_Dev_Dn, Num_Dev_up, averageType = AverageType.EXPONENTIAL).UpperBand;
    lowerBand = reference BollingerBands(MACD_Line, displaceBB, lengthBB, Num_Dev_Dn, Num_Dev_up, averageType = AverageType.EXPONENTIAL).LowerBand;
    midline   = reference BollingerBands(MACD_Line, displaceBB, lengthBB, Num_Dev_Dn, Num_Dev_up, averageType = AverageType.EXPONENTIAL).Midline;
case HMA:
    upperBand = reference BollingerBands(MACD_Line, displaceBB, lengthBB, Num_Dev_Dn, Num_Dev_up, averageType = AverageType.EXPONENTIAL).UpperBand;
    lowerBand = reference BollingerBands(MACD_Line, displaceBB, lengthBB, Num_Dev_Dn, Num_Dev_up, averageType = AverageType.EXPONENTIAL).LowerBand;
    midline   = reference BollingerBands(MACD_Line, displaceBB, lengthBB, Num_Dev_Dn, Num_Dev_up, averageType = AverageType.EXPONENTIAL).Midline;
}

upperBand.SetDefaultColor(Color.GRAY);
upperBand.DefineColor("Up", Color.CYAN);
upperBand.DefineColor("Down", Color.PINK);
upperBand.DefineColor("Even", Color.GRAY);
upperBand.AssignValueColor(if upperBand > upperBand[1] and lowerBand < lowerBand[1] then upperBand.Color("Up") else (if upperBand < upperBand[1] and lowerBand > lowerBand[1] then upperBand.Color("Down") else upperBand.Color("Even")));
upperBand.SetLineWeight(2);

lowerBand.SetDefaultColor(Color.GRAY);
lowerBand.DefineColor("Up", Color.CYAN);
lowerBand.DefineColor("Down", Color.PINK);
lowerBand.DefineColor("Even", Color.GRAY);
lowerBand.AssignValueColor(if upperBand > upperBand[1] and lowerBand < lowerBand[1] then upperBand.Color("Up") else (if upperBand < upperBand[1] and lowerBand > lowerBand[1] then upperBand.Color("Down") else upperBand.Color("Even")));

plot midline1 = midline;

Update to show versatility of the study to fit different trading styles. Will include shares to each variation but same can be accomplished by changing the inputs. Added a zero line.

Standard MACD 12,26,9 BB length 20. https://tos.mx/X1IBznK
Short term MACD 6, 13, 6 BB length 5. https://tos.mx/tpa1Ek8
Long term MACD 48, 104, 36 BB length 20. https://tos.mx/iUs5wqK
 
Last edited:

Lambert58

New member
Good Evening everyone,

I am new to this forum, feel very fortunate to have found all of you. I loaded this into my TOS studies, and that was successful. The MACD lines are very compressed in the lower study window. When I zoom in they become more compressed. Any help would be very much appreciated.
 

horserider

Well-known member
VIP
@Lambert58 You have 2 studies in the same study panel. Many times this will make the scaling do crazy things. If you want to use both of those studies put each in it's own lower panel.
 

HDP

New member
If you could help me creating a watchlist column by using the Macd BB Indicator for tos. I would like to get the last dot to display a numerical value and display the color of the dot into a watchlist. but it has to match as close to the number on the right side of the indicator. thanks I wish I had your skill to make indicators.

Here is what I tried but I cant get the numerical value to match up with the with the lower graph number on the rightside of the indicator. thanks

Code:
# BB_MACD Bollinger Band Indicator Watchlist

input MACD_FastLength = 12;
input MACD_SlowLength = 26;
input Length = 10;
Input Std_Dev = 1.0;

rec BB_MACD = reference MACD(fastlength = MACD_FastLength, slowlength = MACD_SlowLength, MACDlength = Length);
def avg = ExpAverage(BB_MACD, Length);
def sdev = stdev(data = BB_MACD, length = Length);
#def Lower_Band = avg - Std_Dev * sdev;
#def Upper_Band = avg + Std_Dev * sdev;

plot bbmacd = BB_MACD;
def upperband = avg + Std_Dev * sdev;
def lowerband = avg - Std_Dev * sdev;
###################################### added 09032019
BBMACD.assignValueColor(if BB_MACD > upperband then color.green else if BB_MACD < LowerBand then color.red else color.red);
#BBMACD.assignValueColor(if ( BB_MACD[1]> 0.00) then color.Green else if ( BB_MACD[1] < 0.00) then color.RED else color.RED);
input Type = PriceType.LAST;
def Lastprice =(close(priceType = Type));
assignBackgroundColor(if lastprice then color.black else color.black);#added 70419
def CurrentBar = (if !isNaN(close) and isNaN(close[-1])
then barNumber()
                 else double.nan); #added 090419

def LastBar = if isNaN(close[-1]) and !isNaN(close) then barNumber() else LastBar[1]; #added 100419
def priceLine = if isNan(close[-1]) and !isNAN(close) then close else priceLine[1];#added 100419
input Dec_Places = numberformat.TWO_DECIMAL_PLACES;#added 100419
 

RobertPayne

Member
@HDP

I pasted your script into the watchlist column and it worked perfectly. The only change I made was to remove the excess code that had nothing to do with calculating bbmacd.

I believe the problem may be that you didn't match the time frame of your chart to the watchlist. Make certain that both match. Also, either check or uncheck the "extended session" box as necessary.

z7Uoj0Q.png


7fwXOLF.png
 

netarchitech

Well-known member
VIP
@HighBredCloud I'm glad to hear the Breakout signals are working perfectly :) Unfortunately, the coding of the DSS Line and the Moving Averages is more problematic...Below is a screenshot of what the DSS Line looks like currently...

a.png


I am currently at a loss to explain why the DSS Line is plotting the way it is...I will sleep on it and hopefully have an answer in the morning...I would welcome any thoughts or suggestions from the community regarding this situation...

Code:
# MACD with a more Normal Distribution
# Mobius
# V01.09.2015
#Hint: Plots a Gaussian distribution. If Normal Distribution is met, then at minimum, 68.2% of the close values should be inside a One Standard Deviation Envelope and 95.4% of the close values should be inside a 2 Standard Deviation Envelope.

# V11.01.2019 - netarchitech added standard TOS Breakout Signals per HighBredCloud request

declare lower;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input showBreakoutSignals = no;

# Four Pole Filter
script g{
input length = 4;
input betaDev = 2;
input price = OHLC4;
def c;
def w;
def beta;
def alpha;
def G;
c = price;
w = (2 * Double.Pi / length);
beta = (1 - Cos(w)) / (Power(1.414, 2.0 / betaDev) - 1 );
alpha = (-beta + Sqrt(beta * beta + 2 * beta));
G = Power(alpha, 4) * c +
4 * (1 – alpha) * G[1] – 6 * Power( 1 - alpha, 2 ) * G[2] +
4 * Power( 1 - alpha, 3 ) * G[3] - Power( 1 - alpha, 4 ) * G[4];
plot Line = G;
}
# Modified MACD
plot Value = g(length = fastLength) - g(length = slowLength);
plot Avg = g(price = Value, length = MACDLength);
plot Diff = Value - Avg;
plot ZeroLine = 0;

Value.SetDefaultColor(GetColor(1));
Avg.SetDefaultColor(GetColor(8));
Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
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"));
ZeroLine.SetDefaultColor(GetColor(0));

plot UpSignal = if Diff crosses above ZeroLine then ZeroLine else Double.NaN;
plot DownSignal = if Diff crosses below ZeroLine then ZeroLine else Double.NaN;

UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

# DSS Line
input N2_Period = 21;
input R2_Period = 5;

def Ln2 = Lowest(low, N2_Period);
def Hn2 = Highest(high, N2_Period);
def Y2 = ((close - Ln2)/(Hn2 - Ln2)) * 100;
def X2 = ExpAverage(Y2, R2_period);

def Lxn = Lowest(x2, n2_period);
def Hxn = Highest(x2, n2_period);
def DSS = ((X2 - Lxn)/(Hxn - Lxn)) * 100;

def DSSb = ExpAverage(Dss, R2_period);
#DSSb.setdefaultColor(Color.GREEN);

plot DSSsignal = DSSb[1];
DSSsignal.AssignValueColor(if DSSb>DSSsignal then Color.Green else Color.Red);
 

HighBredCloud

Well-known member
VIP
@netarchitech This MACD is working better than expected...I am getting the entry signal a bar sooner on a 5 min chart before the cross over happens...I kept the standard settings of 12, 26, 9 on the 5m timeframe. I kept the AA setting at default 0.1...So far this has been a very good indication of pull backs...Really cool indicator to go along with TMO and the SMI with DSS line. You hit a winner on this one...Can't wait to see more updates to this. Will continue testing variety of other stocks and time frames on it. (This message did not post earlier)
 

tomsk

Well-known member
VIP

Normalized MACD Example Study

There was some discussion in one of the sub forums regarding how to normalize plots. Rather than post it there, thought it might make it easier for future searches to find it here. Based on a normalizePlot function Mobius wrote several years ago, you can use that to normalize plots to whatever scale you like, e.g. 0 to 100, -100 to 100, etc.

Here is an example on how to normalize the MACD on a scale from -100 to 100.

First determine what data you're going to plot. In the example below I have chosen to plot the MACDAvg line. Place all the code into a script() routine, in my example I call this MACDScr(). Then run this through Mobius normalizePlot function and slap on whatever lipstick you need

Code:
# Normalized MACD
# tomsk
# 11.16.2019

declare lower;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input OverBought = 80;
input OverSold = -80;

script normalizePlot {
    input data = close;
    input newRngMin =  -1;
    input newRngMax = 1;
    def hhData = HighestAll( data );
    def llData = LowestAll( data );
    plot nr = ((( newRngMax - newRngMin ) * ( data - llData )) / ( hhData - llData )) + newRngMin;
}

script MACDScr {
   input fastLength = 13;
   input slowLength = 21;
   input MACDLength  =  8;
   input data = close;
   def Value = ExpAverage(data, fastLength) - ExpAverage(data, slowLength);
   plot MACDAvg  = ExpAverage(Value, MACDLength);
}

plot MACDX = normalizePlot(MACDScr("fastLength" = fastLength, "slowLength" = slowLength, "MACDLength" = MACDLength, "data" = close), -100, 100);

plot OS = if !isNaN(close) then OverSold else Double.NaN;
OS.SetPaintingStrategy(PaintingStrategy.Line);
OS.SetLineWeight(2);
OS.SetDefaultColor(Color.Cyan);

plot OB = if !IsNaN(close) then OverBought else Double.NaN;
OB.SetPaintingStrategy(PaintingStrategy.Line);
OB.SetLineWeight(2);
OB.SetDefaultColor(Color.Cyan);

plot MID = if !isNaN(close) then 0 else Double.NaN;
MID.SetPaintingStrategy(PaintingStrategy.Dashes);
MID.SetLineWeight(2);
MID.SetDefaultColor(Color.Orange);

MACDX.SetPaintingStrategy(PaintingStrategy.Line);
MACDX.SetLineWeight(1);
MACDX.AssignValueColor(if MACDX >= 50 then if MACDX > MACDX[1] then Color.Light_Green else Color.Light_Red else if MACDX < MACDX[1] then Color.Light_Red else Color.Light_Green);
AddCloud(MACDX, MID, Color.Light_Green, Color.Light_Red);
# End Normalized MACD
 

Ramiii

New member
Good Evening everyone! I currently use the MACDHistogram as a big part of my trading strategy, usually you can preemtively call a reversal just by using the MACD when the fast moving MA becomes tangent. Is someone able to code to a seperate indicator that works in conjunction with MACD to draw a line when the graph of the line becomes tangent? I assume it would require the use of coding for derivatives in ToS, below I will attach an example of what i mean.

Here is an example of what I mean.

Example:

mY8E196.png
 

C-Note Johnson

New member
Hello Horserider, The MACD with Bollinger bands is very intriguing. I can't wait to try it in my ToS. Is it possible for you to create a shareable link ? If not, can you tell me how to get it into my ToS ? Thank you, SFR
 

J007RMC

Well-known member
2019 Donor
Code:
# MACDHistogramCrossover
# Paris
# Chatroom Request
# 8.30.2018

# Displays number of bars since the last MACDHistogram Crossover signal
# Added logic to display direction of last crossover signal

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;

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

def XUp;
def XDn;

if Crosses(Diff, 0, CrossingDirection.BELOW) {
    XUp = no;
    XDn = yes;
}
else if (Crosses(Diff, 0, CrossingDirection.ABOVE)) {
    XUp = yes;
    XDn = no;
}
else {
    XUp = XUp[1];
    XDn = XDn[1];
}

def crossBarUp = if XUp and !XUp[1] then BarNumber() else crossBarUp[1];
def crossBarDn = if XDn and !XDn[1] then BarNumber() else crossBarDn[1];

plot bullSig = if XUp and !XUp[1] then low else Double.NaN;
     bullSig.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
     bullSig.SetDefaultColor(Color.YELLOW);
     bullSig.SetLineWeight(3);

plot bearSig = if XDn and !XDn[1] then high else Double.NaN;
     bearSig.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
     bearSig.SetDefaultColor(Color.CYAN);
     bearSig.SetLineWeight(3);

AddLabel(1, "Bars since last MACD Histogram " +
    (if crossBarUp > crossBarDn then "BULLISH"
                                else "BEARISH") + " Crossover:  " +
    (if crossBarUp > crossBarDn then BarNumber() - crossBarUp
                                else BarNumber() - crossBarDn),
    if crossBarUp > crossBarDn then Color.YELLOW else Color.CYAN);

# END STUDY
 
Last edited by a moderator:

horserider

Well-known member
VIP
@Ahmar824 Good suggestion. Zero line added. Everyone code has been updated to add a zero line to show overall strength or weakness of MACD.
Update to the new code or add this to your study if you want a zero line.

plot zero = 0;
zero.setDefaultColor(color.LIGHT_ORANGE);
zero.setLineWeight (1) ;
 

J007RMC

Well-known member
2019 Donor

MACD Zero Lag

Code:
# Zero Lag MACD With Bollinger Bands
# Mobius
# V01.01.2018 Chat Room Request .0.19.2018

declare lower;

input fastLength = 13;
input slowLength = 34;
input MACDLength = 13;
input showBreakoutSignals = yes;

script EMA{
input length = 10;
input price = close;
def K = 2 / (length + 1);
def lag = (length - 1) / 2;
def ZLEMA = K * (2 * price - price[lag]) + (1 - K) * ZLEMA[1];
plot data = ZLEMA;
}
plot Value = EMA(length = fastLength) - EMA(length = slowLength);
def Avg = EMA(length = MACDLength, price = value);
plot Diff = Value - Avg;
def SD = StDev(Diff, MACDLength);
plot upper = Diff + SD;
plot lower = Diff - SD;
plot ZeroLine = 0;
Value.SetPaintingStrategy(PaintingStrategy.Line_Vs_Points);
Value.AssignValueColor(if Value > Value[1]
then color.green
else color.red);
Diff.SetStyle(Curve.Short_Dash);
Diff.SetLineWeight(1);
Diff.SetDefaultColor(color.gray);
upper.SetDefaultColor(color.gray);
lower.SetDefaultColor(color.gray);
ZeroLine.SetDefaultColor(GetColor(0));
ZeroLine.HideBubble();
ZeroLine.HideTitle();

# End Code Zero Lag MACD
 
Last edited by a moderator:

dolomick

Member
This is cool. Can you possibly add histogram crossover arrows like the default MACD has? I know this doesn't have a histogram but I thought maybe it could be added in the code, and then hidden, to allow the histogram crossover arrows to appear as another layer of confirmation. Thanks!
 

horserider

Well-known member
VIP
For what it is worth. Good luck .

Code:
# Ultimate MACD by Horserider 8/30/2019
# Standard version
# Also have short and long term versions. Can accomplish all three by just adjusting inputs to fit your trading style.
# Standard MACD 12,26,9 BB length 20.
# Short term MACD 6, 13, 6 BB length 5.
# Long term MACD 48, 104, 36 BBlength 20.
# Added zero line on suggestion of Ahmar824 1/12/2019.
# Added TRIX histogram 3/1/2019


declare lower;
input fastLength = 6;
input slowLength = 13;
input MACDLength = 6;
input AverageTypeMACD = {SMA, default EMA,  Wilders};

input price = close;
input displace = 0;

def MACD_Data = MACD(fastLength = fastLength, slowLength = slowLength, MACDLength = MACDLength);
plot MACD_Line = MACD_Data;

MACD_Line.DefineColor("Up", Color.GREEN);
MACD_Line.DefineColor("Down", Color.RED);
MACD_Line.DefineColor("Even", Color.WHITE);
MACD_Line.AssignValueColor(if MACD_Line > MACD_Line[1] then MACD_Line.Color("Up") else (if MACD_Line == MACD_Line[1] then MACD_Line.Color("Even") else MACD_Line.Color("Down")));
MACD_Line.SetLineWeight(3);

plot zero = 0;
zero.setDefaultColor(color.LIGHT_ORANGE);
zero.setLineWeight (1) ;

def Value;
plot Avg;
switch (AverageTypeMACD) {
case SMA:
    Value = Average(price, fastLength) - Average(price, slowLength);
    Avg = Average(Value, MACDLength);
case EMA:
    Value = ExpAverage(price, fastLength) - ExpAverage(price, slowLength);
    Avg = ExpAverage(Value, MACDLength);

case Wilders:
    Value = WildersAverage(price, fastLength) - WildersAverage(price, slowLength);
    Avg = ExpAverage(Value, MACDLength);
}
Avg.SetDefaultColor(Color.WHITE);


#plot BB;
#Bollinger BandsSMA,EMA
input AverageTypeBB = {default SMA, EMA, HMA};
input displaceBB = 0;
input lengthBB = 5;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;

plot upperBand;
plot lowerBand;
def midline;

switch (AverageTypeBB) {
case SMA:
    upperBand = reference BollingerBands(MACD_Line, displaceBB, lengthBB, Num_Dev_Dn, Num_Dev_up).UpperBand;
    lowerBand = reference BollingerBands(MACD_Line, displaceBB, lengthBB, Num_Dev_Dn, Num_Dev_up).LowerBand;
    midline   = reference BollingerBands(MACD_Line, displaceBB, lengthBB, Num_Dev_Dn, Num_Dev_up).Midline;
case EMA:
    upperBand = reference BollingerBands(MACD_Line, displaceBB, lengthBB, Num_Dev_Dn, Num_Dev_up, averageType = AverageType.EXPONENTIAL).UpperBand;
    lowerBand = reference BollingerBands(MACD_Line, displaceBB, lengthBB, Num_Dev_Dn, Num_Dev_up, averageType = AverageType.EXPONENTIAL).LowerBand;
    midline   = reference BollingerBands(MACD_Line, displaceBB, lengthBB, Num_Dev_Dn, Num_Dev_up, averageType = AverageType.EXPONENTIAL).Midline;
case HMA:
    upperBand = reference BollingerBands(MACD_Line, displaceBB, lengthBB, Num_Dev_Dn, Num_Dev_up, averageType = AverageType.EXPONENTIAL).UpperBand;
    lowerBand = reference BollingerBands(MACD_Line, displaceBB, lengthBB, Num_Dev_Dn, Num_Dev_up, averageType = AverageType.EXPONENTIAL).LowerBand;
    midline   = reference BollingerBands(MACD_Line, displaceBB, lengthBB, Num_Dev_Dn, Num_Dev_up, averageType = AverageType.EXPONENTIAL).Midline;
}

upperBand.SetDefaultColor(Color.GRAY);
upperBand.DefineColor("Up", Color.CYAN);
upperBand.DefineColor("Down", Color.PINK);
upperBand.DefineColor("Even", Color.GRAY);
upperBand.AssignValueColor(if upperBand > upperBand[1] and lowerBand < lowerBand[1] then upperBand.Color("Up") else (if upperBand < upperBand[1] and lowerBand > lowerBand[1] then upperBand.Color("Down") else upperBand.Color("Even")));
upperBand.SetLineWeight(2);

lowerBand.SetDefaultColor(Color.GRAY);
lowerBand.DefineColor("Up", Color.CYAN);
lowerBand.DefineColor("Down", Color.PINK);
lowerBand.DefineColor("Even", Color.GRAY);
lowerBand.AssignValueColor(if upperBand > upperBand[1] and lowerBand < lowerBand[1] then upperBand.Color("Up") else (if upperBand < upperBand[1] and lowerBand > lowerBand[1] then upperBand.Color("Down") else upperBand.Color("Even")));

plot midline1 = midline;

## Trix

input lengthtrix = 9;
input colorNormLength = 14;

input signalLength = 3;

def tr = ExpAverage(ExpAverage(ExpAverage(Log(price), lengthtrix), lengthtrix), lengthtrix);

plot TRIX = (tr - tr[1]) * 10000;
plot Signal = ExpAverage(TRIX, signalLength);
plot ZeroLine = 0;
TRIX.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
TRIX.DefineColor("Highest", Color.LIGHT_GREEN);
TRIX.DefineColor("Lowest", Color.LIGHT_RED);
TRIX.AssignNormGradientColor(colorNormLength, TRIX.color("Lowest"), TRIX.color("Highest"));
Signal.setDefaultColor(GetColor(3));
ZeroLine.SetDefaultColor(GetColor(5));
 

dvorakm

New member
2019 Donor
VIP
Hi! I can not seem to figure out how to edit MACD TwoLines code to use a different aggregation on a given chart. For example, I am needing the MACD TwoLines 30minute aggregation, but viewed on a 5minute chart. I thought simply adding "input agg = AggregationPeriod.thirty_MIN;" would do the trick, but I, of course, was wrong. It displays exactly the same as the MACD TwoLines on the 5minute chart. Any help would be greatly appreciated.
Code:
#
# TD Ameritrade IP Company, Inc. (c) 2007-2020
#

declare lower;

input fastLength = 8;
input slowLength = 21;
input MACDLength = 5;
input averageType = AverageType.EXPONENTIAL;
input agg = AggregationPeriod.thirty_MIN;

plot Value = MACD(fastLength, slowLength, MACDLength, averageType).Value;
plot Avg = MACD(fastLength, slowLength, MACDLength, averageType).Avg;
plot ZeroLine = 0;

Value.SetDefaultColor(GetColor(1));
Avg.SetDefaultColor(GetColor(8));
ZeroLine.SetDefaultColor(GetColor(0));
 
Last edited by a moderator:

Aliikhatami

New member
VIP
@horserider hey what do the blue gray and pink mean on bollingerbands? does blue mean the bands are expanding gray sideways and pink getting tighter? and if so how do you read that?
 

horserider

Well-known member
VIP
@Aliikhatami When bands are expanding ( upper is rising and lower is falling) the color is cyan. Volatility is increasing. When bands are staying same distance apart the color is gray. Could be sloped up or down but bands are moving the same direction and staying basically the same distance apart.
Pink is the bands moving closer together, squeezing. The longer the squeeze period the more likely a volatile period will follow.
 

Similar threads

Top