TradingView
Craig_Claussen
2 Dis 2019 pukul 21.58

MACD Multi-MA Strategy 

Bitcoin / United States DollarCoinbase

Huraian

This script applies the average of each major MA (SMA, RMA, EMA, WVMA, WMA) to the MACD formula.

The logic is simple. When all 5 MA's are in agreement in direction, then then script will notify users of change.
I posted this as a strategy to help show how logic does in back test. If you use my simple yet effective solution to find take profit locations, you can blow this back testing out of the water!!!


To set alerts simply turn script into study



//@version=2
study(title="MACD Multi-MA Study", overlay=false)

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]

alertcondition(long == true, title='MACD LONG SIGNAL', message='MACD LONG!')
alertcondition(short == true, title='MACD SHORT SIGNAL', message='MACD SHORT!')

Nota Keluaran

Sorry for the confusion. I stumbled upon good results thinking I was using MACD formula. Turns out I was only using partial formula.

The mistake just goes to show how uncomplicated a script needs to be to give good back testing results even on a line chart.

Nota Keluaran

Updated version with 4H setting at 66 just to show better backtest. See comment section below to test other lookback periods for other timeframes

I also changed overlay to true to save space on your screen
Komen
JustUncleL
This does not look like MACD formula to me. From my understanding MACD is the difference between the MAs:
MACD = MA(Long Length) - MA(Short Length).

So I believe the 1st MACD result should be:
ma = vwma(len2) - vwma(len1)
JustUncleL
@JustUncleL, Correction:
MACD = MA(Fast Length) - MA(Slow Length).

So 1st MACD calc should be:
ma = vwma(len1) - vwma(len2)
Craig_Claussen
@JustUncleL, Yes I apologize you are correct. I was so blinded by results that I didn't even realize I had only used only part of the formula for macd

Sometimes mistakes can be a good thing - like in this case.

SO this is essentially an average of the most common MA's ( SMA, RMA, EMA, WVMA, WMA). Which is quite funny when you take it all in. Something as simple as a multi-MA formula can create such positive backtest results

Using a lookback period of 598-599 will give same results as original script.
I will update now:

//@version=4
strategy(title="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 = input(close)
len = input(34, "LOOKBACK")

/////////////////////////////////////////////

ma = vwma(src, len)
plot(ma, title="VWMA", color=color.lime)

ma1 = rma(src, len)
plot(ma1, title="RMA", color=color.purple)

ma2 = sma(src, len)
plot(ma2, title="SMA", color=color.red)

ma3 = wma(src, len)
plot(ma3, title="WMA", color=color.orange)

ma4 = ema(src, len)
plot(ma4, title="EMA", color=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)
JustUncleL
@Craig_Claussen, Great thanks for the correction. The results are good as a Multi-MA strategy in any case. In actual fact I found the corrected Multi-MA MACD does not perform as well as straight MAs. Like you said sometimes you find something useful by accident.
theheirophant
@Craig_Claussen, the results are not displayed correctly mate. You are buying more contracts than you have equity for. This inflates the profit percentages so so much. Its a huge bug.
Craig_Claussen
I had error in study format. I apologize about the delay fixing it

//@version=4
study(title="Multi-MA Study", overlay=true)

src = close
len = input(610, "LOOKBACK")

/////////////////////////////////////////////

ma = vwma(src, len)
plot(ma, title="VWMA", color=color.lime)

ma1 = rma(src, len)
plot(ma1, title="RMA", color=color.purple)

ma2 = sma(src, len)
plot(ma2, title="SMA", color=color.red)

ma3 = wma(src, len)
plot(ma3, title="WMA", color=color.orange)

ma4 = ema(src, len)
plot(ma4, title="EMA", color=color.yellow)

ma5 = alma(src, len, 0.85, 0)
plot(ma5, title="ALMA", color=color.aqua)

ma6 = swma(src)
plot(ma6, title="SWMA", color=color.aqua)

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

plotshape(long, "Long", color=color.green, style=shape.triangleup, location=location.top, size=size.small)
plotshape(short, "Short", color=color.red, style=shape.triangledown, location=location.bottom, size=size.small)
BPRoberts
You mention "If you use my simple yet effective solution to find take profit locations" but I can't seem to find any reference to taking profit? Am I overlooking it? Thanks
Craig_Claussen
@XfalconX, I apologize I thought I posted the link to a private chart I published showing how to take profit

huh_
In the updated study, I only see the plotted lines, no shape. Is it possible for you to add a shape for the chart to the script?
Craig_Claussen
@huh_, Correct. Thanks for catching that. I updated study above
Lebih