Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=3
- strategy("VCI_MTF", overlay=true, shorttitle="VCI_Multi_TimeFrame_OB_OS Strategy", default_qty_type = strategy.percent_of_equity, default_qty_value = 100, initial_capital = 10000, slippage = 5)
- ema1 = input(75, title="fast EMA period", minval=1)
- ema2 = input(7, title="slow EMA period", minval=2)
- atrp = input(3, title="ATR period", minval=1)
- src = input(close, type=source, title="Source")
- // Base=input(title="Larger Res than Chart", defval = "D", type=resolution)
- otf_period = input(defval=9, title="Look Back Period (2nd Timeframe)", type=integer)
- otf = input(defval="30", title="Second Momentum Timeframe", type=resolution)
- vci = (ema(src,ema1)-ema(src,ema2))/atr(atrp)
- vciColor = vci>0? lime:red
- lvl = stdev(vci,atrp)
- // Function to dectect a new bar
- is_newbar(res) =>
- t = time(res)
- change(t) != 0 ? true : false
- // Check how many bars are in our upper timeframe
- since_new_bar = barssince(is_newbar(otf))
- otf_total_bars = na
- otf_total_bars := since_new_bar == 0 ? since_new_bar[1] : otf_total_bars[1]
- breakline=input(title="Breaks in lines", defval = true, type=bool)
- so = security(tickerid, otf, rsi(open, otf_period))
- sh = security(tickerid, otf, rsi(high, otf_period))
- sl = security(tickerid, otf, rsi(low, otf_period))
- sc = security(tickerid, otf, rsi(close, otf_period))
- // br= so != so[1] and sc != sc[1] and sh != sh[1] and sl != sl[1] and breakline == true ? 1 : na
- // col= so > sc ? red : green
- // a1=na(br) ? so : na
- // a2=na(br) ? sh : na
- // a3=na(br) ? sl : na
- // a4=na(br) ? sc : na
- final_otf_so = na
- final_otf_so := barstate.isrealtime ? since_new_bar == otf_total_bars ? so : final_otf_so[1] : so
- final_otf_sc = na
- final_otf_sc := barstate.isrealtime ? since_new_bar == otf_total_bars ? sc : final_otf_sc[1] : sc
- overbough = input(title="Close Overbought", defval=71, step=1)
- oversold = input(title="Close Oversold", defval=37, step=1)
- overbought_vci = input(title="VCI Overbought", defval=2, step=0.1)
- oversold_vci = input(title="VCI Oversold", defval=-2, step=0.1)
- if (final_otf_sc < oversold) and (vci> overbought_vci )
- strategy.entry("LONG", strategy.long, stop=close, oca_name="TREND", oca_type=strategy.oca.cancel, comment="LONG")
- if (final_otf_sc > overbough) and ( vci < oversold_vci)
- strategy.close("LONG")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement