Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=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)
- useCurrentRes = input(true, title="Use current Timeframe?")
- current_tf = interval
- // Allows use of Heiki Ashi candles, while still using normal candle values for indicator. Not fully working yet!
- c = security(tickerid, period, close)
- h = security(tickerid, period, high)
- l = security(tickerid, period, low)
- higher_tf = iff(current_tf == 1 and isintraday, "5",
- iff(current_tf == 3 and isintraday, "15",
- iff(current_tf == 5 and isintraday, "15",
- iff(current_tf == 15 and isintraday, "60",
- iff(current_tf == 30 and isintraday, "120",
- iff(current_tf == 60 and isintraday, "240",
- iff(current_tf == 240 and isintraday, "720",
- iff(current_tf == 720 and isintraday, "D",
- iff(current_tf == isdaily, "W",
- "15")))))))))
- res = useCurrentRes ? period : higher_tf
- plot(current_tf, color=fuchsia)
- //plot(higher_tf, color=purple)
- // STOCH
- Stochlength = input(14, minval=1, title="lookback length of Stochastic")
- smoothK = input(3, title="smoothing of Stochastic %K ")
- smoothD = input(3, title="moving average of Stochastic %K")
- StochOverBought = input(75, title="Stochastic overbought condition")
- StochOverSold = input(25, title="Stochastic oversold condition")
- k = sma(stoch(c, h, l, Stochlength), smoothK)
- d = sma(k, smoothD)
- // SMA
- sma_fast = input( 100, title="SMA FAST" )
- sma_slow = input( 200, title="SMA SLOW" )
- // FILTERS
- filter_sma = input( title = "Filter with SMA" , type = bool, defval = true )
- filter_macd = input( title = "Filter with MACD", type = bool, defval = false )
- // OVERALL TREND
- //is_bullish = filter_sma ? sma( close, sma_slow ) < sma( close, sma_fast ) : true
- //is_bearish = filter_sma ? sma( close, sma_slow ) > sma( close, sma_fast ) : true
- //bgcolor( is_bearish and is_bullish ? black : ( is_bearish ? red : green ), transp=80 )
- // SUPERTREND
- Factor=input(4, minval=1,maxval = 100)
- Pd=input(10, minval=1,maxval = 100)
- Up=hl2-(Factor*atr(Pd))
- Dn=hl2+(Factor*atr(Pd))
- TrendUp=close[1]>TrendUp[1]? max(Up,TrendUp[1]) : Up
- TrendDown=close[1]<TrendDown[1]? min(Dn,TrendDown[1]) : Dn
- Trend = close > TrendDown[1] ? 1: close< TrendUp[1]? -1: nz(Trend[1],1)
- Tsl = Trend==1? TrendUp: TrendDown
- Trend15 = security(tickerid,"15",Trend)
- Trend30 = security(tickerid,"30",Trend)
- Trend60 = security(tickerid,"60",Trend)
- Trend120 = security(tickerid,"120",Trend)
- Trend240 = security(tickerid,"240",Trend)
- TrendD = security(tickerid,res,Trend)
- TrendW = security(tickerid,"W",Trend)
- Tsl15 = security(tickerid,"15",Tsl)
- Tsl30 = security(tickerid,"15",Tsl)
- Tsl60 = security(tickerid,"60",Tsl)
- Tsl120 = security(tickerid,"120",Tsl)
- Tsl240 = security(tickerid,"240",Tsl)
- TslD = security(tickerid,res,Tsl)
- TslW = security(tickerid,"W",Tsl)
- //linecolor = Trend == 1 ? green : red
- linecolor15 = Trend15 == 1 ? green : red
- linecolor30 = Trend30 == 1 ? green : red
- linecolor60 = Trend60 == 1 ? green : red
- linecolor120 = Trend120 == 1 ? green : red
- linecolor240 = Trend240 == 1 ? green : red
- linecolorD = TrendD == 1 ? green : red
- linecolorW = TrendW == 1 ? green : red
- is_bullish = TrendD == 1 ? true : false
- is_bearish = TrendD != 1 ? true : false
- //plot(Tsl15, color = linecolor15 , style = line , linewidth = 1,title = "SuperTrend15")
- //plot(Tsl30, color = linecolor30 , style = linebr , linewidth = 1,title = "SuperTrend30")
- //plot(Tsl60, color = linecolor60 , style = circles, linewidth = 1,title = "SuperTrend60")
- //plot(Tsl120, color = linecolor120 , style = cross,linewidth = 1,title = "SuperTrend120")
- //plot(Tsl240, color = linecolor240 , style = line , linewidth = 1,title = "SuperTrend240")
- plot(TslD, color = linecolorD , style = line , linewidth = 2,title = "SuperTrendD")
- //plot(TslW, color = linecolorW , style = line , linewidth = 2,title = "SuperTrendW")
- // - 1 regular cross
- // If STOCH cross over STOCH smooth on the oversold / overbought areas:
- bullish_stoch_cross = crossover (k,d)
- bearish_stoch_cross = crossunder(k,d)
- // - 2 cross on edges
- medium_bullish_stoch_cross = crossover (k,d) and k < StochOverSold
- medium_bearish_stoch_cross = crossunder(k,d) and k > StochOverBought
- // - 3 trend reversal
- // If STOCH cross back from oversold
- strong_bullish_stoch_cross = crossover(k,StochOverSold)
- strong_bearish_stoch_cross = crossunder(k,StochOverBought)
- plotshape( is_bullish and medium_bullish_stoch_cross, style=shape.triangleup, location= location.belowbar, color=green, size=size.small, transp=0)
- plotshape( is_bearish and medium_bearish_stoch_cross, style=shape.triangledown, location= location.abovebar, color=red , size=size.small, transp=0)
- plotshape( is_bullish and medium_bullish_stoch_cross, style=shape.triangleup, location= location.belowbar, color=white, size=size.normal, transp=0)
- plotshape( is_bearish and medium_bearish_stoch_cross, style=shape.triangledown, location= location.abovebar, color=white , size=size.normal, transp=0)
- 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)
- 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)
- plotshape( is_bullish and strong_bullish_stoch_cross, style=shape.triangleup , location= location.belowbar, color=green, size=size.small, transp=0)
- plotshape( is_bearish and strong_bearish_stoch_cross, style=shape.triangledown, location= location.abovebar, color=red, size=size.small, transp=0)
- plotshape( is_bearish and strong_bullish_stoch_cross, style=shape.xcross , location= location.belowbar, color=red, size=size.small, transp=0)
- plotshape( is_bullish and strong_bearish_stoch_cross, style=shape.xcross, location= location.abovebar, color=green, size=size.small, transp=0)
- // ~ PLOTTING
- trend_colour = is_bearish and is_bullish ? gray : ( is_bearish ? red : green )
- //plot( sma( close, sma_slow ), 'slow sma', color=gray, linewidth=1, transp=20)
- //plot( sma( close, sma_fast ), 'fast sma', color=trend_colour, linewidth=4 )
- alertcondition(is_bullish and strong_bullish_stoch_cross, title='Smaoch: Long', message='Smaoch: Long ')
- alertcondition(is_bearish and strong_bearish_stoch_cross, title='Smaoch: Short', message='Smaoch: Short ')
- 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 ')
- 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 ')
- alertcondition(is_bullish and medium_bullish_stoch_cross, title='Smaoch: Upcoming Long', message='Smaoch: Upcoming Long ')
- alertcondition(is_bearish and medium_bearish_stoch_cross, title='Smaoch: Upcoming Short', message='Smaoch: Upcoming Short ')
- alertcondition(is_bullish and strong_bearish_stoch_cross, title='Smaoch: Exit Long', message='Smaoch: Exit Long ')
- alertcondition(is_bearish and strong_bullish_stoch_cross, title='Smaoch: Exit Short', message='Smaoch: Exit Short ')
- if ((year >= 2010) and (year <= 2016))
- strategy.close("short", when = is_bearish and strong_bullish_stoch_cross)
- //strategy.exit("short SL", "short", loss = lossinpoints)
- strategy.entry("short", strategy.short, when = is_bearish and strong_bearish_stoch_cross)
- if ((year >= 2010) and (year <= 2016))
- strategy.close("long", when = is_bullish and strong_bearish_stoch_cross)
- //strategy.exit("long SL", "long", loss = lossinpoints)
- strategy.entry("long", strategy.long, when = is_bullish and strong_bullish_stoch_cross)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement