Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. //@version=2
  2. strategy("Super BitMoon v2", overlay=false, commission_value = 0.25, default_qty_type=strategy.percent_of_equity, default_qty_value = 100)
  3.  
  4. //BTCUSD 12h & ETHBTC 12h
  5.  
  6. /////////////////////////////////////////////////////////////
  7. //START - SET DATE RANGE
  8.  
  9. // === BACKTEST RANGE ===
  10. FromMonth = input(defval = 1, title = "From Month", minval = 1)
  11. FromDay = input(defval = 1, title = "From Day", minval = 1)
  12. FromYear = input(defval = 2011, title = "From Year")
  13. ToMonth = input(defval = 12, title = "To Month", minval = 1)
  14. ToDay = input(defval = 31, title = "To Day", minval = 1)
  15. ToYear = input(defval = 2018, title = "To Year")
  16.  
  17. startDate = time > timestamp(FromYear, FromMonth, FromDay, 00, 00)
  18. endDate = time < timestamp(ToYear, ToMonth, ToDay, 23, 59)
  19. withinTimeRange = startDate and endDate
  20.  
  21. /////////////////////////////////////////////////////////////
  22. //END - SET DATE RANGE
  23.  
  24.  
  25.  
  26. /////////////////////////////////////////////////////////////
  27. //START - INDICATORS
  28.  
  29. //ATR STOPS TREND FILTER
  30. length = input(5, title="ATR Stop's Length")
  31. mult = input(1, minval=0.01, title="ATR Stop's Multiple")
  32. atr_ = atr(length)
  33. max1 = max(nz(max_[1]), close)
  34. min1 = min(nz(min_[1]), close)
  35. is_uptrend_prev = nz(is_uptrend[1], true)
  36. stop = is_uptrend_prev ? max1 - mult * atr_ : min1 + mult * atr_
  37. vstop_prev = nz(vstop[1])
  38. vstop1 = is_uptrend_prev ? max(vstop_prev, stop) : min(vstop_prev, stop)
  39. is_uptrend = close - vstop1 >= 0
  40. is_trend_changed = is_uptrend != is_uptrend_prev
  41. max_ = is_trend_changed ? close : max1
  42. min_ = is_trend_changed ? close : min1
  43. vstop = is_trend_changed ? is_uptrend ? max_ - mult * atr_ : min_ + mult * atr_ : vstop1
  44.  
  45. //SYNTHETIC VIX
  46. pd = input(10, title="Synthetic VIX's Length")
  47. bbl = input(2, title="Synthetic VIX's Bollinger Band's Length")
  48. mult2 = input(0.01, minval=0.01, title="Synthetic VIX's Bollinger Band's Std Dev")
  49. wvf = ((highest(close, pd)-low)/(highest(close, pd)))*100
  50. sDev = mult2 * stdev(wvf, bbl)
  51. midLine = sma(wvf, bbl)
  52. upperBand = midLine + sDev
  53.  
  54. //RSI
  55. rsi = rsi(close, input(10,title="RSI's Length"))
  56. os = input(50,title="RSI's Oversold Level")
  57.  
  58. /////////////////////////////////////////////////////////////
  59. //END - INDICATORS
  60.  
  61.  
  62.  
  63. /////////////////////////////////////////////////////////////
  64. //START - TRADING RULES
  65. direction = input(defval=1, title = "Strategy Direction", type=integer, minval=-1, maxval=1)
  66. strategy.risk.allow_entry_in(direction == 0 ? strategy.direction.all : (direction < 0 ? strategy.direction.short : strategy.direction.long))
  67.  
  68. condition1 = crossunder(wvf, upperBand) and close > vstop and withinTimeRange
  69. condition2 = rsi < os and withinTimeRange
  70.  
  71. strategy.entry("BUY", strategy.long, when = condition1)
  72. strategy.entry("SELL", strategy.short, when = condition2)
  73.  
  74. /////////////////////////////////////////////////////////////
  75. //END - TRADING RULES
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement