Advertisement
PineCoders

Price and VixFix

Aug 4th, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. //@version=4
  2. strategy(title="S&P Bear Warning", shorttitle="Bear Warning", pyramiding=0,
  3. currency=currency.USD, default_qty_type=strategy.percent_of_equity, default_qty_value=100,
  4. initial_capital=10000, commission_value=0.1)
  5.  
  6. //Momentum
  7. len = input(50, minval=1, title="Length")
  8. src = input(close, title="Source")
  9. bandUpper = input( 5)
  10. bandLower = input(-5)
  11. pivotLegs = input(10)
  12.  
  13. // ————— Control plotting of each signal. You could use the same technique to be able to turn acc/dist on/off.
  14. showVixFix = input(true)
  15. showMomentum = input(false)
  16.  
  17. mom = src - src[len]
  18. momPivotLo = pivotlow(mom, pivotLegs, pivotLegs)
  19. myAtr = atr(14)
  20. momBull = mom > myAtr
  21. plot(showMomentum ? mom : na, color=mom > 0 ? color.blue : color.maroon, title="MOM")
  22. plot(showMomentum ? 0 : na, color=color.silver, title="MOM Zero line", style=plot.style_circles)
  23. plot(showMomentum ? myAtr : na, color=color.orange, title="ATR")
  24.  
  25. priceMaLen = input(25, minval=1, title="Length")
  26. priceMaFast = ema(close, priceMaLen)
  27. priceMaSlow = ema(close, priceMaLen * 6)
  28. priceBull = priceMaFast > priceMaSlow
  29.  
  30. //VIX
  31. VIXFixLength = input(22,title="VIX Fix Length")
  32. VIXFix = (highest(close,VIXFixLength)-low)/(highest(close,VIXFixLength))*100
  33. vixMaFast = ema(VIXFix, VIXFixLength * 2)
  34. vixMaSlow = ema(VIXFix, VIXFixLength * 6)
  35. vixBull = vixMaFast < vixMaSlow
  36. plot(showVixFix ? VIXFix : na, "VIXFix", color.lime, 1)
  37. plot(showVixFix ? vixMaFast : na, "VIXFix MA", color.green, 1)
  38. plot(showVixFix ? vixMaSlow : na, "VIXFix MA", color.purple, 1)
  39. band1 = plot(showVixFix ? bandUpper : na, "Upper Band", color.maroon, 1, plot.style_circles, transp = 70)
  40. band0 = plot(showVixFix ? bandLower : na, "Lower Band", color.maroon, 1, plot.style_circles, transp = 70)
  41. fill(band1, band0, color=color.red, transp=90, title="Background")
  42.  
  43. priceAndVixBull = vixBull and priceBull
  44. priceAndVixBear = not vixBull and not priceBull
  45. bgcolor(priceAndVixBull ? color.green : priceAndVixBear ? color.red : na)
  46. //Identify Triggers
  47. //Back Test Range
  48. start = timestamp("America/New_York", 2000, 1, 1, 9,30)
  49. end = timestamp("America/New_York", 2020, 7, 1, 0, 0)
  50.  
  51. //Momentum
  52. // Long1 = mom > myAtr
  53. enterLong = not na(momPivotLo) and priceAndVixBull
  54. // exitLong = crossover(VIXFix, ema(VIXFix, 100))
  55. exitLong = priceAndVixBull[1] and not priceAndVixBull
  56. Short = mom < myAtr
  57.  
  58. // Debugging code to visualize your conditions.
  59. plotchar(enterLong, "enterLong", "▲", location.bottom, color.green, size = size.tiny)
  60. plotchar(exitLong, "exitLong", "▼", location.top, color.red, size = size.tiny)
  61.  
  62. //Entry and Exit
  63. if time >= start and time <= end
  64. strategy.entry("Long", true, when = enterLong)
  65.  
  66. strategy.close("Long", when = exitLong)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement