Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.89 KB | None | 0 0
  1. //@version=2
  2. strategy("Superstoch 1.0 Strategy", overlay = true, precision=0, initial_capital=10000, currency="USD", default_qty_type=strategy.percent_of_equity, default_qty_value=100)
  3.  
  4. useCurrentRes = input(true, title="Use current Timeframe?")
  5. current_tf = interval
  6.  
  7. // Allows use of Heiki Ashi candles, while still using normal candle values for indicator. Not fully working yet!
  8. c = security(tickerid, period, close)
  9. h = security(tickerid, period, high)
  10. l = security(tickerid, period, low)
  11.  
  12. higher_tf = iff(current_tf == 1 and isintraday, "5",
  13. iff(current_tf == 3 and isintraday, "15",
  14. iff(current_tf == 5 and isintraday, "15",
  15. iff(current_tf == 15 and isintraday, "60",
  16. iff(current_tf == 30 and isintraday, "120",
  17. iff(current_tf == 60 and isintraday, "240",
  18. iff(current_tf == 240 and isintraday, "720",
  19. iff(current_tf == 720 and isintraday, "D",
  20. iff(current_tf == isdaily, "W",
  21. "15")))))))))
  22.  
  23. res = useCurrentRes ? period : higher_tf
  24.  
  25. plot(current_tf, color=fuchsia)
  26. //plot(higher_tf, color=purple)
  27.  
  28. // STOCH
  29. Stochlength = input(14, minval=1, title="lookback length of Stochastic")
  30. smoothK = input(3, title="smoothing of Stochastic %K ")
  31. smoothD = input(3, title="moving average of Stochastic %K")
  32.  
  33. StochOverBought = input(75, title="Stochastic overbought condition")
  34. StochOverSold = input(25, title="Stochastic oversold condition")
  35.  
  36. k = sma(stoch(c, h, l, Stochlength), smoothK)
  37. d = sma(k, smoothD)
  38.  
  39. // SMA
  40.  
  41. sma_fast = input( 100, title="SMA FAST" )
  42. sma_slow = input( 200, title="SMA SLOW" )
  43.  
  44. // FILTERS
  45.  
  46. filter_sma = input( title = "Filter with SMA" , type = bool, defval = true )
  47. filter_macd = input( title = "Filter with MACD", type = bool, defval = false )
  48.  
  49. // OVERALL TREND
  50.  
  51. //is_bullish = filter_sma ? sma( close, sma_slow ) < sma( close, sma_fast ) : true
  52. //is_bearish = filter_sma ? sma( close, sma_slow ) > sma( close, sma_fast ) : true
  53.  
  54. //bgcolor( is_bearish and is_bullish ? black : ( is_bearish ? red : green ), transp=80 )
  55.  
  56. // SUPERTREND
  57.  
  58. Factor=input(4, minval=1,maxval = 100)
  59. Pd=input(10, minval=1,maxval = 100)
  60.  
  61. Up=hl2-(Factor*atr(Pd))
  62. Dn=hl2+(Factor*atr(Pd))
  63.  
  64. TrendUp=close[1]>TrendUp[1]? max(Up,TrendUp[1]) : Up
  65. TrendDown=close[1]<TrendDown[1]? min(Dn,TrendDown[1]) : Dn
  66.  
  67. Trend = close > TrendDown[1] ? 1: close< TrendUp[1]? -1: nz(Trend[1],1)
  68. Tsl = Trend==1? TrendUp: TrendDown
  69.  
  70. Trend15 = security(tickerid,"15",Trend)
  71. Trend30 = security(tickerid,"30",Trend)
  72. Trend60 = security(tickerid,"60",Trend)
  73. Trend120 = security(tickerid,"120",Trend)
  74. Trend240 = security(tickerid,"240",Trend)
  75. TrendD = security(tickerid,res,Trend)
  76. TrendW = security(tickerid,"W",Trend)
  77.  
  78. Tsl15 = security(tickerid,"15",Tsl)
  79. Tsl30 = security(tickerid,"15",Tsl)
  80. Tsl60 = security(tickerid,"60",Tsl)
  81. Tsl120 = security(tickerid,"120",Tsl)
  82. Tsl240 = security(tickerid,"240",Tsl)
  83. TslD = security(tickerid,res,Tsl)
  84. TslW = security(tickerid,"W",Tsl)
  85.  
  86. //linecolor = Trend == 1 ? green : red
  87. linecolor15 = Trend15 == 1 ? green : red
  88. linecolor30 = Trend30 == 1 ? green : red
  89. linecolor60 = Trend60 == 1 ? green : red
  90. linecolor120 = Trend120 == 1 ? green : red
  91. linecolor240 = Trend240 == 1 ? green : red
  92. linecolorD = TrendD == 1 ? green : red
  93. linecolorW = TrendW == 1 ? green : red
  94.  
  95. is_bullish = TrendD == 1 ? true : false
  96. is_bearish = TrendD != 1 ? true : false
  97.  
  98. //plot(Tsl15, color = linecolor15 , style = line , linewidth = 1,title = "SuperTrend15")
  99. //plot(Tsl30, color = linecolor30 , style = linebr , linewidth = 1,title = "SuperTrend30")
  100. //plot(Tsl60, color = linecolor60 , style = circles, linewidth = 1,title = "SuperTrend60")
  101. //plot(Tsl120, color = linecolor120 , style = cross,linewidth = 1,title = "SuperTrend120")
  102. //plot(Tsl240, color = linecolor240 , style = line , linewidth = 1,title = "SuperTrend240")
  103. plot(TslD, color = linecolorD , style = line , linewidth = 2,title = "SuperTrendD")
  104. //plot(TslW, color = linecolorW , style = line , linewidth = 2,title = "SuperTrendW")
  105.  
  106.  
  107. // - 1 regular cross
  108. // If STOCH cross over STOCH smooth on the oversold / overbought areas:
  109.  
  110. bullish_stoch_cross = crossover (k,d)
  111. bearish_stoch_cross = crossunder(k,d)
  112.  
  113. // - 2 cross on edges
  114.  
  115. medium_bullish_stoch_cross = crossover (k,d) and k < StochOverSold
  116. medium_bearish_stoch_cross = crossunder(k,d) and k > StochOverBought
  117.  
  118.  
  119. // - 3 trend reversal
  120. // If STOCH cross back from oversold
  121.  
  122. strong_bullish_stoch_cross = crossover(k,StochOverSold)
  123. strong_bearish_stoch_cross = crossunder(k,StochOverBought)
  124.  
  125.  
  126. plotshape( is_bullish and medium_bullish_stoch_cross, style=shape.triangleup, location= location.belowbar, color=green, size=size.small, transp=0)
  127. plotshape( is_bearish and medium_bearish_stoch_cross, style=shape.triangledown, location= location.abovebar, color=red , size=size.small, transp=0)
  128.  
  129. plotshape( is_bullish and medium_bullish_stoch_cross, style=shape.triangleup, location= location.belowbar, color=white, size=size.normal, transp=0)
  130. plotshape( is_bearish and medium_bearish_stoch_cross, style=shape.triangledown, location= location.abovebar, color=white , size=size.normal, transp=0)
  131.  
  132. plotshape( is_bullish and bullish_stoch_cross and not medium_bullish_stoch_cross and not strong_bullish_stoch_cross, style=shape.cross, location= location.belowbar, color=green, transp=0, size=size.small)
  133. plotshape( is_bearish and bearish_stoch_cross and not medium_bearish_stoch_cross and not strong_bearish_stoch_cross, style=shape.cross, location= location.abovebar, color=red , transp=0, size=size.small)
  134.  
  135. plotshape( is_bullish and strong_bullish_stoch_cross, style=shape.triangleup , location= location.belowbar, color=green, size=size.small, transp=0)
  136. plotshape( is_bearish and strong_bearish_stoch_cross, style=shape.triangledown, location= location.abovebar, color=red, size=size.small, transp=0)
  137.  
  138. plotshape( is_bearish and strong_bullish_stoch_cross, style=shape.xcross , location= location.belowbar, color=red, size=size.small, transp=0)
  139. plotshape( is_bullish and strong_bearish_stoch_cross, style=shape.xcross, location= location.abovebar, color=green, size=size.small, transp=0)
  140.  
  141. // ~ PLOTTING
  142.  
  143. trend_colour = is_bearish and is_bullish ? gray : ( is_bearish ? red : green )
  144.  
  145. //plot( sma( close, sma_slow ), 'slow sma', color=gray, linewidth=1, transp=20)
  146. //plot( sma( close, sma_fast ), 'fast sma', color=trend_colour, linewidth=4 )
  147.  
  148. alertcondition(is_bullish and strong_bullish_stoch_cross, title='Smaoch: Long', message='Smaoch: Long ')
  149. alertcondition(is_bearish and strong_bearish_stoch_cross, title='Smaoch: Short', message='Smaoch: Short ')
  150. alertcondition(is_bullish and bullish_stoch_cross and not medium_bullish_stoch_cross and not strong_bullish_stoch_cross, title='Smaoch: Add to Long', message='Smaoch: Add to Long ')
  151. alertcondition(is_bearish and bearish_stoch_cross and not medium_bearish_stoch_cross and not strong_bearish_stoch_cross, title='Smaoch: Add to Short', message='Smaoch: Add to Short ')
  152. alertcondition(is_bullish and medium_bullish_stoch_cross, title='Smaoch: Upcoming Long', message='Smaoch: Upcoming Long ')
  153. alertcondition(is_bearish and medium_bearish_stoch_cross, title='Smaoch: Upcoming Short', message='Smaoch: Upcoming Short ')
  154. alertcondition(is_bullish and strong_bearish_stoch_cross, title='Smaoch: Exit Long', message='Smaoch: Exit Long ')
  155. alertcondition(is_bearish and strong_bullish_stoch_cross, title='Smaoch: Exit Short', message='Smaoch: Exit Short ')
  156.  
  157.  
  158. if ((year >= 2010) and (year <= 2016))
  159. strategy.close("short", when = is_bearish and strong_bullish_stoch_cross)
  160. //strategy.exit("short SL", "short", loss = lossinpoints)
  161. strategy.entry("short", strategy.short, when = is_bearish and strong_bearish_stoch_cross)
  162.  
  163. if ((year >= 2010) and (year <= 2016))
  164. strategy.close("long", when = is_bullish and strong_bearish_stoch_cross)
  165. //strategy.exit("long SL", "long", loss = lossinpoints)
  166. strategy.entry("long", strategy.long, when = is_bullish and strong_bullish_stoch_cross)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement