Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. //@version=2
  2. strategy("My Strategy", overlay=true)
  3.  
  4. //inputs
  5. src = close
  6. useCurrentRes = input(true, title="Use Current Chart Resolution?")
  7. resCustom = input(title="Use Different Timeframe? Uncheck Box Above", type=resolution, defval="2")
  8. len = input(20, title="Moving Average Length - LookBack Period")
  9. atype = input(1,minval=1,maxval=7,title="1=SMA, 2=EMA, 3=WMA, 4=HullMA, 5=VWMA, 6=RMA, 7=TEMA")
  10. cc = input(true,title="Change Color Based On Direction?")
  11. smoothe = input(2, minval=1, maxval=10, title="Color Smoothing - 1 = No Smoothing")
  12. doma2 = input(false, title="Optional 2nd Moving Average")
  13. len2 = input(50, title="Moving Average Length - Optional 2nd MA")
  14. atype2 = input(1,minval=1,maxval=7,title="1=SMA, 2=EMA, 3=WMA, 4=HullMA, 5=VWMA, 6=RMA, 7=TEMA")
  15. cc2 = input(true,title="Change Color Based On Direction 2nd MA?")
  16. warn = input(false, title="***You Can Turn On The Show Dots Parameter Below Without Plotting 2nd MA to See Crosses***")
  17. warn2 = input(false, title="***If Using Cross Feature W/O Plotting 2ndMA - Make Sure 2ndMA Parameters are Set Correctly***")
  18. sd = input(false, title="Show Dots on Cross of Both MA's")
  19.  
  20.  
  21. res = useCurrentRes ? period : resCustom
  22. //hull ma definition
  23. hullma = wma(2*wma(src, len/2)-wma(src, len), round(sqrt(len)))
  24. //TEMA definition
  25. ema1 = ema(src, len)
  26. ema2 = ema(ema1, len)
  27. ema3 = ema(ema2, len)
  28. tema = 3 * (ema1 - ema2) + ema3
  29.  
  30. avg = atype == 1 ? sma(src,len) : atype == 2 ? ema(src,len) : atype == 3 ? wma(src,len) : atype == 4 ? hullma : atype == 5 ? vwma(src, len) : atype == 6 ? rma(src,len) : tema
  31. //2nd Ma - hull ma definition
  32. hullma2 = wma(2*wma(src, len2/2)-wma(src, len2), round(sqrt(len2)))
  33. //2nd MA TEMA definition
  34. sema1 = ema(src, len2)
  35. sema2 = ema(sema1, len2)
  36. sema3 = ema(sema2, len2)
  37. stema = 3 * (sema1 - sema2) + sema3
  38.  
  39. avg2 = atype2 == 1 ? sma(src,len2) : atype2 == 2 ? ema(src,len2) : atype2 == 3 ? wma(src,len2) : atype2 == 4 ? hullma2 : atype2 == 5 ? vwma(src, len2) : atype2 == 6 ? rma(src,len2) : tema
  40.  
  41. out = avg
  42. out_two = avg2
  43.  
  44. out1 = security(tickerid, res, out)
  45. out2 = security(tickerid, res, out_two)
  46.  
  47. ma_up = out1 >= out2[smoothe]
  48. ma_down = out1 < out2[smoothe]
  49.  
  50. col = cc ? ma_up ? lime : ma_down ? red : aqua : aqua
  51. col2 = cc2 ? ma_up ? lime : ma_down ? red : aqua : aqua
  52.  
  53. barcolor(cc ? ma_up ? lime : ma_down ? red : aqua : aqua)
  54. barcolor(cc2 ? ma_up ? lime : ma_down ? red : aqua : aqua)
  55.  
  56. buy = ma_up
  57. sell = ma_down
  58.  
  59.  
  60. circleYPosition = out2
  61.  
  62. plot(out1, title="Multi-Timeframe Moving Avg", style=line, linewidth=4, color = col)
  63. plot(doma2 and out2 ? out2 : na, title="2nd Multi-TimeFrame Moving Average", style=circles, linewidth=4, color=col2)
  64. plot(sd and cross(out1, out2) ? circleYPosition : na,style=cross, linewidth=5, color=yellow)
  65.  
  66.  
  67.  
  68. longCondition = buy
  69. shortCondition = sell
  70.  
  71. if (longCondition)
  72. strategy.entry( "long",strategy.long, comment = "BUY")
  73.  
  74.  
  75. if(shortCondition)
  76. strategy.entry("short",strategy.short)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement