c2 AdaptiveMovingHullStrategy
c2 AdaptiveMovingHullStrategy
0 at
https://mozilla.org/MPL/2.0/
// 2020 © io72signals
//@version=4
strategy("72s: Adaptive Hull Moving Average+", shorttitle="72s: Adaptive HMA+",
overlay=true)
//Optional Inputs
charger = input("Volatility", title="Choose which charger to adapt to:",
options=["Volatility", "Volume"])
src = input(close, title="Source:")
minLength = input(172, title="Minimum period:")
maxLength = input(233, title="Maximum period:")
adaptPct = input(3.141, minval = 0, maxval = 100, title="Adapting
Percentage:") / 100.0
//Source to adapt to
highVolatility = atr(13) > atr(40) //Volatility Meter.
Change it to match to your strat/pair/tf if needs.
//Dynamics
var float dynamicLen = avg(minLength,maxLength)
plugged = charger=="Volume"? volBreak : highVolatility
dynamicLen := iff(plugged, max(minLength, dynamicLen * (1 - adaptPct)),
min(maxLength, dynamicLen * (1 + adaptPct)))
//Adaptive HMA
xhma(_src,_length) => _return = wma(2 * wma(_src, _length / 2) - wma(_src,
_length), int(sqrt(_length)))
dynamicHMA = xhma(close,int(dynamicLen))
//Plot
plot(dynamicHMA, "Dynamic HMA", dynColor(dynamicHMA, #6fbf73, #c0f5ae, #eb4d5c,
#f2b1d4, color.yellow), 3)
// Comparative study
// staticHMA = hma(close, 200)
// plot(staticHMA, "Static HMA")
// plotchar(dynamicLen, "dynamicLength", "", location.top) //check output the
calculated Dynamic Length in the Data Window.
//Backgroud coloring
useBg = input(true, title="Background color to differentiate movement")
notgreat = calcslope(dynamicHMA) < flat and calcslope(dynamicHMA) > -flat
bgcolor(useBg? plugged? na : notgreat? #757779: #afb4b9 : na)
//Alerts
alertcondition(highVolatility and not notgreat, "72s: Volatility Meter", "Market is
on the move")
alertcondition(volBreak[1] and volBreak and not notgreat, "72s: Volume Break",
"Volume has just break above average")
// Trading Logic
// USAGE:
// Very very nice BUY entry to catch big up-movement if:
// 1. Price is above MA. (It is best when price is also not to far distance from
the MA, or you can also use distance oscillator to help out too)
// 2. HMA's color is in darker green. Means it's on the charging plug with your
chosen aspect.
// 3. RSI is above 50. This is to help as additional confirmation.
plotarrow(buyEntry ? 1 : 0)
plotarrow(sellEntry ? -1 : 0)
strategy.entry("Go Long", strategy.long, when=buyEntry)
strategy.entry("Go Short", strategy.short, when=sellEntry)