Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.45 KB | None | 0 0
  1. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. // Autoview scalping script based on Vdub Renko SniperVX1.
  3. // Instructions:
  4. // 1) Setup Autoview
  5. // 2) Switch to 1m TF w/ Renko candles (requires Pro paid acct). Set Box Size to Traditional (not ATR) and manually test optimal value.
  6. // 3) Add each of 4 alerts: Open Long, Close Long, Open Short, Close Short
  7. // Suggestions:
  8. // PAIR BOX SIZE TF
  9. // EURCAD ??? 1m
  10. // BTCUSD 50-100 1m
  11. // ETHUSD 1.0-3.0 1m
  12. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  13.  
  14. //@version=3
  15. // Toggle comments on below 2 lines if using as indicator or strategy
  16. //study(title="Renkonator 5000 [IND]", overlay=true)
  17. strategy(title="Renkonator 5000 [STRAT]", overlay=true, commission_type=strategy.commission.percent, commission_value=0.075, calc_on_order_fills=true, calc_on_every_tick=true, pyramiding=0, initial_capital=10000) //default_qty_value=10000)
  18.  
  19. //---------------------------------------------------------------------------------------------------------------------------------------------------
  20. // Init
  21. //---------------------------------------------------------------------------------------------------------------------------------------------------
  22. m1 = input(title="From Month", defval=6, minval=1, maxval=12) // Strat Backtest
  23. d1 = input(title="From Day", defval=1, minval = 1, maxval=31) // Strat Backtest
  24. y1 = input(title="From Year", defval=2018, minval=2013) // Strat Backtest
  25. m2 = input(title="To Month", defval=1, minval=1, maxval=12) // Strat Backtest
  26. d2 = input(title="To Day", defval=1, minval=1, maxval=31) // Strat Backtest
  27. y2 = input(title="To Year", defval=9999, minval=2017) // Strat Backtest
  28. t_start = timestamp(y1, m1, d1, 00, 00) // Strat Backtest
  29. t_end = timestamp(y2, m2, d2, 23, 59) // Strat Backtest
  30. src = input(close, title="Renko Channel") // Renko S/R
  31. rst = input(title='Renko Channel length', type=integer, defval=1) // Renko S/R
  32. factor = input(1, minval=1,maxval = 1000, title="Trend Transition Signal") // Trend
  33. pd = input(1, minval=1,maxval = 1000, title="Period") // Trend
  34. hma_src = input(close, title="Hull MA's Source:") // Hull MA
  35. hma_slow_base_length = input(20, minval=1, title="HMA Slow Base Length:") // Hull MA
  36. hma_slow_length_scalar = input(1, minval=0, title="HMA Slow Length Scalar:") // Hull MA
  37. hma_fast_base_length = input(10, minval=1, title="HMA Fast Base Length:") // Hull MA
  38. hma_fast_length_scalar = input(1, minval=0, title="HMA Fast Length Scalar:") // Hull MA
  39. sl_pct = input(title="Stop Loss Percent", defval=3.0, type=float)
  40. //open_long=na, open_short=na, close_long=na, close_short=na, position=na, final_pos=na, flat=na, entry_price=na, stop=na
  41.  
  42. // Functions
  43. window() => time >= t_start and time <= t_end ? true : false
  44. hullma(src, length)=>wma(2*wma(src, length/2)-wma(src, length), round(sqrt(length)))
  45.  
  46. //---------------------------------------------------------------------------------------------------------------------------------------------------
  47. // Signal Generation
  48. //---------------------------------------------------------------------------------------------------------------------------------------------------
  49. last8h = highest(close, 13) // S/R
  50. lastl8 = lowest(close, 13) // S/R
  51. rstt = valuewhen(high >= highest(high, rst), high, 0) // S/R
  52. rstb = valuewhen(low <= lowest(low, rst), low, 0) // S/R
  53. renko_top = last8h //last8h == nz(last8h[1]) ? last8h : na // S/R
  54. renko_bot = lastl8 //lastl8 == nz(lastl8[1]) ? lastl8 : na // S/R
  55.  
  56. // Rajandran Supertrend (1==up, -1==down)
  57. up = hl2 - (factor * atr(pd)) // Trend
  58. down = hl2 + (factor * atr(pd)) // Trend
  59. trend_up = na, trend_down = na, trend = na // Trend
  60. trend_up := close[1] > trend_up[1] ? max(up, trend_up[1]) : up // Trend
  61. trend_down := close[1] < trend_down[1] ? min(down, trend_down[1]) : down // Trend
  62. trend := close > trend_down[1] ? 1 : close < trend_up[1] ? -1: nz(trend[1],0) // Trend
  63.  
  64. hma_slow = hullma(hma_src, hma_slow_base_length + hma_slow_length_scalar * 6) // Hull MA
  65. hma_fast = hullma(hma_src, hma_fast_base_length + hma_fast_length_scalar * 6) // Hull MA
  66. hull_cross = 0
  67. hull_cross := crossover(hma_fast, hma_slow) ? 1 : crossunder(hma_fast, hma_slow) ? -1 : hull_cross[1]
  68.  
  69. //---------------------------------------------------------------------------------------------------------------------------------------------------
  70. // Position Management
  71. // Manually tracks long/short positions and stop losses (both unavailable in indicators)
  72. // Strategy: only trade in direction of trend
  73. // Setup #1: HMA cross + 3 brick trend
  74. // Setup #2: HMA cross + 1 brick trend following 2+ brick pullback
  75. //---------------------------------------------------------------------------------------------------------------------------------------------------
  76. //open_long := (hull_cross==1 and close>open and barssince(close<open)>3) or (hull_cross==1 and close>open and barssince(close[1]>open[1])>2)
  77. //close_long := barssince(close>open) >= 3
  78. //open_short := (hull_cross==-1 and open>close and barssince(open<close)>3) or (hull_cross==-1 and open>close and barssince(open[1]<close[1])>2)
  79. //close_short := barssince(close<open) >= 3
  80.  
  81. long_signal = trend==1 and trend[1]==-1
  82. short_signal = trend==-1 and trend[1]==1
  83.  
  84. close_long = short_signal and strategy.position_size > 0 and window()
  85. close_short = long_signal and strategy.position_size < 0 and window()
  86. open_long = long_signal and strategy.position_size <= 0 and window()
  87. open_short = short_signal and strategy.position_size >= 0 and window()
  88.  
  89. //open_long := trend==1 and trend[1]==-1
  90. //close_long := trend==-1 and trend[1]==1
  91. //open_short := trend==-1 and trend[1]==1
  92. //close_short := trend==1 and trend[1]==-1
  93.  
  94. //position := open_long ? 1 : open_short ? -1 : (position[1]==1 and close_long) or (position[1]==-1 and close_short) ? 0 : position[1]
  95. //entry_price := position==1 and position[1]!=1 ? low : position==-1 and position[1]!=-1 ? high : entry_price[1]
  96. //stop := position[1]==1 and ((low - entry_price)/entry_price)*100 <= sl_pct*-1 ? true : position[1]==-1 and ((high - entry_price)/entry_price)*100 >= sl_pct ? true : false
  97. //final_pos := open_long ? 1 : open_short ? -1 : (position[1]==1 and close_long or stop) or (position[1]==-1 and close_short or stop) ? 0 : final_pos[1]
  98.  
  99. //go_long_sig = final_pos==1 and final_pos[1]!=1 and window()
  100. //cl_long_sig = final_pos[1]==1 and final_pos==0 and window()
  101. //go_short_sig = final_pos==-1 and final_pos[1]!=-1 and window()
  102. //cl_short_sig = final_pos[1]==-1 and final_pos==0 and window()
  103.  
  104. //-------------------------------------------------------------------------------------------------------------------------------------
  105. // Tradingview Strategy Backtesting
  106. // Important: Comment these lines when running an indicator script.
  107. //---------------------------------------------------------------------------------------------------------------------------------------------------
  108. //strategy.close("LONG", when=close_long)
  109. //strategy.close("SHORT", when=close_short)
  110. strategy.entry("LONG", strategy.long, when=open_long)
  111. strategy.entry("SHORT", strategy.short, when=open_short)
  112.  
  113. //---------------------------------------------------------------------------------------------------------------------------------------------------
  114. // Autoview Alerts
  115. // IMPORTANT: Check alert expiration time regularly to monitor expiry dates.
  116. // CMD DESC VALUES
  117. // e exchange bitmex, okcoin, ...
  118. // a acct name created for linked Autoview exchange
  119. // s symbol xbtusd, ...
  120. // b book long, short
  121. // c close order, position
  122. // t type market, limit, ...
  123. // q quantity order size
  124. // l leverage 1-50
  125. // Close all longs = e=okcoin s=butcusd3m c=position b=long
  126. // Close all shorts = e=okcoin s=butcusd3m c=position b=short
  127. //---------------------------------------------------------------------------------------------------------------------------------------------------
  128. alertcondition(open_long, title='Long Entry', message='e=bitmex-testnet a=testmex s=ethusd b=long t=market l=10 q=1000')
  129. alertcondition(close_long, title='Long Exit', message='e=bitmex-testnet a=testmex s=ethusd c=position t=market')
  130. alertcondition(open_short, title='Short Entry', message='e=bitmex-testnet a=testmex s=ethusd b=short t=market l=10 q=1000')
  131. alertcondition(close_short, title='Short Exit', message='e=bitmex-testnet a=testmex s=ethusd c=position t=market')
  132.  
  133. //---------------------------------------------------------------------------------------------------------------------------------------------------
  134. // Plots & Styling
  135. // Upblock: #b6d7a8, border: #6aa84f, Downblock: #ea9999f7, border: #e06666
  136. //---------------------------------------------------------------------------------------------------------------------------------------------------
  137. rt2 = plot(rstt, color = rstt != rstt[1] ? na : red, title="RT2", linewidth=1, offset=+0, editable=true) // S/R
  138. rb2 = plot(rstb, color = rstb != rstb[1] ? na : green, title="RB2", linewidth=1, offset=0, editable=true) // S/R
  139. ul2 = plot(renko_top, "Renko Channel Top", color=#e06666, linewidth=1, style=circles, transp=25) // S/R
  140. ll2 = plot(renko_bot, "Renko Channel Bot", color=#6aa84f, linewidth=1, style=circles, transp=25) // S/R
  141. fill(ul2, ll2, black, 95, "Renko Channel") // S/R
  142. fill(ul2, rt2, red, 93, "Resistance Channel") // S/R
  143. fill(ll2, rb2, green, 93, "Support Channel") // S/R
  144. // plotshape(ema_up, "Uptrend", shape.circle, location.belowbar, black, 50, 0, size=size.tiny) // Trend
  145. // plotshape(ema_down, "Downtrend", shape.circle, location.abovebar, black, 50, 0, size=size.tiny) // Trend
  146. // plotshape(trend_rev_up, "New Uptrend", shape.labelup, location.belowbar, fuchsia, 0, 0, size=size.tiny) // Trend
  147. // plotshape(trend_rev_down, "New Downtrend", shape.labeldown, location.abovebar, fuchsia, 0, 0, size=size.tiny) // Trend
  148. //plot(trend, "Trend", color=black, linewidth=2, transp=0)
  149. //plot(trend_up, "Trend Up", color=green, linewidth=2, transp=0)
  150. //plot(trend_down, "Trend Down", color=red, linewidth=2, transp=0)
  151. plot(hma_slow, "HMA Slow", color=orange, linewidth=2, transp=0) // Hull MA
  152. plot(hma_fast, "HMA Fast", color=teal, linewidth=2, transp=0) // Hull MA
  153. // plot(hull_cross, "Hull Cross", color=white, linewidth=2)
  154. //plotshape(open_long, "Long Entry", shape.triangleup, location.belowbar, green, 0, 0, size=size.small, transp=0)//, text="Long") // Positions
  155. //plotshape(close_long, "Long Exit", shape.triangledown, location.abovebar, green, 0, 0, size=size.small, transp=0)//, text="Long") // Positions
  156. //plotshape(open_short, "Short Entry", shape.triangledown, location.abovebar, red, 0, 0, size=size.small, transp=0)//, text="Short") // Positions
  157. //plotshape(close_short, "Short Exit", shape.triangleup, location.belowbar, red, 0, 0, size=size.small, transp=0)//, text="Short") // Positions
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement