首先聲明,落魄其實並不會寫程式,一切都是誤會。
這次分享的是剝頭皮策略的指標合併,介紹YT:https://youtu.be/rOqCgwoTWCE
用到的指標分別是:
1.UT Bot Alerts
2.STC Indicator - A Better MACD [SHK]
3.Hull Suite
相關參數請看原YT
由於TradingView免費版一次只能用三個指標,落魄將三個指標合併成一個指標,並依影片參數修改,最難搞的是STC,原始程式碼似乎故意讓人看不懂,都是AAABBB代碼。
買賣信號各有兩種
一般Buy、Sell,是指收盤價在Hull Suite之上或之下。
Buy!、Sell!,是指開盤價(整根K棒)在Hull Suite之上或之下。
並增加一條200EMA線。
快訊也有分Buy、Sell、Buy!、Sell!
//@version=5
//Basic Hull Ma Pack tinkered by InSilico
//UT Bot Alerts by QuantNomad by shayankm
//STC Indicator - A Better MACD [SHK] by shayankm
indicator('HS+UT+STC+EMA200', overlay=true)
//INPUT
src = input(close, title='Source')
modeSwitch = input.string('Hma', title='Hull Variation', options=['Hma', 'Thma', 'Ehma'])
length = input(55, title='Length(180-200 for floating S/R , 55 for swing entry)')
lengthMult = input(1.0, title='Length multiplier (Used to view higher timeframes with straight band)')
useHtf = input(false, title='Show Hull MA from X timeframe? (good for scalping)')
htf = input.timeframe('240', title='Higher timeframe')
switchColor = input(true, 'Color Hull according to trend?')
candleCol = input(false, title='Color candles based on Hull\'s Trend?')
visualSwitch = input(true, title='Show as a Band?')
thicknesSwitch = input(1, title='Line Thickness')
transpSwitch = input.int(40, title='Band Transparency', step=5)
//FUNCTIONS
//HMA
HMA(_src, _length) =>
ta.wma(2 * ta.wma(_src, _length / 2) - ta.wma(_src, _length), math.round(math.sqrt(_length)))
//EHMA
EHMA(_src, _length) =>
ta.ema(2 * ta.ema(_src, _length / 2) - ta.ema(_src, _length), math.round(math.sqrt(_length)))
//THMA
THMA(_src, _length) =>
ta.wma(ta.wma(_src, _length / 3) * 3 - ta.wma(_src, _length / 2) - ta.wma(_src, _length), _length)
//SWITCH
Mode(modeSwitch, src, len) =>
modeSwitch == 'Hma' ? HMA(src, len) : modeSwitch == 'Ehma' ? EHMA(src, len) : modeSwitch == 'Thma' ? THMA(src, len / 2) : na
//OUT
_hull = Mode(modeSwitch, src, int(length * lengthMult))
HULL = useHtf ? request.security(syminfo.ticker, htf, _hull) : _hull
MHULL = HULL[0]
SHULL = HULL[2]
//COLOR
hullColor = switchColor ? HULL > HULL[2] ? #00ff00 : #ff0000 : #ff9800
//PLOT
///< Frame
Fi1 = plot(MHULL, title='MHULL', color=hullColor, linewidth=thicknesSwitch)
Fi2 = plot(visualSwitch ? SHULL : na, title='SHULL', color=hullColor, linewidth=thicknesSwitch)
alertcondition(ta.crossover(MHULL, SHULL), title='Hull trending up.', message='Hull trending up.')
alertcondition(ta.crossover(SHULL, MHULL), title='Hull trending down.', message='Hull trending down.')
///< Ending Filler
fill(Fi1, Fi2, title='Band Filler', color=color.new(hullColor, transpSwitch))
///BARCOLOR
barcolor(color=candleCol ? switchColor ? hullColor : na : na)
EEEEEE = input(80, 'Length')
BBBB = input(27, 'FastLength')
BBBBB = input(50, 'SlowLength')
AAAA(BBB, BBBB, BBBBB) =>
fastMA = ta.ema(BBB, BBBB)
slowMA = ta.ema(BBB, BBBBB)
AAAA = fastMA - slowMA
AAAA
AAAAA(EEEEEE, BBBB, BBBBB) =>
AAA = input(0.5)
var CCCCC = 0.0
var DDD = 0.0
var DDDDDD = 0.0
var EEEEE = 0.0
BBBBBB = AAAA(close, BBBB, BBBBB)
CCC = ta.lowest(BBBBBB, EEEEEE)
CCCC = ta.highest(BBBBBB, EEEEEE) - CCC
CCCCC := CCCC > 0 ? (BBBBBB - CCC) / CCCC * 100 : nz(CCCCC[1])
DDD := na(DDD[1]) ? CCCCC : DDD[1] + AAA * (CCCCC - DDD[1])
DDDD = ta.lowest(DDD, EEEEEE)
DDDDD = ta.highest(DDD, EEEEEE) - DDDD
DDDDDD := DDDDD > 0 ? (DDD - DDDD) / DDDDD * 100 : nz(DDDDDD[1])
EEEEE := na(EEEEE[1]) ? DDDDDD : EEEEE[1] + AAA * (DDDDDD - EEEEE[1])
EEEEE
STC = AAAAA(EEEEEE, BBBB, BBBBB)
mColor = STC > STC[1] ? color.new(color.green, 20) : color.new(color.red, 20)
if STC[3] <= STC[2] and STC[2] > STC[1] and STC > 75
alert("Red", alert.freq_once_per_bar)
if STC[3] >= STC[2] and STC[2] < STC[1] and STC < 25
alert("Green", alert.freq_once_per_bar)
// Inputs
a = input(2, title='Key Vaule. \'This changes the sensitivity\'')
c = input(6, title='ATR Period')
h = input(false, title='Signals from Heikin Ashi Candles')
xATR = ta.atr(c)
nLoss = a * xATR
ssrc = h ? request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, close, lookahead=barmerge.lookahead_off) : close
xATRTrailingStop = 0.0
iff_1 = ssrc > nz(xATRTrailingStop[1], 0) ? ssrc - nLoss : ssrc + nLoss
iff_2 = ssrc < nz(xATRTrailingStop[1], 0) and ssrc[1] < nz(xATRTrailingStop[1], 0) ? math.min(nz(xATRTrailingStop[1]), ssrc + nLoss) : iff_1
xATRTrailingStop := ssrc > nz(xATRTrailingStop[1], 0) and ssrc[1] > nz(xATRTrailingStop[1], 0) ? math.max(nz(xATRTrailingStop[1]), ssrc - nLoss) : iff_2
pos = 0
iff_3 = ssrc[1] > nz(xATRTrailingStop[1], 0) and ssrc < nz(xATRTrailingStop[1], 0) ? -1 : nz(pos[1], 0)
pos := ssrc[1] < nz(xATRTrailingStop[1], 0) and ssrc > nz(xATRTrailingStop[1], 0) ? 1 : iff_3
xcolor = pos == -1 ? color.red : pos == 1 ? color.green : color.blue
ema = ta.ema(ssrc, 1)
above = ta.crossover(ema, xATRTrailingStop)
below = ta.crossover(xATRTrailingStop, ema)
buy = ssrc > xATRTrailingStop and above and STC[1] < 25 and STC > STC[1]
sell = ssrc < xATRTrailingStop and below and STC[1] > 75 and STC < STC[1]
buy2 = ssrc > xATRTrailingStop and above and STC[1] < 25 and STC > STC[1] and open > MHULL
sell2 = ssrc < xATRTrailingStop and below and STC[1] > 75 and STC < STC[1] and open <SHULL
barbuy = ssrc > xATRTrailingStop
barsell = ssrc < xATRTrailingStop
plotshape(buy, title='Buy', text='Buy', style=shape.labelup, location=location.belowbar, color=color.new(color.green, 0), textcolor=color.new(color.white, 0), size=size.tiny)
plotshape(sell, title='Sell!', text='Sell', style=shape.labeldown, location=location.abovebar, color=color.new(color.red, 0), textcolor=color.new(color.white, 0), size=size.tiny)
plotshape(buy2, title='Buy', text='Buy!', style=shape.labelup, location=location.belowbar, color=color.new(color.green, 0), textcolor=color.new(color.white, 0), size=size.tiny)
plotshape(sell2, title='Sell!', text='Sell!', style=shape.labeldown, location=location.abovebar, color=color.new(color.red, 0), textcolor=color.new(color.white, 0), size=size.tiny)
alertcondition(buy, 'buy', 'buy')
alertcondition(sell, 'sell', 'sell')
alertcondition(buy2 , 'buy!' , 'buy!')
alertcondition(sell2 , 'sell!', 'sell!')
srcc = input(close, title='Source')
//Add 200EMA
ema200 = ta.ema(src, 200)
plot(ema200, color=ema200 > ema200[1] ? color.green : color.red, title='200 EMA')
沒有留言:
張貼留言