MACD MTF (Multi Time Frame) Indicator for ThinkorSwim

horserider

horserider

Well-known member
VIP
Here is a Multi Time frame MACD . Came up in discord so thought I would put it here also.

Code:
declare lower;
input midTermPeriod = {"1 min", "3 min", "5 min", "15 min", "30 min", "60 min", "120 min", "Daily", default "Weekly", "Monthly"};
input longTermPeriod = {"3 min", "5 min", "15 min", "30 min", "60 min", "120 min", "Daily", "Weekly", default "Monthly"};

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

input midTermFastLength = 12;
input midTermSlowLength = 26;
input midTermMACDLength = 9;

input longTermFastLength = 12;
input longTermSlowLength = 26;
input longTermMACDLength = 9;

def middleAggregation;

switch (midTermPeriod) {
    case "1 min":
        middleAggregation = AggregationPeriod.MIN;
    case "3 min":
        middleAggregation = AggregationPeriod.THREE_MIN;
    case "5 min":
        middleAggregation = AggregationPeriod.FIVE_MIN;
    case "15 min":
        middleAggregation = AggregationPeriod.FIFTEEN_MIN;
    case "30 min":
        middleAggregation = AggregationPeriod.THIRTY_MIN;
    case "60 min":
        middleAggregation = AggregationPeriod.HOUR;
    case "120 min":
        middleAggregation = AggregationPeriod.TWO_HOURS;
    case "Daily":
        middleAggregation = AggregationPeriod.DAY;
    case "Weekly":
        middleAggregation = AggregationPeriod.WEEK;
    case "Monthly":
        middleAggregation = AggregationPeriod.MONTH;
}

def highestAggregation;
switch (longTermPeriod) {
    case "3 min":
        highestAggregation = AggregationPeriod.THREE_MIN;
    case "5 min":
        highestAggregation = AggregationPeriod.FIVE_MIN;
    case "15 min":
        highestAggregation = AggregationPeriod.FIFTEEN_MIN;
    case "30 min":
        highestAggregation = AggregationPeriod.THIRTY_MIN;
    case "60 min":
        highestAggregation = AggregationPeriod.HOUR;
    case "120 min":
        highestAggregation = AggregationPeriod.TWO_HOURS;
    case "Daily":
        highestAggregation = AggregationPeriod.DAY;
    case "Weekly":
        highestAggregation = AggregationPeriod.WEEK;
    case "Monthly":
        highestAggregation = AggregationPeriod.MONTH;
}

DefineGlobalColor("UpTrend", color.GREEN);
DefineGlobalColor("DownTrend", color.RED);
DefineGlobalColor("NoTrend", color.LIGHT_GRAY);

def timeFrame = getAggregationPeriod();
def testTimeFrames = if timeFrame < middleAggregation and middleAggregation < highestAggregation then yes else no;

AddLabel(yes, if testTimeFrames  then "Time Frames Are Correct" else "Time Frames Are Wrong", if testTimeFrames  then color.GREEN else color.RED);

# This section is for the chart level MACD
def fastAvg = ExpAverage(close, fastLength);
def slowAvg = ExpAverage(close, slowLength);

plot Value = fastAvg - slowAvg;
Value.SetDefaultColor(color.CYAN);
plot Avg = ExpAverage(Value, MACDLength);
Avg.SetDefaultColor(color.YELLOW);
plot Diff = (value - avg)*3;

# This section is for the medium term MACD
def midTermFastAvg = ExpAverage(close(period = middleAggregation)[1] , midTermFastLength);
def midTermSlowAvg = ExpAverage(close(period = middleAggregation)[1] , midTermSlowLength);

def midTermValue = midTermFastAvg - midTermSlowAvg;
def midTermAvg = ExpAverage(midTermValue, midTermMACDLength);
plot midTermDiff = (midTermValue - midTermAvg)*3;
midTermDiff.Hide();
midTermDiff.HideBubble();

# This section is for the long term MACD
def longTermFastAvg = ExpAverage(close(period = highestAggregation)[1] , longTermFastLength);
def longTermSlowAvg = ExpAverage(close(period = highestAggregation)[1] , longTermSlowLength);

def longTermValue = longTermFastAvg - longTermSlowAvg;
def longTermAvg = ExpAverage(longTermValue, longTermMACDLength);
plot longTermDiff = (longTermValue - longTermAvg)*3;
longTermDiff.Hide();
longTermDiff.HideBubble();


def midTermLower = midTermDiff < midTermDiff[1];
def midTermHigher = midTermDiff > midTermDiff[1];
rec midTermSignal = if midTermLower then  yes  else if midTermSignal[1] == yes and midTermHigher == no then yes else no;
#plot test = midTermSignal;
def longTermLower = longTermDiff < longTermDiff[1];
def longTermHigher = longTermDiff > longTermDiff[1];
rec longTermSignal = if longTermLower then  yes  else if longTermSignal[1] == yes and longTermHigher == no then yes else no;

midTermDiff.AssignValueColor(if midTermSignal then color.RED else color.BLUE);
longTermDiff.AssignValueColor(if longTermSignal then color.RED else color.BLUE);

def upTrend = Diff > Diff[1] and midTermSignal == no and longTermSignal == no;
def downTrend = Diff < Diff[1] and midTermSignal == yes and longTermSignal == yes;

Diff.AssignValueColor(if upTrend then GlobalColor("UpTrend") else if downTrend then GlobalColor("DownTrend") else GlobalColor("NoTrend") );
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);

def longSignal = upTrend[1] == 1;
plot upTrendAlert = if longSignal  then 0 else Double.NaN;
upTrendAlert.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
upTrendAlert.SetDefaultColor(Color.CYAN);
upTrendAlert.SetLineWeight(3);
Alert(upTrendAlert == 0, "MTF Uptrend", Alert.BAR, Sound.RING);

def shortSignal = downTrend[1] == 1;
plot downTrendAlert = if shortSignal then 0 else Double.NaN;
downTrendAlert.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
downTrendAlert.SetDefaultColor(Color.MAGENTA);
downTrendAlert.SetLineWeight(3);
Alert(downTrendAlert == 0, "MTF Downtrend", Alert.BAR, Sound.RING);


plot zeroLine = if close[-1] > 0 then 0 else Double.Nan;
zeroLine.AssignValueColor(if Diff > Diff[1] and midTermSignal == no and longTermSignal == no then GlobalColor("UpTrend") else if Diff < Diff[1] and midTermSignal == yes and longTermSignal == yes then GlobalColor("DownTrend") else GlobalColor("NoTrend") );
zeroLine.SetPaintingStrategy(PaintingStrategy.POINTS);
zeroLine.SetLineWeight(3);
 
Shinthus

Shinthus

Member
2019 Donor
Nice! Great, easy to follow signals on SPY, especially.
 
J

joshuadstout

New member
2019 Donor
Warehouse
I tried this one and all I got was the histogram and chart is gone is all I see is MACD Hist.
 
horserider

horserider

Well-known member
VIP
@joshuadstout Hmmm just tried it worked fine. Give more details how you added it or show the chart. Maybe then it can be figured out. Or delete it and re add and see if that solves the problem.
 
J

joshuadstout

New member
2019 Donor
Warehouse
I got it Ty @horserider I think it was my computer.
 
Y

yamiyugi

New member
For the zero line it has grey and green color. Can someone enlighten me on such difference and its meaning?
 
T

tomsk

Well-known member
VIP
Here is the relevant section of the code that describes the condition you are interested in.
Basically if the variable "Diff" is uptrend, then GREEN is displayed. If downtrend then RED
Otherwise if no trend then GRAY is displayed

Code:
DefineGlobalColor("UpTrend", color.GREEN);
DefineGlobalColor("DownTrend", color.RED);
DefineGlobalColor("NoTrend", color.LIGHT_GRAY);

Diff.AssignValueColor(if upTrend then GlobalColor("UpTrend") 
                      else if downTrend then GlobalColor("DownTrend") 
                      else GlobalColor("NoTrend") );
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
 
Y

yamiyugi

New member
Here is the relevant section of the code that describes the condition you are interested in.
Basically if the variable "Diff" is uptrend, then GREEN is displayed. If downtrend then RED
Otherwise if no trend then GRAY is displayed

Code:
DefineGlobalColor("UpTrend", color.GREEN);
DefineGlobalColor("DownTrend", color.RED);
DefineGlobalColor("NoTrend", color.LIGHT_GRAY);

Diff.AssignValueColor(if upTrend then GlobalColor("UpTrend")
                      else if downTrend then GlobalColor("DownTrend")
                      else GlobalColor("NoTrend") );
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Alright, thanks tomsk. Coz in my chart i only have green and grey color but no red color. Appreciate your advice.
 
T

tomsk

Well-known member
VIP
What does it mean when it says time frames are wrong?
@Miket This likely means the aggregation period selection for the study is incorrect
Within the code, there are 2 aggregation periods to choose - midTermPeriod and longTermPeriod
Make sure the aggregation period for midTermPeriod is less than the aggregation period of longTermPeriod
The other REQUIREMENT is that the aggregation of the chart you're on must not be larger than the midTermPeriod agg.

For example, if your selection for midTermPeriod is 5 min and for longTermPeriod is 15 min, then your chart aggregation must be 5 mins or less
If you're interested here is the code snippet that details this

Code:
def timeFrame = getAggregationPeriod();
def testTimeFrames = if timeFrame < middleAggregation and
                        middleAggregation < highestAggregation
                     then yes
                     else no;

AddLabel(yes, if testTimeFrames  then "Time Frames Are Correct" else "Time Frames Are Wrong", if testTimeFrames  then color.GREEN else color.RED);
 
Y

ykd2018x

Member
2019 Donor
can anybody convert this code to tos script and back test stretergy ??

the original post is a weekly script of trading view , link is below , appricate and thanks for help and taking interst in advance
.

https://www.tradingview.com/script/34lAHcyo-MACD-Multi-MA-Strategy/?utm_source=weekly_digest&utm_medium=email&utm_campaign=weekly_digest_idea&utm_source=TradingView&utm_campaign=c9fcf3d090-EMAIL_CAMPAIGN_2019_07_12_06_35_COPY_01&utm_medium=email&utm_term=0_d411e4719e-c9fcf3d090-277452033

Code:
//@version=2
strategy(title="MACD Multi-MA Strategy", overlay=false, calc_on_order_fills=true, initial_capital=100000, default_qty_type=strategy.percent_of_equity, currency="USD", default_qty_value=100)

src = close
len1 = input(8, "FAST LOOKBACK")
len2 = input(144, "SLOW LOOKBACK")

/////////////////////////////////////////////
length = len2-len1
ma = vwma(src, length)
plot(ma, title="VWMA", color=lime)


length1 = len2-len1
ma1 = rma(src, length1)
plot(ma1, title="RMA", color=purple)

length2 = len2-len1
ma2 = sma(src, length2)
plot(ma2, title="SMA", color=red)


length3 = len2-len1
ma3 = wma(src, length3)
plot(ma3, title="WMA", color=orange)

length4 = len2-len1
ma4 = ema(src, length4)
plot(ma4, title="EMA", color=yellow)





long = ma > ma[1] and ma1 > ma1[1] and ma2 > ma2[1] and ma3 > ma3[1] and ma4 > ma4[1]
short = ma < ma[1] and ma1 < ma1[1] and ma2 < ma2[1] and ma3 < ma3[1] and ma4 < ma4[1]


strategy.entry("Long", strategy.long, when=long)
strategy.entry("Short", strategy.short, when=short)
 
Last edited by a moderator:
D

diazlaz

Well-known member
2019 Donor
VIP
Hi @ykd2018x

thanks for sharing - looked interesting, here is an initial port and my interpretation of it, all, please feel free to tweak and make adjustments.



Setup:



Ruby:
#MACD Multi-MA for ThinkorSwim V1.0
#
#CREDITS
# Craig_Claussen
# https://www.tradingview.com/script/34lAHcyo-MACD-Multi-MA-Strategy
#
#CHANGELOG
# 2019.12.05 1.0 @diazlaz - Initial Port

#
#
#DESCRIPTION
# This script applies the average of each major MA ( SMA , RMA, EMA , WVMA, WMA )
# to the MACD formula
#
#
#INSTRUCTIONS
# Add to upper and lower study
# Set upper = showArrows = yes; ColorBars = yes; showPlots = no;
# Set lower = showArrows = no; ColorBars = no; showPlots = yes;
#
#

#INPUTS
input src = close;
input len1 = 8; #Fast Lookback
input len2 = 144; #Slow Lookback
input showPlots = yes; #show MA plots (lower study)
input showArrows = no; #show Arrows (upper study)
input showColorBars = no; #show color bars (optional upper study)

#CORE
def length = len2-len1;
def ma = sum(src * volume, length) / sum(volume,length);

def length1 = len2-len1;
def ma1 = MovingAverage(AverageType.WEIGHTED, src, length1);

def length2 = len2-len1;
def ma2 = Average(src, length2);

def length3 = len2-len1;
def ma3 = wma(src, length3);

def length4 = len2-len1;
def ma4 = ExpAverage(src, length4);

#STATES
def long = ma > ma[1] and ma1 > ma1[1] and ma2 > ma2[1] and ma3 > ma3[1] and ma4 > ma4[1];
def short = ma < ma[1] and ma1 < ma1[1] and ma2 < ma2[1] and ma3 < ma3[1] and ma4 < ma4[1];
def sState = if long then 100 else if short then -100 else sState[1];

#PLOTS
plot pMA1 = ma1;
plot pMA2 = ma2;
plot pMA3 = ma3;
plot pMA4 = ma4;
pMA1.SetHiding(!showPlots);
pMA2.SetHiding(!showPlots);
pMA3.SetHiding(!showPlots);
pMA4.SetHiding(!showPlots);

# ARROWS
plot pUP = sState crosses above 0;
pUP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
pUP.SetDefaultColor(Color.GREEN);
pUP.SetLineWeight(2);
pUP.SetHiding(!showArrows);

plot pDown = sState crosses below 0;
pDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
pDown.SetDefaultColor(Color.RED);
pDown.SetLineWeight(2);
pDown.SetHiding(!showArrows);

#COLORBARS
AssignPriceColor(if showColorBars then
if sState > 0 then Color.GREEN
  else Color.RED
else
  COLOR.CURRENT
);

#END OF MACD Multi-MA for ThinkorSwim V1.0
 
J007RMC

J007RMC

Active member
2019 Donor
Warehouse
VIP
I came across this macd study and I rather like it


Code:
plot Data = close;# MACD by the math
# Mobius
# Mobius at MyTrade

declare lower;

input agg1 = AggregationPeriod.Day;
input agg2 = AggregationPeriod.Hour;
Input fastEMA = 13;
Input slowEMA = 21;
Input Smooth  =  8;
def value   = close;
def value2 = close(period = agg1);
def value3 = close(period = agg2);

  def FSignal = (value * .15) +  (.85  * ExpAverage(value, fastEMA)[1]);
  def SSignal = (value * .075) + (.925 * ExpAverage(value, slowEMA)[1]);
plot MACD    = FSignal - SSignal;
plot MACDSL  = ExpAverage(MACD, Smooth);
plot zero    = 0;

     MACD.SetpaintingStrategy(PaintingStrategy.Line);
     MACD.SetLineWeight(2);
     MACD.AssignValueColor(if MACD > MACD[1] and MACD[1] > MACD[2]
                           then Color.Green else Color.Red);
     MACDSL.AssignValueColor(if MACDSL > MACDSL[1] and MACDSL[1] > MACDSL[2]
                             then Color.Blue else Color.Yellow);

  def FSignal2 = (value2 * .15) +  (.85  * ExpAverage(value2, fastEMA)[1]);
  def SSignal2 = (value2 * .075) + (.925 * ExpAverage(value2, slowEMA)[1]);
plot MACD2   = FSignal2 - SSignal2;
plot MACDSL2  = ExpAverage(MACD2, Smooth);

     MACD2.SetpaintingStrategy(PaintingStrategy.Line);
     MACD2.SetLineWeight(2);
     MACD2.AssignValueColor(if MACD2 > MACD2[1] and MACD2[1] > MACD2[2]
                           then Color.White else Color.Plum);
     MACDSL2.AssignValueColor(if MACDSL2 > MACDSL2[1] and MACDSL2[1] > MACDSL2[2]
                             then Color.Orange else Color.Dark_Orange);

  def FSignal3 = (value3 * .15) +  (.85  * ExpAverage(value3, fastEMA)[1]);
  def SSignal3 = (value3 * .075) + (.925 * ExpAverage(value3, slowEMA)[1]);
plot MACD3    = FSignal3 - SSignal3;
plot MACDSL3  = ExpAverage(MACD3, Smooth);


     MACD3.SetpaintingStrategy(PaintingStrategy.Line);
     MACD3.SetLineWeight(2);
     MACD3.AssignValueColor(if MACD3 > MACD3[1] and MACD3[1] > MACD3[2]
                           then Color.Gray else Color.Cyan);
     MACDSL3.AssignValueColor(if MACDSL3 > MACDSL3[1] and MACDSL3[1] > MACDSL3[2]
                             then Color.Magenta else Color.Pink);


# End Code
[CODE]
 
Last edited:
J007RMC

J007RMC

Active member
2019 Donor
Warehouse
VIP
Came across a Mobius range indicator GACD it appears to be very telling I'm using this on intraday.
Code:
plot Data = close;# GACD (G)aussian (A)verage (C)onvergence (D)ivergence
# Mobius
# V01.01.2019
# Study shows Long Term Trend with shading above and below the zero line. Short Term Trend with faster and slower Gaussian Average color line plots. Convergence and Divergence is displayed by the Histogram. Crosses of the Averages and therefore crosses of the Histogram above an below zero are marked with corresponding colored vertical lines. A label has been added to remind the user of trend indication.
# Note: This study plots on Mobile without some of the features.

declare lower;

input length  = 21;
input length2 = 34;
input length3 = 21;

script G 
    {
    input iData = close;
    input length = 21;
    def h = high;
    def l = low;
    def c = close;
    def betaDenom = 10 * (Log(Sum((Max(h, c[1]) - Min(l, c[1])), length) /
            (Highest(h, length) - Lowest(l, length)))
            / Log(length));
    def w = (2 * Double.Pi / length);
    def beta = (1 - Cos(w)) / (Power(1.414, 2.0 / betaDenom) - 1 );
    def alpha = (-beta + Sqrt(beta * beta + 2 * beta));
    def G = Power(alpha, 4) * iData + 
                 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 data = G;
}
plot a = G(close, length) - G(close, length2);
plot b = G(a, length3);
plot d = a - b;
plot "0" = if IsNaN(close) 
           then Double.NaN 
           else 0;
"0".SetDefaultColor(Color.WHITE);
"0".HideTitle();
a.AssignValueColor(if a > b 
                        then Color.GREEN 
                        else Color.RED);
a.HideBubble();
a.HideTitle();
b.AssignValueColor(if a > b 
                        then Color.GREEN 
                        else Color.RED);
b.HideBubble();
b.HideTitle();
d.SetLineWeight(4);
d.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
d.AssignValueColor(if d > 0 and d > d[1] 
                        then Color.GREEN
                        else if d > 0 and d < d[1] 
                             then Color.BLUE
                             else if d < 0 and d < d[1] 
                             then Color.RED
                        else Color.YELLOW);
d.HideBubble();
AddCloud(a, b, Color.GREEN, Color.RED);
AddVerticalLine(d crosses 0, "", if d crosses above 0 
                                 then Color.GREEN 
                                 else Color.RED);
AddCloud(if Max(a, b) < 0 
         then Max(a, b) 
         else Double.NaN, 0, Color.LIGHT_RED, Color.LIGHT_RED);
AddCloud(if Min(a, b) > 0
         then 0 
         else Double.NaN, Min(a, b), Color.LIGHT_GREEN, Color.LIGHT_GREEN);
AddLabel(1, if Max(a, b) < 0 and a < b
            then "Trend Down"
            else if Max(a, b) < 0 and a > b
            then "Trend Down Slowing"
            else if between(0, b, a) and d > d[1]
            then "Trend Reversing"
            else if Min(a, b) > 0 and a > b
            then "Trend Up"
            else if Min(a, b) > 0 and a < b
            then "Trend Up Slowing"
            else if Min(a, b) > 0 and d > d[1]
            then "Trend Up Accelerating"
            else if Min(a, b) > 0 and a < b and  d < d[1]
            then "Trend Up decelerating"
            else "Undetermined Trend", if Max(a, b) < 0
                                       then color.light_red
                                       else if Min(a, b) > 0
                                       then color.light_green
                                       else color.white);
           
# End Code GACD
 
E

emm11

New member
I came across this macd study and I rather like it


Code:
plot Data = close;# MACD by the math
# Mobius
# Mobius at MyTrade

declare lower;

input agg1 = AggregationPeriod.Day;
input agg2 = AggregationPeriod.Hour;
Input fastEMA = 13;
Input slowEMA = 21;
Input Smooth  =  8;
def value   = close;
def value2 = close(period = agg1);
def value3 = close(period = agg2);

  def FSignal = (value * .15) +  (.85  * ExpAverage(value, fastEMA)[1]);
  def SSignal = (value * .075) + (.925 * ExpAverage(value, slowEMA)[1]);
plot MACD    = FSignal - SSignal;
plot MACDSL  = ExpAverage(MACD, Smooth);
plot zero    = 0;

     MACD.SetpaintingStrategy(PaintingStrategy.Line);
     MACD.SetLineWeight(2);
     MACD.AssignValueColor(if MACD > MACD[1] and MACD[1] > MACD[2]
                           then Color.Green else Color.Red);
     MACDSL.AssignValueColor(if MACDSL > MACDSL[1] and MACDSL[1] > MACDSL[2]
                             then Color.Blue else Color.Yellow);

  def FSignal2 = (value2 * .15) +  (.85  * ExpAverage(value2, fastEMA)[1]);
  def SSignal2 = (value2 * .075) + (.925 * ExpAverage(value2, slowEMA)[1]);
plot MACD2   = FSignal2 - SSignal2;
plot MACDSL2  = ExpAverage(MACD2, Smooth);

     MACD2.SetpaintingStrategy(PaintingStrategy.Line);
     MACD2.SetLineWeight(2);
     MACD2.AssignValueColor(if MACD2 > MACD2[1] and MACD2[1] > MACD2[2]
                           then Color.White else Color.Plum);
     MACDSL2.AssignValueColor(if MACDSL2 > MACDSL2[1] and MACDSL2[1] > MACDSL2[2]
                             then Color.Orange else Color.Dark_Orange);

  def FSignal3 = (value3 * .15) +  (.85  * ExpAverage(value3, fastEMA)[1]);
  def SSignal3 = (value3 * .075) + (.925 * ExpAverage(value3, slowEMA)[1]);
plot MACD3    = FSignal3 - SSignal3;
plot MACDSL3  = ExpAverage(MACD3, Smooth);


     MACD3.SetpaintingStrategy(PaintingStrategy.Line);
     MACD3.SetLineWeight(2);
     MACD3.AssignValueColor(if MACD3 > MACD3[1] and MACD3[1] > MACD3[2]
                           then Color.Gray else Color.Cyan);
     MACDSL3.AssignValueColor(if MACDSL3 > MACDSL3[1] and MACDSL3[1] > MACDSL3[2]
                             then Color.Magenta else Color.Pink);


# End Code
[CODE]

what are all the studies on your photo there if you dont mind sharing? Thanks
 
J007RMC

J007RMC

Active member
2019 Donor
Warehouse
VIP
ZERO LAG MACD WITH BOLLINGER BANDS.

I watch for an underder the bands or zero level to take trades its very responsive



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
 

Top