Adding breakouts and DSS to MACD indicator for ThinkorSwim?

netarchitech

netarchitech

Active member
VIP
Warehouse
I know I'm going to sound like a hypocrite again, but everyone needs to sleep some time 💤 Hopefully, this will help:

 
netarchitech

netarchitech

Active member
VIP
Warehouse
@HighBredCloud This is what frustration looks like...ARRRGHHH!



Cue the music...looks like I'm gonna be bangin' my head against the Wall...

 
netarchitech

netarchitech

Active member
VIP
Warehouse
@HighBredCloud Good Morning :) Well...I've got good news and bad news...The good news is I've finished the prototype and the actual coding...The bad news is I've finished the prototype and the actual coding...What I mean is there are no syntax errors which leaves potential logic errors and the fact that I am facing the dreaded Case Switch error(s) AGAIN...ugh...

Unfortunately, this is the same error I ran into when I was trying to code the multiple Moving Averages...Maybe this is a good time to revisit the Larry Williams Pro Go code you so kindly proffered...In any event, I'll make sure to keep you apprised of any further developments...
 
Last edited:
D

diazlaz

Active 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:
Good stuff congratulations everyone who contributed to the creation of this beast!

Any recommendations parameters for intraday, 1 to 5 minute timeframe?
 
H

HighBredCloud

Active member
@netarchitech WOAH...You've been busy and it shows! Having a hell of a morning yet again. Lost all internet at around 2:45 AM last night...so decided to go to bed...Needless to say internet just came back on NOW...like WTF are we back in the infant days of the 90's when it comes to internet? This is not the type of sitting on my hands that I was referring to earlier...But God works in mysterious ways so maybe I'm being taught patience one way or another...

Anyways...can't wait to test everything out...Seems to me like everything will need to be done all at once again to see which MA hits faster and does not repaint as much on the MACD/FREMA and how the new version with new settings compares to the "OG."

In regards to the PercentR did you try my suggestion of simply adding an additional PercentR line by itself while leaving the original code the way that it is and simply disabling the coded PercentR line by unchecking the "show plot" from the settings later on? I know its just a band aid and not the actual way of how its suppose to be done...but perhaps we can test the theory of SuperSmootherFilter MA's with the jagged lines of PercentR...BTW I also saw in the PRMACSSF that there is an actual RSI tab to plot...

Yeah I know its frustrating...trial and error and keep moving forward...no other option that I see and hopefully an idea will emerge as you go...and yeah...Try the ProGo...it could provide some answers...or not.

BTW...thanks for the tunes!
 
netarchitech

netarchitech

Active member
VIP
Warehouse
Hey there @diazlaz Thanks! I really appreciate it...Thanks also to @HighBredCloud for coming up with the idea and digging up critical information that led to solving outstanding issues...It's all about Teamwork!

As for recommendation parameters, you'll have to ask @HighBredCloud ....

Good Luck and Good Trading :)
 
netarchitech

netarchitech

Active member
VIP
Warehouse
Having a hell of a morning yet again. Lost all internet at around 2:45 AM last night...so decided to go to bed...Needless to say internet just came back on NOW...like WTF are we back in the infant days of the 90's when it comes to internet?
Sorry to read about your current woes with respect to the Internet, but I'm glad you're back up and running :) Yeah...things have been a little busy, but we're making progress...all we need now is for your Internet Service Provider to maintain your connection! Who is your ISP anyway? Is there an alternative where you live? Can you call them up and express your frustration...maybe even get a discount of some kind for the inconvenience?

In regards to the PercentR did you try my suggestion of simply adding an additional PercentR line by itself while leaving the original code the way that it is and simply disabling the coded PercentR line by unchecking the "show plot" from the settings later on?
No...not yet, but it just so happens to be the next thing on my dance card ;)

Try the ProGo...it could provide some answers...
Already have...thanks again...it helped me finally overcome the dreaded "Value never assigned" error, which led to the MACD/FREMA multiple moving average component...Not one to boast, but who else currently has 12 different moving averages available to select from within an indicator!

BTW...thanks for the tunes!
You are certainly most welcome...I'll have to start another playlist as we go here :cool:
 
H

HighBredCloud

Active member
Good stuff congratulations everyone who contributed to the creation of this beast!

Any recommendations parameters for intraday, 1 to 5 minute timeframe?
@diazlaz I will be testing those next to see how they compare to the "OG" version with the Forward/Reverse EMA...With all the new moving averages implemented I don't know what will work best...The few questions that I have that need to be answered when I do the test are:

1. Is changing the VALUE/AVG moving average better over what Mobius used with the FREMA?
2. Is changing the FREMA to a different MA better to go along VALUE/AVG used by Mobius?
3. Is possibly adding a 4th line to the MACD/FREMA the answer to go along with the FREMA and and the VALUE/AVG originall assigned?

The whole point is to make this indicator better and more functional...With all the added Moving Averages its will take a while a lot of testing...I hope that other users here can help with the tests and post the results as everyone here trades differently and on different timeframes.
 
H

HighBredCloud

Active member
@netarchitech Comacst or Xfinity whatever they go by now...its suppose to be 100MB or 150MB...I need to call them and go from there.

AND YES...this is quite the accomplishment with the 12 MA's for sure so boast away...you've earned it!

The real questions that I now have that need to be addressed while testing are the ones I referred to above the the response to @diazlaz

Honestly that is what will determine how functional and effective the MACD really is...making it pretty is one thing BUT making it pretty AND functional is another level.
 
netarchitech

netarchitech

Active member
VIP
Warehouse
Comacst or Xfinity whatever they go by now...its suppose to be 100MB or 150MB...
If you weren't already doing so, try out Ookla Speedtest.net to verify that you're actually getting the speeds they claim they're delivering...

AND YES...this is quite the accomplishment with the 12 MA's for sure so boast away...you've earned it!
Aww shucks! To be honest, I couldn't have done it without YOU! Thanks for making perceived impossibilities into tangible realities :cool:
 
H

HighBredCloud

Active member
If you weren't already doing so, try out Ookla Speedtest.net to verify that you're actually getting the speeds they claim they're delivering...


Aww shucks! To be honest, I couldn't have done it without YOU! Thanks for making perceived impossibilities into tangible realities :cool:
@netarchitech This is definitely a team effort for sure...I am just amazed at how you bring even the craziest ideas into reality...SO NOW...lets not disappoint the hard work put in and make sure that the theory behind the ideas actually works...and so here comes the "fun" part of it all...TESTING.
 
H

HighBredCloud

Active member
@HighBredCloud How can I help?
@netarchitech when you're trading I would put 3-5 instances of the MACD with different MA's and see what works better on specific timeframes that you're trading on. There's no other way. Testing 12 MA's and their actual reaction time in a live market environment is a lot different than slapping an indicator on an after hours charts as you already know. This test will require live market results...ON DEMAND is cool...BUT that just takes time from other possible projects that you're working on. Makes no sense for you to do that AFTER HOURS.

IF we could get more people to test this and post results that would be awesome.

@diazlaz do you want to help with the tests and share your finding and specific time frames you traded on?

We need to be able to see what actual settings or MA's work the best on given time frames etc. The combination of 12 MA's is a crazy concept all on its own...So we need to find the best MA's and settings to narrow down the field.

This is just my opinion on how to go about this...feedback welcomed.
 
D

diazlaz

Active member
VIP
Warehouse
@netarchitech when you're trading I would put 3-5 instances of the MACD with different MA's and see what works better on specific timeframes that you're trading on. There's no other way. Testing 12 MA's and their actual reaction time in a live market environment is a lot different than slapping an indicator on an after hours charts as you already know. This test will require live market results...ON DEMAND is cool...BUT that just takes time from other possible projects that you're working on. Makes no sense for you to do that AFTER HOURS.

IF we could get more people to test this and post results that would be awesome.

@diazlaz do you want to help with the tests and share your finding and specific time frames you traded on?

We need to be able to see what actual settings or MA's work the best on given time frames etc. The combination of 12 MA's is a crazy concept all on its own...So we need to find the best MA's and settings to narrow down the field.

This is just my opinion on how to go about this...feedback welcomed.
Sounds good - I recommend, we define a set of test cases (e.g. a list of parameters we all want to test, and a way to record the results, at a list of parameters, as a community we can take pieces of it and contribute to the cause.

Trading Style: I'm mostly a 1MIN - 5MIN intra-day trader at the moment (feed's my ADD's), and believe there is value in the longer term weekly for longer term holdings, and interim term (not sure, but think the 1H to 4H (with 5MIN entry) for weekly swings and/or options.
 
netarchitech

netarchitech

Active member
VIP
Warehouse
IF we could get more people to test this and post results that would be awesome.
@HighBredCloud Agreed...Do you think asking @BenTen if it might be possible to put out a forum-wide invitation to the other community members to lend a hand? If not, could we possibly round up some of the regulars and just start the process? As I mentioned before, I'm a complete noob when it comes to all aspects of testing in this manner...BUT that doesn't mean I'm not up to whatever needs to be done :)

Sounds good - I recommend, we define a set of test cases (e.g. a list of parameters we all want to test, and a way to record the results, at a list of parameters, as a community we can take pieces of it and contribute to the cause.
Thanks, @diazlaz ...You are certainly far more organized than I am...It's good to know you're on board with this :cool:
 
H

HighBredCloud

Active member
Sounds good - I recommend, we define a set of test cases (e.g. a list of parameters we all want to test, and a way to record the results, at a list of parameters, as a community we can take pieces of it and contribute to the cause.

Trading Style: I'm mostly a 1MIN - 5MIN intra-day trader at the moment (feed's my ADD's), and believe there is value in the longer term weekly for longer term holdings, and interim term (not sure, but think the 1H to 4H (with 5MIN entry) for weekly swings and/or options.
@diazlaz That's good to hear that you're willing to help out with the test...and especially with the timeframes that you trade...I myself trade 3m 5m 15m...so you and I can compare our results no avoid any one sided bias. The more objective people will be the more will be known how to improve the indicator. I think @netarchitech likes the higher intraday timeframes...

As far as parameters go...I guess we should really establish them...Are we testing this out as a single indicator or are we paring this with the PercentR_MAC and see how they go together? @netarchitech

And I do agree that perhaps we can make a thread asking for interest with the testing once the indicator is ready. IF I recall correctly you'd probably be testing this on an ETF? That be good to test this across a variety of equities so that we can see the behavior and the reaction of the indicator to such equities. Because your time is very valuable in coding and enhancing the indicator...If I were you I would just test it during live market hours...Kill 2 birds with one stone. Since I don't code I can go over some data that was gathered by others...

Before we run the test tho...we would need to establish the entry and exit rules for others to follow and explain how the indicator is suppose to work...I'm sure this group can figure it out as the indicator does not seem complicated.

Perhaps @BenTen has some ideas how to go about this.
 
D

diazlaz

Active member
VIP
Warehouse
@diazlaz That's good to hear that you're willing to help out with the test...and especially with the timeframes that you trade...I myself trade 3m 5m 15m...so you and I can compare our results no avoid any one sided bias. The more objective people will be the more will be known how to improve the indicator. I think @netarchitech likes the higher intraday timeframes...

As far as parameters go...I guess we should really establish them...Are we testing this out as a single indicator or are we paring this with the PercentR_MAC and see how they go together? @netarchitech

And I do agree that perhaps we can make a thread asking for interest with the testing once the indicator is ready. IF I recall correctly you'd probably be testing this on an ETF? That be good to test this across a variety of equities so that we can see the behavior and the reaction of the indicator to such equities. Because your time is very valuable in coding and enhancing the indicator...If I were you I would just test it during live market hours...Kill 2 birds with one stone. Since I don't code I can go over some data that was gathered by others...

Before we run the test tho...we would need to establish the entry and exit rules for others to follow and explain how the indicator is suppose to work...I'm sure this group can figure it out as the indicator does not seem complicated.

Perhaps @BenTen has some ideas how to go about this.
cool will let Ben chime in with suggestion on structure, think we should keep this thread for general discussion and maintenance, and create a new one for testing and testing results.
 
BenTen

BenTen

Administrative
Staff
VIP
Warehouse
I agree with @diazlaz. Feel free to create a new thread if need be. This one has gotten very long. You are more than welcome to keep posting on here as long as it relates to the original topic.
 
H

HighBredCloud

Active member
@netarchitech I LOVE this MACD already! The addition of just ONE MA to the equation makes the confirmation that much stronger. Here are the current settings that I am using @diazlaz

MACD VALUE/AVG are default 12, 26, 9

Purple Line PLOT X = 7 HULL MA

I took out the PLOT Y for now as it was a bit hard to read when all the MA's and MACD lines came together...This is just the beginning so I will probably test with PLOT Y for a longer trend continuation.

THE STRATEGY:

What I am looking for is in a LONG position ENTRY when the MACD is below the ZERO line is for the Histogram to change colors from Bright RED to Dark RED...followed by FREMA to be GREEN...

Secondly, I look for the MACD VALUE line...(Cyan) to be crossing upward over the X Line (Purple Line HULL MA 7).

EXIT or for a SHORT position I look for the Histogram to change color from Bright GREEN to Dark GREEN. The MACD VALUE line must be crossing over the X Line and FREMA should be changing from GREEN to RED.

The addition of the X Line helps eliminate false signals by the Histogram simply changing colors midway through...or even the breakout signals from disappearing then appearing...ALSO same could be said about FREMA...I have seen instances where FREMA even though it does not repaint...turn colors on the next candle and then the trend reversing from its original entry.

The X Line serves as a confirmation that you are trading in the correct trend direction even though you may experience some pullbacks...THE PAIN should ONLY be temporary.

Just with any other indicator...I do suggest paring this MACD/FREMAS with another type...I am also testing Tillson T3 set to 10 periods...My next test will be with a Mobius SuperTrend from my archives to see how on a 3 min chart everything plays out.

I also found that DEMA was a good choice but anything with the with the MA Length of 5...same concept as above...

@netarchitech under the AA the input length is set to 14...but when I try to change that nothing seems to happen...is that length suppose to do something when changed or possible script error?

Once I do more testing I will keep everyone posted of what I find...This should be a good starting strategy for the testing. Please let me know what your findings will be and perhaps different settings or strategy etc...

Counter Trend LONG Entry


Trend is Your Friend SHORT Entry

 
netarchitech

netarchitech

Active member
VIP
Warehouse
As far as parameters go...I guess we should really establish them...Are we testing this out as a single indicator or are we paring this with the PercentR_MAC and see how they go together?
Establishing the parameters sounds like a good idea to me...Tough choice...both have benefits as far as I can see...I think pairing with the PercentR_MAC would be my choice...

@netarchitech I LOVE this MACD already! The addition of just ONE MA to the equation makes the confirmation that much stronger.
@HighBredCloud I'm so glad to read that...Thank you! You know, in the short span of time we have worked/collaborated together, your positive confirmations have bolstered my confidence and determination to keep on coding as best I can :cool:

@netarchitech under the AA the input length is set to 14...but when I try to change that nothing seems to happen...is that length suppose to do something when changed or possible script error?
I'll look into it and get back to you...
 

Top