Advertisement
namile

Untitled

Aug 17th, 2020
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.55 KB | None | 0 0
  1. //@version=4
  2. //Basic Hull Ma Pack tinkered by InSilico
  3. //Converted to Strategy by DashTrader
  4. strategy("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)
  5. strat_dir_input = input(title="Strategy Direction", defval="long", options=["long", "short", "all"])
  6. strat_dir_value = strat_dir_input == "long" ? strategy.direction.long : strat_dir_input == "short" ? strategy.direction.short : strategy.direction.all
  7. strategy.risk.allow_entry_in(strat_dir_value)
  8. //////////////////////////////////////////////////////////////////////
  9. // Testing Start dates
  10. testStartYear = input(2016, "Backtest Start Year")
  11. testStartMonth = input(1, "Backtest Start Month")
  12. testStartDay = input(1, "Backtest Start Day")
  13. testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)
  14. //Stop date if you want to use a specific range of dates
  15. testStopYear = input(2030, "Backtest Stop Year")
  16. testStopMonth = input(12, "Backtest Stop Month")
  17. testStopDay = input(30, "Backtest Stop Day")
  18. testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)
  19.  
  20.  
  21. testPeriod() =>
  22. time >= testPeriodStart and time <= testPeriodStop ? true : false
  23. // Component Code Stop
  24. //////////////////////////////////////////////////////////////////////
  25. //INPUT
  26. src = input(close, title="Source")
  27. modeSwitch = input("Hma", title="Hull Variation", options=["Hma", "Thma", "Ehma"])
  28. length = input(55, title="Length(180-200 for floating S/R , 55 for swing entry)")
  29. switchColor = input(true, "Color Hull according to trend?")
  30. candleCol = input(false,title="Color candles based on Hull's Trend?")
  31. visualSwitch = input(true, title="Show as a Band?")
  32. thicknesSwitch = input(1, title="Line Thickness")
  33. transpSwitch = input(40, title="Band Transparency",step=5)
  34.  
  35. //FUNCTIONS
  36. //HMA
  37. HMA(_src, _length) => wma(2 * wma(_src, _length / 2) - wma(_src, _length), round(sqrt(_length)))
  38. //EHMA
  39. EHMA(_src, _length) => ema(2 * ema(_src, _length / 2) - ema(_src, _length), round(sqrt(_length)))
  40. //THMA
  41. THMA(_src, _length) => wma(wma(_src,_length / 3) * 3 - wma(_src, _length / 2) - wma(_src, _length), _length)
  42.  
  43. //SWITCH
  44. Mode(modeSwitch, src, len) =>
  45. modeSwitch == "Hma" ? HMA(src, len) :
  46. modeSwitch == "Ehma" ? EHMA(src, len) :
  47. modeSwitch == "Thma" ? THMA(src, len/2) : na
  48.  
  49. //OUT
  50. HULL = Mode(modeSwitch, src, length)
  51. MHULL = HULL[0]
  52. SHULL = HULL[2]
  53.  
  54. //COLOR
  55. hullColor = switchColor ? (HULL > HULL[2] ? #00ff00 : #ff0000) : #ff9800
  56.  
  57. //PLOT
  58. ///< Frame
  59. Fi1 = plot(MHULL, title="MHULL", color=hullColor, linewidth=thicknesSwitch, transp=50)
  60. Fi2 = plot(visualSwitch ? SHULL : na, title="SHULL", color=hullColor, linewidth=thicknesSwitch, transp=50)
  61. ///< Ending Filler
  62. fill(Fi1, Fi2, title="Band Filler", color=hullColor, transp=transpSwitch)
  63. ///BARCOLOR
  64. barcolor(color = candleCol ? (switchColor ? hullColor : na) : na)
  65.  
  66. sizelong = input(100, defval = 100, minval = 1, maxval = 10000, title = "Lot long, %")
  67. sizeshort = input(100, defval = 100, minval = 1, maxval = 10000, title = "Lot short, %")
  68. size = strategy.position_size
  69.  
  70. lotlong = 0.0
  71. lotshort = 0.0
  72. lotlong := size != size[1] ? strategy.equity / close * sizelong / 100 : lotlong[1]
  73. lotshort := size != size[1] ? strategy.equity / close * sizeshort / 100 : lotshort[1]
  74.  
  75. if HULL[0] > HULL[2] and testPeriod()
  76. strategy.entry("buy", strategy.long, lotlong)
  77. if HULL[0] < HULL[2] and testPeriod()
  78. strategy.entry("sell", strategy.short, lotshort)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement