Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. //@version=2
  2. strategy("BitMoon v3.0", overlay=true, commission_value = 0.25, default_qty_type=strategy.percent_of_equity, default_qty_value = 100)
  3.  
  4. /////////////////////////////////////////////////////////////
  5. //START - SET DATE RANGE
  6.  
  7. // === BACKTEST RANGE ===
  8. FromMonth = input(defval = 1, title = "From Month", minval = 1)
  9. FromDay = input(defval = 1, title = "From Day", minval = 1)
  10. FromYear = input(defval = 1990, title = "From Year")
  11. ToMonth = input(defval = 12, title = "To Month", minval = 1)
  12. ToDay = input(defval = 31, title = "To Day", minval = 1)
  13. ToYear = input(defval = 2020, title = "To Year")
  14.  
  15. startDate = time > timestamp(FromYear, FromMonth, FromDay, 00, 00)
  16. endDate = time < timestamp(ToYear, ToMonth, ToDay, 23, 59)
  17. withinTimeRange = startDate and endDate
  18.  
  19. /////////////////////////////////////////////////////////////
  20. //END - SET DATE RANGE
  21.  
  22.  
  23.  
  24. /////////////////////////////////////////////////////////////
  25. //START - INDICATORS
  26.  
  27. length = input(5)
  28. mult = input(3)
  29. atr_ = atr(length)
  30. max1 = max(nz(max_[1]), close)
  31. min1 = min(nz(min_[1]), close)
  32. is_uptrend_prev = nz(is_uptrend[1], true)
  33. stop = is_uptrend_prev ? max1 - mult * atr_ : min1 + mult * atr_
  34. vstop_prev = nz(vstop[1])
  35. vstop1 = is_uptrend_prev ? max(vstop_prev, stop) : min(vstop_prev, stop)
  36. is_uptrend = close - vstop1 >= 0
  37. is_trend_changed = is_uptrend != is_uptrend_prev
  38. max_ = is_trend_changed ? close : max1
  39. min_ = is_trend_changed ? close : min1
  40. vstop = is_trend_changed ? is_uptrend ? max_ - mult * atr_ : min_ + mult * atr_ : vstop1
  41. plot(vstop, color = is_uptrend ? green : red, style=cross, linewidth=2)
  42.  
  43. rsi = rsi(close, input(2))
  44. upper_band = input(70)
  45. lower_band = input(30)
  46.  
  47. /////////////////////////////////////////////////////////////
  48. //END - INDICATORS
  49.  
  50.  
  51.  
  52. /////////////////////////////////////////////////////////////
  53. //START - TRADING RULES
  54. direction = input(defval=1, title = "Strategy Direction", type=integer, minval=-1, maxval=1)
  55. strategy.risk.allow_entry_in(direction == 0 ? strategy.direction.all : (direction < 0 ? strategy.direction.short : strategy.direction.long))
  56.  
  57. condition1 = crossover(rsi, upper_band) and withinTimeRange
  58. condition2 = rsi < lower_band and close < vstop and withinTimeRange
  59.  
  60. strategy.entry("BUY", strategy.long, when = condition1)
  61. strategy.entry("SELL", strategy.short, when = condition2)
  62.  
  63. /////////////////////////////////////////////////////////////
  64. //END - TRADING RULES
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement