//@version=5
strategy(title='Arty', overlay=true, initial_capital = 1000, currency = currency.USD, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_value=0.04)
// == HULL SUITE == //
//INPUT
src = input(close, title='Source', group='Hull MA Settings')
modeSwitch = input.string('Hma', title='Hull Variation', options=['Hma', 'Thma', 'Ehma'], group='Hull MA Settings')
length = input(200, title='Length(180-200 for floating S/R , 55 for swing entry)', group='Hull MA Settings')
lengthMult = input(1.0, title='Length multiplier (Used to view higher timeframes with straight band)', group='Hull MA Settings')
useHtf = input(false, title='Show Hull MA from X timeframe? (good for scalping)', group='Hull MA Settings')
htf = input.timeframe('240', title='Higher timeframe', group='Hull MA Settings')
switchColor = input(true, 'Color Hull according to trend?', group='Hull MA Settings')
candleCol = input(false, title='Color candles based on Hull\'s Trend?', group='Hull MA Settings')
visualSwitch = input(true, title='Show as a Band?', group='Hull MA Settings')
thicknesSwitch = 1
transpSwitch = 40
// INPUT VARIABLES
entryMethod = input.string('Single Entry', title='Entry Method', options=['Single Entry', 'Cumulative Entries'], group='Entry Settings')
buyInput = input.float(20, 'Entry Size (%) ', group='Entry Settings')/100
len1 = input.int(1, title='EMA 1', group='Entry Settings')
len2 = input.int(10, title='EMA 2', group='Entry Settings')
// Exit Inputs
exitEma1Len = input.int(1, title='Exit EMA 1', group='Exit Settings')
exitEma2Len = input.int(100, title='Exit EMA 2', group='Exit Settings')
// Alerts
// Alert Input
longMessage= input.string("", title="Long Bot Message", group='Alerts')
shortMessage= input.string("", title="Short Bot Message", group='Alerts')
//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 CALCUTION
ema1 = ta.ema(close, len1)
ema2 = ta.ema(close, len2)
ema1Exit = ta.ema(close, exitEma1Len)
ema2Exit = ta.ema(close, exitEma2Len)
//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
var bool Buy = na
var bool Sell = na
if entryMethod == 'Single Entry'
Buy := HULL_B and EMA_S and not isLong and strategy.position_size == 0
Sell := HULL_S and EMA_B and not isShort and strategy.position_size == 0
if entryMethod == 'Cumulative Entries'
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
// Exit logics
longExit = ta.crossunder(ema1Exit, ema2Exit)
shortExit = ta.crossover(ema1Exit, ema2Exit)
// Position size
posQty = buyInput * strategy.equity / close
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.order('Long', strategy.long, qty=posQty)
alert(longMessage, alert.freq_once_per_bar_close)
if Sell
strategy.order('Short', strategy.short, qty=posQty)
alert(shortMessage, alert.freq_once_per_bar_close)
if longExit
strategy.close('Long', 'Long Exit')
if shortExit
strategy.close('Short', 'Short Exit')