Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
3.5 kB
6
Indexable
Never
//@version=5

strategy(title='Arty', overlay=true)

// ==  HULL SUITE  == // 


//INPUT
src = input(close, title='Source')
modeSwitch = input.string('Hma', title='Hull Variation', options=['Hma', 'Thma', 'Ehma'])
length = input(200, 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)


// Alert Input
longMessage= input.string("", title="Long Alertatron Message")
shortMessage= input.string("", title="Short Alertatron Message")

//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)
///< Ending Filler
fill(Fi1, Fi2, title='Band Filler', color=hullColor, transp=90)
///BARCOLOR
barcolor(color=candleCol ? switchColor ? hullColor : na : na)




// ==  EMA CROSS  == //                                                         


// INPUT VARIABLES

len1 = input(1, title='EMA 1 length')
len2 = input(10, title='EMA 2 length')

// EMA CALCUTION
ema1 = ta.ema(close, len1)
ema2 = ta.ema(close, len2)

// PLOTS
plot(ema1)
plot(ema2)



                            // == STRATEGY == //


//CONDITIONS
isLong = false
isLong := nz(isLong[1])

isShort = false
isShort := nz(isShort[1])

HULL_B = MHULL > SHULL
HULL_S = SHULL > MHULL

EMA_B = ema1 > ema2
EMA_S = ema1 < ema2


Buy = HULL_B and EMA_S and not isLong
Sell = HULL_S and EMA_B and not isShort

Close_L = HULL_S and EMA_B
Close_S = HULL_B and EMA_S

if Buy
    isLong := true
    isShort := false
    isShort

if Sell
    isShort := true
    isLong := false
    isLong

plotshape(Buy, title='Long Entry', location=location.belowbar, style=shape.labelup, color=color.new(#2C9670, 0), text='Long', textcolor=color.new(color.white, 0))
plotshape(Sell, title='Short Entry', location=location.abovebar, style=shape.labeldown, color=color.red, text='Short', textcolor=color.new(color.white, 0))

if Buy
    strategy.entry('Long', strategy.long)
    alert(longMessage, alert.freq_once_per_bar_close)

if Sell
    strategy.entry('Short', strategy.short)
    alert(shortMessage, alert.freq_once_per_bar_close)

//ALERTS