Adding breakouts and DSS to MACD indicator for ThinkorSwim?

H

HighBredCloud

Active member
@HighBredCloud I enjoyed collaborating with you once again. Glad to hear it is working well :)

Thanks for the optimized parameters. I'll make sure to take a look...

Good Luck and Good Trading :)
Same here...You always seem to get what I am asking for exactly! I am looking at a modified Mobius MACD that I found somewhere down the grapevine...It does not have the breakout signals and I am not sure how adding a DSS line like the one you did before on both the Stochastic Momentum Index and on FULL Stochastics would work with that modified MACD. If you're interested to try let me know...The MACD itself is very smooth as far as lines go. Could be something to build other variations of MACD on...but I don't know.
 
H

HighBredCloud

Active member
@netarchitech Cool...If you could add the breakout signals to the Mobius version MACD using the same format as the standard MACD found in TOS. I was also thinking if it's possible to add the DSS line from the Stochastic Momentum Index indicator that you made previously.

Also I have recently found a HULL Moving average suite that contains regular HULL MA...but also has EHMA and THMA...Would that be possible to add a drop down menu and add the two additional MA's to the already preloaded MA's (Simple, Exponential, Weighted, Wilders, Hull) found in the standard MACD version? This would come in handy for anyone looking to have an all in one MACD like this...I just don't know what you would name the standard type that is found in Mobius MACD because its so smooth. Gaussian perhaps? Unless you know the real type used.

Will post the HULL Suite next...from there IF you could just add the THMA and EHMA moving averages to the rest of the list as mentioned above...if its possible...I have back tested regular Hull vs THMA and EHMA and there are differences on regular candlesticks especially on higher timeframes...I am not sure how that would react with the MACD settings if the divergence would be enhanced or not or even if the crossovers would come sooner...not sure.

Code:

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.

declare lower;

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

# 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));
# End Code Modified MACD - Gaussian
 
H

HighBredCloud

Active member
@netarchitech Hull Suite

Code:

Code:
#Basic Hull Ma Pack tinkered by InSilico
#Original Port from https://www.tradingview.com/script/hg92pFwS-Hull-Suite
#
#2019.10.30 1.0 [USER=258]@diazlaz[/USER] - Original Port
#

#INPUTS

input modeSwitch = {default "Hma", "Thma", "Ehma"}; #Hull Variation
input length = 55; #Length(180-200 for floating S/R , 55 for swing entry)
input switchColor = yes; #Color Hull according to trend?
input candleCol = yes; #Color candles based on Hull's Trend?
input visualSwitch = yes; #Show as a Band?
input thicknesSwitch = 2; #Line Thickness
input showLabels = yes;
input src = close; #Source

addLabel (showLabels, modeSwitch, COLOR.ORANGE);
def na = Double.NaN;

# HMA

def hma;
switch (modeSwitch) {
case "Hma":
    hma = wma(2 * wma(src, length / 2) - wma(src, length), round(sqrt(length)));
case "Ehma":
    hma = expAverage(2 * expAverage(src, length / 2) - expAverage(src, length), round(sqrt(length)));
case "Thma":
    hma = wma(wma(src,(length/2) / 3) * 3 - wma(src, (length/2) / 2) - wma(src, (length/2)), (length/2));
}

# PLOTS

def HULL = hma;
def MHULL = HULL[0];
def SHULL = HULL[2];

plot Fi1 = MHULL;
Fi1.AssignValueColor(
if HULL > HULL[2] then COLOR.MAGENTA else COLOR.CYAN
);
Fi1.SetLineWeight(thicknesSwitch);

plot Fi2 = SHULL;
Fi2.AssignValueColor(
if HULL > HULL[2] then COLOR.MAGENTA else COLOR.CYAN
);
Fi2.SetLineWeight(thicknesSwitch);
Fi2.SetHiding(!visualSwitch);

AddCloud (if visualSwitch then Fi1 else na, Fi2);

# COLORBARS
AssignPriceColor(
if !candleCol then
Color.CURRENT
else
if HULL > HULL[2] then COLOR.MAGENTA else COLOR.CYAN
);

#END OF HULL
 
Last edited by a moderator:
H

HighBredCloud

Active member
@netarchitech Here is the Stochastic Momentum Index with the DSS line that you made previously...in case you need the code.

Code:

Code:
# Stochastic_Momentum_Index
# original author: TDAmeritrade
# enhancements: netarchitech
# 10.20.2019


declare lower;

input over_bought = 40.0;
input over_sold = -40.0;
input percentDLength = 3;
input percentKLength = 5;
input showBreakoutSignals = {default "No", "On SMI", "On AvgSMI", "On SMI & AvgSMI"};

def min_low = lowest(low, percentKLength);
def max_high = highest(high, percentKLength);
def rel_diff = close - (max_high + min_low)/2;
def diff = max_high - min_low;

def avgrel = expaverage(expaverage(rel_diff, percentDLength), percentDLength);
def avgdiff = expaverage(expaverage(diff, percentDLength), percentDLength);

plot SMI = if avgdiff != 0 then avgrel / (avgdiff / 2) * 100 else 0;
smi.setDefaultColor(getColor(1));
smi.setLineWeight(2);

plot AvgSMI = expaverage(smi, percentDLength);
avgsmi.setDefaultColor(getcolor(5));
avgsmi.setLineWeight(2);

plot overbought = over_bought;
overbought.setDefaultColor(getcolor(4));

plot oversold = over_sold;
oversold.setDefaultColor(getcolor(4));

# Slow 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);
DSSsignal.SetLineWeight(3);

def upSMI = SMI crosses above OverSold;
def upAvgSMI = AvgSMI crosses above OverSold;
def downSMI = SMI crosses below OverBought;
def downAvgSMI = AvgSMI crosses below OverBought;

plot UpSignal;
plot DownSignal;
switch (showBreakoutSignals) {
case "No":
    UpSignal = Double.NaN;
    DownSignal = Double.NaN;
case "On SMI":
    UpSignal = if upSMI then OverSold else Double.NaN;
    DownSignal = if downSMI then OverBought else Double.NaN;
case "On AvgSMI":
    UpSignal = if upAvgSMI then OverSold else Double.NaN;
    DownSignal = if downAvgSMI then OverBought else Double.NaN;
case "On SMI & AvgSMI":
    UpSignal = if upSMI or upAvgSMI then OverSold else Double.NaN;
    DownSignal = if downSMI or downAvgSMI then OverBought else Double.NaN;
}

UpSignal.setHiding(showBreakoutSignals == showBreakoutSignals."No");
DownSignal.setHiding(showBreakoutSignals == showBreakoutSignals."No");

OverBought.SetDefaultColor(GetColor(4));
OverSold.SetDefaultColor(GetColor(4));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
UpSignal.SetLineWeight(3);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
DownSignal.SetLineWeight(3);
 
Last edited by a moderator:
netarchitech

netarchitech

Active member
VIP
Warehouse
@HighBredCloud WOW! I guess I've got some work to do ;) Good thing the weekend is coming up :)

Thanks for rounding up all the code...I'll start digging in first thing tomorrow...
 
H

HighBredCloud

Active member
@HighBredCloud WOW! I guess I've got some work to do ;) Good thing the weekend is coming up :)

Thanks for rounding up all the code...I'll start digging in first thing tomorrow...
@netarchitech Its all good...I didn't mean to overwhelm you with work. Do this whenever you have time no rush at all...I just thought it would be a good idea to have an indicator such as that and I hope there is value in the hard work that you're putting in...Like with everything else...trail and error until something happens...even if it is by accident...

I am back testing the Mobius MACD as we speak on a 15m chart as we speak. I just can't figure out what indicator to use as an exit IF such an indicator as the Mobius MACD is used as an entry other than getting out on a smaller timeframe when a target profit is met. I keep seeing the change on the histogram from bright green to dark green as a possible exit just need a confirmation. If you have any ideas let me know...till then I am watching the DSS line alongside to see if that would help out to either stay in the trade or get out of one.
 
netarchitech

netarchitech

Active member
VIP
Warehouse
If you could add the breakout signals to the Mobius version MACD using the same format as the standard MACD found in TOS.
OK...Thought I would start tonight, instead of tomorrow :) The breakout signals are added. Let me know if there are any adjustments needed...

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);
 
H

HighBredCloud

Active member
@netarchitech Breakout signals are working perfectly!...The menu to turn them off and on is also great. Can you make that same type of menu when you add on the average types? I really want to see how EHMA and THMA compare to the rest...The average type that Mobius used is very interesting all on its own. If you have any other ideas how to improve or add on to this please feel free...
 
netarchitech

netarchitech

Active member
VIP
Warehouse
@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...



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);
 
H

HighBredCloud

Active member
@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...



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);
@netarchitech Wow...You've done so much tonight...Looks great...I see the issue with the DSS line...Hopefully someone has some ideas.
 
H

horserider

Well-known member
VIP
Warehouse
Scaling differences from 0 to 100 and a centered on 0 scale.
Change your histogram colors to ;
RED for Negative and down
Dark Green for Negative and up
Dark RED for Positive and down
Green for Positive and Up
 
H

HighBredCloud

Active member
@netarchitech I was looking over some indicators I had...IF the DSS will continue to be an issue with scaling as mentioned by @horserider Perhaps maybe abandon the DSS...and use Mobius Forward Reverse EMA instead. The idea I had with the DSS line to begin with was for it to hit faster than the MACD would in terms of the cross over...while still having the histogram to identify divergence. ForwardReverseEMA seems to also do that...Here is the code below incase you wanna try that as well...All suggestions are welcomed if anyone has any.

Code:

# Forward / Reverse EMA
# (c) 2017 John F. Ehlers
# Ported to TOS 07.16.2017
# Mobius

declare lower;

# Inputs:
input AA = .1;

# Vars:
def CC;
def RE1;
def RE2;
def RE3;
def RE4;
def RE5;
def RE6;
def RE7;
def RE8;
def EMA;
plot Signal;
plot plot0;

CC = if CC[1] == 0 then .9 else 1 – AA;
EMA = AA * Close + CC * EMA[1];
RE1 = CC * EMA + EMA[1];
RE2 = Power(CC, 2) * RE1 + RE1[1];
RE3 = Power(CC, 4) * RE2 + RE2[1];
RE4 = Power(CC, 8) * RE3 + RE3[1];
RE5 = Power(CC, 16) * RE4 + RE4[1];
RE6 = Power(CC, 32) * RE5 + RE5[1];
RE7 = Power(CC, 64) * RE6 + RE6[1];
RE8 = Power(CC, 128) * RE7 + RE7[1];

Signal = EMA – AA * RE8;
signal.AssignValueColor(if Signal > Signal[1]
then color.green
else color.red);
Plot0 = if isNaN(close) then double.nan else 0;
Plot0.SetDefaultColor(Color.gray);
addCloud(0, Signal, color.red, color.green);
# End Code Ehlers Forward / Reverse EMA
 
netarchitech

netarchitech

Active member
VIP
Warehouse
@HighBredCloud Thanks for the Forward/Reverse EMA...I've plugged it in as shown below...



Scaling differences from 0 to 100 and a centered on 0 scale.
Thanks for the tip, @horserider...I would agree with you about scaling differences except that I applied the DSS Line to the Stochastic Momentum Index, which is also centered on a zero scale, and it worked...

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
# V11.01.2019 - netarchitech added Ehlers and Mobius Forward/Reverse EMA 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));
#Value.SetLineWeight(2);
Avg.SetDefaultColor(GetColor(8));
#Avg.SetLineWeight(2);
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);


# Forward / Reverse EMA
# (c) 2017 John F. Ehlers
# Ported to TOS 07.16.2017
# Mobius

# Inputs:
input AA = .1;

# Vars:
def CC;
def RE1;
def RE2;
def RE3;
def RE4;
def RE5;
def RE6;
def RE7;
def RE8;
def EMA;
plot Signal;
plot plot0;

CC = if CC[1] == 0 then .9 else 1 – AA;
EMA = AA * Close + CC * EMA[1];
RE1 = CC * EMA + EMA[1];
RE2 = Power(CC, 2) * RE1 + RE1[1];
RE3 = Power(CC, 4) * RE2 + RE2[1];
RE4 = Power(CC, 8) * RE3 + RE3[1];
RE5 = Power(CC, 16) * RE4 + RE4[1];
RE6 = Power(CC, 32) * RE5 + RE5[1];
RE7 = Power(CC, 64) * RE6 + RE6[1];
RE8 = Power(CC, 128) * RE7 + RE7[1];

Signal = EMA – AA * RE8;
Signal.AssignValueColor(if Signal > Signal[1]
                        then Color.CYAN
                        else Color.MAGENTA);
Signal.SetLineWeight(3);
Plot0 = if isNaN(close) then double.nan else 0;
Plot0.SetDefaultColor(Color.GRAY);

#addCloud(0, Signal, color.RED, color.GREEN);
Hope this helps :)

@HighBredCloud I'll start working on the Moving Average addition today...will keep you posted...
 
H

horserider

Well-known member
VIP
Warehouse
SMI has a normal range of values between +100 and -100
So the 0 to 100 of DSS fit
 
H

HighBredCloud

Active member
@netarchitech Wow...very cool...Testing this right now as we speak...ONLY changes I made was change the signal colors from the cyan/magenta to green/red to avoid color blend. I will leet you know my finding as I am comparing this MACD study to the Stochastic Momentum Index with the DSS line. I can tell you right now that looking at SHOP at opening bell until 9 AM CST...DSS was showing a down signal even tho the price was going up...The MACD was showing the correct trend of the stock.

I have also changed the settings to 8,17,9 from 12, 26, 9 to speed up the cross over on the MACD but NOT engaging in the trade until the Forward/Reverse EMA also changes color to avoid fake breakouts...but will monitor both settings as Mobius used a very unique average type.

For reference I am also using TMO indicator with the Fisher Transform to see how this MACD compares to the two other studies that I mentioned. I think having the Forward/Reverse EMA was a better call that you implemented now that I have the studies side by side...
 
H

HighBredCloud

Active member
@netarchitech I just had an idea...Not sure if I am reaching too high with this one...But here goes...Is there a way where you can incorporate a choice of a moving average on the Forward/Reverse EMA line but stand alone and with its own separate menu? Like for example...a drop separate menu where the user can select another moving average type to replace the Forward/Reverse EMA with to go along with the MACD Value and AVG lines? On my charts I have a separate EHMA line from the HULL Suite that I posted...but I would be curious how something like that would play out with having an option to replace the Forward/Reverse EMA with would work.

From my end the way that I would go about it is IF someone wants to use something other than the Forward/Reverse EMA they can just un-click the show plot box and with the secondary drop down select a moving average of their own choice. What do you think? I will let you finish adding the moving averages because I do want to see how those would work on the VALUE and AVG cross overs and divergence and we can go from there...just keep that in mind when you're coding to see if such a request would be doable.
 
netarchitech

netarchitech

Active member
VIP
Warehouse
SMI has a normal range of values between +100 and -100
So the 0 to 100 of DSS fit
Aha! Learn something new everyday... Thanks, @horserider I appreciate the insights :)

@HighBredCloud I'm glad to hear again that the enhancements so far are helpful. As always, I look forward to your findings when you have a chance...

Is there a way where you can incorporate a choice of a moving average on the Forward/Reverse EMA line but stand alone and with its own separate menu? Like for example...a drop separate menu where the user can select another moving average type to replace the Forward/Reverse EMA with to go along with the MACD Value and AVG lines?
I'll do my best and give it a shot :) First, I've got to see if I can successfully implement the multiple Moving Averages code, as your latest requests appear to rely upon it...With that said, time to get back to work 🕑
 
netarchitech

netarchitech

Active member
VIP
Warehouse
@HighBredCloud Below please find the latest iteration of the code. While I have been able to get the multiple moving average interface to work, unfortunately, I cannot get the Forward/Reverse EMA to respond...Frustrating...Looks like I'm going to have to distract myself for a while in order for my subconscious to hopefully find a solution... :) In the meantime, let me know if there are any adjustments to the multiple moving average interface needing to be made...

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
# V11.01.2019 - netarchitech added Ehlers and Mobius Forward/Reverse EMA 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);

# Forward / Reverse EMA
# (c) 2017 John F. Ehlers
# Ported to TOS 07.16.2017
# Mobius

# Inputs:
input AA = .1;

# Vars:
def CC;
def RE1;
def RE2;
def RE3;
def RE4;
def RE5;
def RE6;
def RE7;
def RE8;
def EMA;
plot Signal;
plot plot0;

CC = if CC[1] == 0 then .9 else 1 – AA;
EMA = AA * Close + CC * EMA[1];
RE1 = CC * EMA + EMA[1];
RE2 = Power(CC, 2) * RE1 + RE1[1];
RE3 = Power(CC, 4) * RE2 + RE2[1];
RE4 = Power(CC, 8) * RE3 + RE3[1];
RE5 = Power(CC, 16) * RE4 + RE4[1];
RE6 = Power(CC, 32) * RE5 + RE5[1];
RE7 = Power(CC, 64) * RE6 + RE6[1];
RE8 = Power(CC, 128) * RE7 + RE7[1];

Signal = EMA – AA * RE8;
Signal.AssignValueColor(if Signal > Signal[1]
                        then Color.GREEN
                        else Color.RED);
Signal.SetLineWeight(3);

Plot0 = if isNaN(close) then double.nan else 0;
Plot0.SetDefaultColor(Color.GRAY);

#addCloud(0, Signal, color.RED, color.GREEN);


input modeswitch = {default "Value", "Avg", "Diff", "Signal", "EMA"};

input modeSwitch_ma = {default "Simple", "Exponential", "Weighted", "Wilders", "Hull", "EHMA", "THMA"}; 

input ma_length = 55; #Length(180-200 for floating S/R , 55 for swing entry)


def ma_calc;

switch (modeSwitch) {

case "Value":
ma_calc = g(length = fastLength) - g(length = slowLength);

case "Avg":
ma_calc = g(price = Value, length = MACDLength);

case "Diff":
ma_calc = Value - Avg;

case "Signal":
ma_calc = EMA – AA * RE8;

case "EMA":
ma_calc = AA * Close + CC * EMA[1];

}
;


def multi_ma;

switch (modeSwitch_ma) {

case "Simple":
multi_ma = average(ma_calc, ma_length);

case "Exponential":
multi_ma = expaverage(ma_calc, ma_length);

case "Weighted":
multi_ma = wma(ma_calc, ma_length);

case "Wilders":
multi_ma = wildersaverage(ma_calc, ma_length);

case "Hull":
multi_ma = wma(2 * wma(ma_calc, ma_length / 2) - wma(ma_calc, ma_length), round(sqrt(ma_length)));

case "EHMA":
multi_ma = expaverage(2 * expaverage(ma_calc, ma_length / 2) - expaverage(ma_calc, ma_length), round(sqrt(ma_length)));

case "THMA":
multi_ma = wma(wma(ma_calc,(ma_length/2) / 3) * 3 - wma(ma_calc, (ma_length/2) / 2) - wma(ma_calc, (ma_length/2)), (ma_length/2));

}
;
 
H

HighBredCloud

Active member
@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)
 

Top