Skip to content

Instantly share code, notes, and snippets.

@immoh
Created May 25, 2021 11:14
Show Gist options
  • Select an option

  • Save immoh/ad1a035503392c3d319c0264dc7c0ab2 to your computer and use it in GitHub Desktop.

Select an option

Save immoh/ad1a035503392c3d319c0264dc7c0ab2 to your computer and use it in GitHub Desktop.
Immo's Hull Strategy
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © immoh
//@version=4
//Basic Hull Ma Pack tinkered by InSilico s
//Converted to Strategy by DashTrader
strategy("Immo's Hull Suite Strategy", overlay=true, pyramiding=1, default_qty_type= strategy.percent_of_equity, default_qty_value = 100, calc_on_order_fills=false, slippage=0,commission_type=strategy.commission.percent,commission_value=0)
//////////////////////////////////////////////////////////////////////
// Testing Start dates
testPeriodStart = timestamp(2019,5,1,0,0)
testPeriodStop = timestamp(2030,5,1,0,0)
testPeriod() =>
time >= testPeriodStart and time <= testPeriodStop ? true : false
// Component Code Stop
//////////////////////////////////////////////////////////////////////
//INPUT
src = input(close, title="Source")
length = input(55, title="Length(180-200 for floating S/R , 55 for swing entry)")
switchColor = input(true, "Color Hull according to trend?")
visualSwitch = input(true, title="Show as a Band?")
thicknesSwitch = input(1, title="Line Thickness")
transpSwitch = input(40, title="Band Transparency",step=5)
//OUT
HULL = wma(2 * wma(src, length / 2) - wma(src, length), round(sqrt(length)))
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, transp=50)
Fi2 = plot(visualSwitch ? SHULL : na, title="SHULL", color=hullColor, linewidth=thicknesSwitch, transp=50)
///< Ending Filler
fill(Fi1, Fi2, title="Band Filler", color=hullColor, transp=transpSwitch)
stop_loss_level = 0.99 * lowest(low, 14)
if strategy.position_size > 0
stop_loss_level := stop_loss_level[1] + max(close - open, 0) / 2
plot(stop_loss_level)
//if HULL[0] > HULL[2] and testPeriod()
// strategy.entry("buy", strategy.long)
// //strategy.exit("stop loss", "buy", stop=stop_loss_level)
//if HULL[0] < HULL[2] and testPeriod()
// strategy.close("buy")
buy_signal = HULL[0] > HULL[2] and HULL[1] <= HULL[3]
sell_signal = HULL[0] < HULL[2] and HULL[1] >= HULL[3]
strategy.entry("buy", strategy.long, when = testPeriod() and buy_signal)
strategy.exit("stop loss", "buy", stop=stop_loss_level)
strategy.close("buy", when = testPeriod() and sell_signal)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment