Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=2
- strategy("BitMoon v3.0", overlay=true, commission_value = 0.25, default_qty_type=strategy.percent_of_equity, default_qty_value = 100)
- /////////////////////////////////////////////////////////////
- //START - SET DATE RANGE
- // === BACKTEST RANGE ===
- FromMonth = input(defval = 1, title = "From Month", minval = 1)
- FromDay = input(defval = 1, title = "From Day", minval = 1)
- FromYear = input(defval = 1990, title = "From Year")
- ToMonth = input(defval = 12, title = "To Month", minval = 1)
- ToDay = input(defval = 31, title = "To Day", minval = 1)
- ToYear = input(defval = 2020, title = "To Year")
- startDate = time > timestamp(FromYear, FromMonth, FromDay, 00, 00)
- endDate = time < timestamp(ToYear, ToMonth, ToDay, 23, 59)
- withinTimeRange = startDate and endDate
- /////////////////////////////////////////////////////////////
- //END - SET DATE RANGE
- /////////////////////////////////////////////////////////////
- //START - INDICATORS
- length = input(5)
- mult = input(3)
- atr_ = atr(length)
- max1 = max(nz(max_[1]), close)
- min1 = min(nz(min_[1]), close)
- is_uptrend_prev = nz(is_uptrend[1], true)
- stop = is_uptrend_prev ? max1 - mult * atr_ : min1 + mult * atr_
- vstop_prev = nz(vstop[1])
- vstop1 = is_uptrend_prev ? max(vstop_prev, stop) : min(vstop_prev, stop)
- is_uptrend = close - vstop1 >= 0
- is_trend_changed = is_uptrend != is_uptrend_prev
- max_ = is_trend_changed ? close : max1
- min_ = is_trend_changed ? close : min1
- vstop = is_trend_changed ? is_uptrend ? max_ - mult * atr_ : min_ + mult * atr_ : vstop1
- plot(vstop, color = is_uptrend ? green : red, style=cross, linewidth=2)
- rsi = rsi(close, input(2))
- upper_band = input(70)
- lower_band = input(30)
- /////////////////////////////////////////////////////////////
- //END - INDICATORS
- /////////////////////////////////////////////////////////////
- //START - TRADING RULES
- direction = input(defval=1, title = "Strategy Direction", type=integer, minval=-1, maxval=1)
- strategy.risk.allow_entry_in(direction == 0 ? strategy.direction.all : (direction < 0 ? strategy.direction.short : strategy.direction.long))
- condition1 = crossover(rsi, upper_band) and withinTimeRange
- condition2 = rsi < lower_band and close < vstop and withinTimeRange
- strategy.entry("BUY", strategy.long, when = condition1)
- strategy.entry("SELL", strategy.short, when = condition2)
- /////////////////////////////////////////////////////////////
- //END - TRADING RULES
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement