Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=4
- strategy(title="S&P Bear Warning", shorttitle="Bear Warning", pyramiding=0,
- currency=currency.USD, default_qty_type=strategy.percent_of_equity, default_qty_value=100,
- initial_capital=10000, commission_value=0.1)
- //Momentum
- len = input(50, minval=1, title="Length")
- src = input(close, title="Source")
- bandUpper = input( 5)
- bandLower = input(-5)
- pivotLegs = input(10)
- // ————— Control plotting of each signal. You could use the same technique to be able to turn acc/dist on/off.
- showVixFix = input(true)
- showMomentum = input(false)
- mom = src - src[len]
- momPivotLo = pivotlow(mom, pivotLegs, pivotLegs)
- myAtr = atr(14)
- momBull = mom > myAtr
- plot(showMomentum ? mom : na, color=mom > 0 ? color.blue : color.maroon, title="MOM")
- plot(showMomentum ? 0 : na, color=color.silver, title="MOM Zero line", style=plot.style_circles)
- plot(showMomentum ? myAtr : na, color=color.orange, title="ATR")
- priceMaLen = input(25, minval=1, title="Length")
- priceMaFast = ema(close, priceMaLen)
- priceMaSlow = ema(close, priceMaLen * 6)
- priceBull = priceMaFast > priceMaSlow
- //VIX
- VIXFixLength = input(22,title="VIX Fix Length")
- VIXFix = (highest(close,VIXFixLength)-low)/(highest(close,VIXFixLength))*100
- vixMaFast = ema(VIXFix, VIXFixLength * 2)
- vixMaSlow = ema(VIXFix, VIXFixLength * 6)
- vixBull = vixMaFast < vixMaSlow
- plot(showVixFix ? VIXFix : na, "VIXFix", color.lime, 1)
- plot(showVixFix ? vixMaFast : na, "VIXFix MA", color.green, 1)
- plot(showVixFix ? vixMaSlow : na, "VIXFix MA", color.purple, 1)
- band1 = plot(showVixFix ? bandUpper : na, "Upper Band", color.maroon, 1, plot.style_circles, transp = 70)
- band0 = plot(showVixFix ? bandLower : na, "Lower Band", color.maroon, 1, plot.style_circles, transp = 70)
- fill(band1, band0, color=color.red, transp=90, title="Background")
- priceAndVixBull = vixBull and priceBull
- priceAndVixBear = not vixBull and not priceBull
- bgcolor(priceAndVixBull ? color.green : priceAndVixBear ? color.red : na)
- //Identify Triggers
- //Back Test Range
- start = timestamp("America/New_York", 2000, 1, 1, 9,30)
- end = timestamp("America/New_York", 2020, 7, 1, 0, 0)
- //Momentum
- // Long1 = mom > myAtr
- enterLong = not na(momPivotLo) and priceAndVixBull
- // exitLong = crossover(VIXFix, ema(VIXFix, 100))
- exitLong = priceAndVixBull[1] and not priceAndVixBull
- Short = mom < myAtr
- // Debugging code to visualize your conditions.
- plotchar(enterLong, "enterLong", "▲", location.bottom, color.green, size = size.tiny)
- plotchar(exitLong, "exitLong", "▼", location.top, color.red, size = size.tiny)
- //Entry and Exit
- if time >= start and time <= end
- strategy.entry("Long", true, when = enterLong)
- strategy.close("Long", when = exitLong)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement