MACD_FREMA Indicator for ThinkorSwim

netarchitech

netarchitech

Well-known member
VIP
Warehouse
@HighBredCloud GOT IT! 👍

MACD/FREMA now has the ability to harness 12 different Moving Averages! Below is a sample of 5 for your review:



And the code is below:

Code:
# filename: MR__EZ_MACD_FREMA_
# source: https://usethinkscript.com/threads/blast-off-indicator-for-thinkorswim.621/post-7785

# 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
# V11.07.2019 - netarchitech added multiple Moving Average selection per HighBredCloud request

declare lower;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input showBreakoutSignals = yes;
input ma_length = 21; #Length(180-200 for floating S/R , 55 for swing entry)


# 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 MACD_Value = g(length = fastLength) - g(length = slowLength);
MACD_Value.Hide();
plot MACD_Avg = g(price = MACD_Value, length = MACDLength);
MACD_Avg.Hide();
plot Diff = MACD_Value - MACD_Avg;
plot ZeroLine = 0;

MACD_Value.SetDefaultColor(GetColor(1));
MACD_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 EMA_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];

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

plot0 = if IsNaN(close) then Double.NaN else 0;
plot0.SetDefaultColor(Color.GRAY);

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

# Multi-moving average Component

input length = 14; #hint Length: Number of periods to average the data.
input movingAverageType = {default "Simple MA", "Exponential MA", "Wilders Smoothing", "Weighted MA", "Hull MA", "Adaptive MA", "Triangular MA", "Variable MA", "Dema MA", "Tema MA", "EHMA", "THMA"};
input displace = 0;

def avg_MACD_Value = ExpAverage(2 * ExpAverage(MACD_Value, ma_length / 2) - ExpAverage(MACD_Value, ma_length), Round(Sqrt(ma_length)));
def avg_MACD_Avg = ExpAverage(2 * ExpAverage(MACD_Avg, ma_length / 2) - ExpAverage(MACD_Avg, ma_length), Round(Sqrt(ma_length)));

plot X;
X.SetDefaultColor(CreateColor(0, 102, 204));
X.SetLineWeight(3);
plot Y;
Y.SetDefaultColor(Color.WHITE);
Y.SetLineWeight(3);

switch (movingAverageType) {
case "Simple MA":
X = Average(MACD_Value, ma_length);
Y = Average(MACD_Avg, ma_length);

case "Exponential MA":
X = ExpAverage(MACD_Value, ma_length);
Y = ExpAverage(MACD_Avg, ma_length);

case "Wilders Smoothing":
X = WildersAverage(MACD_Value, ma_length);
Y = WildersAverage(MACD_Avg, ma_length);

case "Weighted MA":
X = wma(MACD_Value, ma_length);
Y = wma(MACD_Avg, ma_length);

case "Hull MA":
X = HullMovingAvg(MACD_Value, ma_length);
Y = HullMovingAvg(MACD_Avg, ma_length);

case "Adaptive MA":
X = MovAvgAdaptive(MACD_Value, ma_length);
Y = MovAvgAdaptive(MACD_Avg, ma_length);

case "Triangular MA":
X = MovAvgTriangular(MACD_Value, ma_length);
Y = MovAvgTriangular(MACD_Avg, ma_length);

case "Variable MA":
X = VariableMA(MACD_Value, ma_length);
Y = VariableMA(MACD_Avg, ma_length);

case "Dema MA":
X = DEMA(MACD_Value, ma_length);
Y = DEMA(MACD_Avg, ma_length);

case "Tema MA":
X = TEMA(MACD_Value, ma_length);
Y = TEMA(MACD_Avg, ma_length);

case EHMA:
X = ExpAverage(2 * ExpAverage(MACD_Value, ma_length / 2) - ExpAverage(MACD_Value, ma_length), Round(Sqrt(ma_length)));
Y = ExpAverage(2 * ExpAverage(MACD_Avg, ma_length / 2) - ExpAverage(MACD_Avg, ma_length), Round(Sqrt(ma_length)));

case THMA:
X = WMA(WMA(MACD_Value, (ma_length / 2) / 3) * 3 - WMA(MACD_Value, (ma_length / 2) / 2) - WMA(MACD_Value, (ma_length / 2)), (ma_length / 2));
Y = WMA(WMA(MACD_Avg, (ma_length / 2) / 3) * 3 - WMA(MACD_Avg, (ma_length / 2) / 2) - WMA(MACD_Avg, (ma_length / 2)), (ma_length / 2));
}
;
Looking forward to your thoughts, feedback and analysis when you have a chance :cool:
 
netarchitech

netarchitech

Well-known member
VIP
Warehouse
@HighBredCloud Updated code and image for your review:



Code:
# filename: MR__EZ_MACD_FREMA_
# original source: https://usethinkscript.com/threads/blast-off-indicator-for-thinkorswim.621/post-7785
# current source: https://usethinkscript.com/threads/adding-breakouts-and-dss-to-macd-indicator-for-thinkorswim.957/post-8463

# 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
# V11.07.2019 - netarchitech added multiple Moving Average selection per HighBredCloud request
# V11.08.2019 - netarchitech added cloud feature to MACD_Value - MACD_Avg lines per HighBredCloud request

declare lower;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input showBreakoutSignals = yes;
input ma_length = 21; #Length(180-200 for floating S/R , 55 for swing entry)


# 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 MACD_Value = g(length = fastLength) - g(length = slowLength);
MACD_Value.Hide();
plot MACD_Avg = g(price = MACD_Value, length = MACDLength);
MACD_Avg.Hide();
addCloud(MACD_Value, MACD_Avg, Color.GREEN, Color.RED);

plot Diff = MACD_Value - MACD_Avg;
plot ZeroLine = 0;

MACD_Value.SetDefaultColor(GetColor(1));
MACD_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(4));
ZeroLine.HideTitle();

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);
Upsignal.SetLineWeight(3);
DownSignal.SetHiding(!showBreakoutSignals);
Downsignal.SetLineWeight(3);

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

# 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 EMA_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];

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

plot0 = if IsNaN(close) then Double.NaN else 0;
plot0.SetDefaultColor(Color.GRAY);
plot0.HideTitle();

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

# Multi-moving average Component

#input length = 14; #hint Length: Number of periods to average the data.
input movingAverageType = {default "Simple MA", "Exponential MA", "Wilders Smoothing", "Weighted MA", "Hull MA", "Adaptive MA", "Triangular MA", "Variable MA", "Dema MA", "Tema MA", "EHMA", "THMA"};
input displace = 0;

def avg_MACD_Value = ExpAverage(2 * ExpAverage(MACD_Value, ma_length / 2) - ExpAverage(MACD_Value, ma_length), Round(Sqrt(ma_length)));
def avg_MACD_Avg = ExpAverage(2 * ExpAverage(MACD_Avg, ma_length / 2) - ExpAverage(MACD_Avg, ma_length), Round(Sqrt(ma_length)));

plot X;
X.SetDefaultColor(CreateColor(0, 102, 204));
X.SetLineWeight(3);
plot Y;
Y.SetDefaultColor(Color.WHITE);
Y.SetLineWeight(3);

switch (movingAverageType) {
case "Simple MA":
X = Average(MACD_Value, ma_length);
Y = Average(MACD_Avg, ma_length);

case "Exponential MA":
X = ExpAverage(MACD_Value, ma_length);
Y = ExpAverage(MACD_Avg, ma_length);

case "Wilders Smoothing":
X = WildersAverage(MACD_Value, ma_length);
Y = WildersAverage(MACD_Avg, ma_length);

case "Weighted MA":
X = wma(MACD_Value, ma_length);
Y = wma(MACD_Avg, ma_length);

case "Hull MA":
X = HullMovingAvg(MACD_Value, ma_length);
Y = HullMovingAvg(MACD_Avg, ma_length);

case "Adaptive MA":
X = MovAvgAdaptive(MACD_Value, ma_length);
Y = MovAvgAdaptive(MACD_Avg, ma_length);

case "Triangular MA":
X = MovAvgTriangular(MACD_Value, ma_length);
Y = MovAvgTriangular(MACD_Avg, ma_length);

case "Variable MA":
X = VariableMA(MACD_Value, ma_length);
Y = VariableMA(MACD_Avg, ma_length);

case "Dema MA":
X = DEMA(MACD_Value, ma_length);
Y = DEMA(MACD_Avg, ma_length);

case "Tema MA":
X = TEMA(MACD_Value, ma_length);
Y = TEMA(MACD_Avg, ma_length);

case EHMA:
X = ExpAverage(2 * ExpAverage(MACD_Value, ma_length / 2) - ExpAverage(MACD_Value, ma_length), Round(Sqrt(ma_length)));
Y = ExpAverage(2 * ExpAverage(MACD_Avg, ma_length / 2) - ExpAverage(MACD_Avg, ma_length), Round(Sqrt(ma_length)));

case THMA:
X = WMA(WMA(MACD_Value, (ma_length / 2) / 3) * 3 - WMA(MACD_Value, (ma_length / 2) / 2) - WMA(MACD_Value, (ma_length / 2)), (ma_length / 2));
Y = WMA(WMA(MACD_Avg, (ma_length / 2) / 3) * 3 - WMA(MACD_Avg, (ma_length / 2) / 2) - WMA(MACD_Avg, (ma_length / 2)), (ma_length / 2));
}
;
Let me know what you think...Hope this helps :)
 
netarchitech

netarchitech

Well-known member
VIP
Warehouse
@HighBredCloud You are certainly welcome...I'm going to call Tech Support tomorrow on another issue...I'll ask if there is anything else that can be done :)
 
H

HighBredCloud

Active member
@HighBredCloud You are certainly welcome...I'm going to call Tech Support tomorrow on another issue...I'll ask if there is anything else that can be done :)
@netarchitech just don't spend too much time like I did...Hey BTW...The last time I called TOS in regards to the candles being delayed by 40 sec or so on a 5 min timeframe...I was told that having TOS run in "Real Time" makes it glitch and run slower. I was told to run a 3 second delay. I then spoke to a different rep who couldn't verify what the first rep stated. That might be a good question to ask. Have you experienced any problems with TOS with the new candles forming? I am super paranoid now and run my brokers charting along side TOS to make sure it does not lag.

I really don't know if its perhaps that I am running 5 charts on one screen with 2 custom indicators per chart with about 5 other upper studies...Figured I'd ask to see if you're experiencing a similar problem...

EDIT: I was also told that all the custom studies are stored in their cloud so not like I've overloaded the TOS memory. I am starting to think that I need an outside video card to speed up the computer process...running 4 monitors is probably what is slowing it down.
 
netarchitech

netarchitech

Well-known member
VIP
Warehouse
Figured I'd ask to see if you're experiencing a similar problem...
@HighBredCloud Thanks for asking...Yes I have...Keep getting different answers...feels a little like "the runaround" if you ask me...I will make a point of asking again and let you know what they say...

ON that note, I am more than a little concerned about the zero commission thing...it takes serious money to run a serious datacenter...Something's gotta give :(

I am starting to think that I need an outside video card to speed up the computer process...running 4 monitors is probably what is slowing it down.
Given 4 32" monitors, I would say it wouldn't hurt...I still can't get over you having 4 32" monitors...AWESOME :cool:
 
H

HighBredCloud

Active member
@HighBredCloud Thanks for asking...Yes I have...Keep getting different answers...feels a little like "the runaround" if you ask me...I will make a point of asking again and let you know what they say...

ON that note, I am more than a little concerned about the zero commission thing...it takes serious money to run a serious datacenter...Something's gotta give :(


Given 4 32" monitors, I would say it wouldn't hurt...I still can't get over you having 4 32" monitors...AWESOME :cool:
@netarchitech Yeah same...But TOS will never tell you that. I did notice tho that my brokers charting...even though a naked chart did load faster and you could actually see the price action moving up and down on the 5 min candle unlike TOS. When I spoke to TOS I eluded to the no commissions being a factor in my issue but they denied. To bad tho because they actually might be charging a monthly fee for their platform like others..and its not like we in this community have better options but to pay up...

ON a side note...I used to run 5 32 inch monitors...I needed two laptops for that...it just gets too busy. Got a good deal on 2 of them when my friend stepped up to a 43 inch set up...now that's bad ass...so he kinda dropped them on me with a deal I couldn't refuse...haha. But in all honesty 3 monitors does the job for me well. I can be in 3 trades at once on one monitor...if needed be...Have a live watchlist with 12 stocks displaying on 15 min time frame on another monitor and watch my SPY D W 1h 2h 4h charts on the third...I don't need anything else...Discord and YouTube I check on the laptop screen. The more simpler the better your focus is...Too much of anything...indicators in particular will create analysis paralysis...I am sure you know how that goes. My main focus now as far as indicators go are MACD_FREMA and PercentR_MAC...the SMI_EOU is another exit indicator I have up. That one works great too. Everything you made thus far is awesome!
 
netarchitech

netarchitech

Well-known member
VIP
Warehouse
To bad tho because they actually might be charging a monthly fee for their platform like others..
I was thinking that might be where they go...Of course they could sell Order Flow, if they aren't doing so already :(

ON a side note...I used to run 5 32 inch monitors...
Holy Moly!!! Surely you jest :)

43 inch set up...now that's bad ass...
Yeah, I'd say...I'm wondering at what point do you hit diminishing returns...

I can be in 3 trades at once on one monitor...if needed be...Have a live watchlist with 12 stocks displaying on 15 min time frame on another monitor and watch my SPY D W 1h 2h 4h charts on the third...I don't need anything else...Discord and YouTube I check on the laptop screen. The more simpler the better your focus is...Too much of anything...indicators in particular will create analysis paralysis...
OMG!!! You are working for NASA, aren't you?!?

Everything you made thus far is awesome!
Awww shucks, @HighBredCloud I'm blushing :ROFLMAO: Seriously tho...Thank you! Just trying to keep up with you :cool:
 

Top