Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=3
- strategy(title="Indicator agreement", shorttitle="IA", overlay=false, pyramiding=1, default_qty_type=strategy.percent_of_equity, default_qty_value=10, currency=currency.USD, initial_capital=1500, commission_type= strategy.commission.percent, commission_value= 0.1)
- ////Ichimoku Cloud
- middleDonchian(Length) =>
- lower = lowest(Length)
- upper = highest(Length)
- avg(upper, lower)
- conversionPeriods = 9
- basePeriods = 26
- laggingSpan2Periods = 52
- displacement = 26
- Tenkan = middleDonchian(conversionPeriods)
- Kijun = middleDonchian(basePeriods)
- xChikou = close
- SenkouA = middleDonchian(laggingSpan2Periods)[displacement]
- SenkouB = (Tenkan[basePeriods] + Kijun[basePeriods]) / 2
- ichiSignal = na
- ichiSignalScore = na
- ichiWasNeutral = false
- ichiWasNeutral := ((SenkouA[1] > SenkouB[1] ? (close[1] < SenkouA[1] and close[1] > SenkouB[1]) : (close[1] < SenkouB[1] and close[1] > SenkouA[1])) and not na(SenkouA) and not na(SenkouB)) or ichiWasNeutral[1]
- ichilong = ((crossunder(close, SenkouA < SenkouB ? SenkouA : SenkouB) and ichiSignalScore[1] <= 0 and ichiWasNeutral) ? 1 : 0) + ((crossunder(close, SenkouA < SenkouB ? SenkouB : SenkouA) and ichiSignalScore[1] <= -1 and ichiWasNeutral) ? 1 : 0)
- ichishort = ((crossover(close, SenkouA < SenkouB ? SenkouB : SenkouA) and ichiSignalScore[1] >= 0 and ichiWasNeutral) ? -1 : 0) + ((crossover(close, SenkouA < SenkouB ? SenkouA : SenkouB) and ichiSignalScore[1] >= 1 and ichiWasNeutral) ? -1 : 0)
- ichiSignal := ichilong + ichishort
- ichiSignalScore := nz(ichiSignalScore[1]) + nz(ichiSignal)
- ////RSI
- rsisrc = close,
- rsilen = 14
- rsilen2 = 1
- rsiup = rma(max(change(rsisrc), 0), rsilen)
- rsidown = rma(-min(change(rsisrc), 0), rsilen)
- rsi = rsidown == 0 ? 100 : rsiup == 0 ? 0 : 100 - (100 / (1 + rsiup / rsidown))
- emaRSI = ema(rsi,rsilen2)
- rsiSignal = na
- rsiSignalScore = na
- rsiWasNeutral = false
- rsiWasNeutral := nz(rsi[1]) < 70 and nz(rsi[1]) > 30 or rsiWasNeutral[1]
- rsilong = ((crossover(rsi, 30) and rsiSignalScore[1] <= 0 and rsiWasNeutral) ? 1 : 0) + ((crossover(rsi, 70) and rsiSignalScore[1] <= -1 and rsiWasNeutral) ? 1 : 0)
- rsishort = ((crossunder(rsi, 70) and rsiSignalScore[1] >= 0 and rsiWasNeutral) ? -1 : 0) + ((crossunder(rsi, 30) and rsiSignalScore[1] >= 1 and rsiWasNeutral) ? -1 : 0)
- rsiSignal := rsilong + rsishort
- rsiSignalScore := nz(rsiSignalScore[1]) + nz(rsiSignal)
- ////MACD
- macdfast_length = 12
- macdslow_length = 26
- macdsrc = close
- signal_length = 9
- sma_source = false
- sma_signal = false
- col_grow_above = #26A69A
- col_grow_below = #FFCDD2
- col_fall_above = #B2DFDB
- col_fall_below = #EF5350
- col_macd = #0094ff
- col_signal = #ff6a00
- fast_ma = sma_source ? sma(macdsrc, macdfast_length) : ema(macdsrc, macdfast_length)
- slow_ma = sma_source ? sma(macdsrc, macdslow_length) : ema(macdsrc, macdslow_length)
- macd = fast_ma - slow_ma
- signal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length)
- hist = macd - signal
- macdSignal = na
- macdSignalScore = na
- macdWasNeutral = false
- macdWasNeutral := nz(macdSignal[1]) != 0 or macdWasNeutral[1]
- macdlong = ((crossunder(macd, 0) and macdSignalScore[1] <= 0) ? (macdWasNeutral ? 2 : 1) : 0)
- macdshort = ((crossover(macd, 0) and macdSignalScore[1] >= 0) ? (macdWasNeutral ? -2 : -1) : 0)
- macdSignal := macdlong + macdshort
- macdSignalScore := nz(macdSignalScore[1]) + nz(macdSignal)
- ////KDJ
- ilong = 21
- isig = 13
- bcwsma(s,l,m) =>
- _s = s
- _l = l
- _m = m
- _bcwsma = na
- _bcwsma := (_m*_s+(_l-_m)*nz(_bcwsma[1]))/_l
- _bcwsma
- c = close
- h = highest(high, ilong)
- l = lowest(low,ilong)
- RSV = 100*((c-l)/(h-l))
- pK = bcwsma(RSV, isig, 1)
- pD = bcwsma(pK, isig, 1)
- pJ = 3 * pK-2 * pD
- kdjSignal = na
- kdjSignalScore = na
- kdjWasNeutral = false
- kdjWasNeutral := nz(pJ[1]) < 80 and nz(pJ[1]) > 20 or kdjWasNeutral[1]
- kdjlong = ((crossunder(pJ, 20) and kdjSignalScore[1] <= 0 and kdjWasNeutral) ? 1 : 0) + ((crossunder(pJ, 80) and kdjSignalScore[1] <= -1 and kdjWasNeutral) ? 1 : 0)
- kdjshort = ((crossover(pJ, 80) and kdjSignalScore[1] >= 0 and kdjWasNeutral) ? -1 : 0) + ((crossover(pJ, 20) and kdjSignalScore[1] >= 1 and kdjWasNeutral) ? -1 : 0)
- kdjSignal := kdjlong + kdjshort
- kdjSignalScore := nz(kdjSignalScore[1]) + nz(kdjSignal)
- ////OBV
- obvsrc = close
- obv = cum(change(obvsrc) > 0 ? volume : change(obvsrc) < 0 ? -volume : 0*volume)
- ////BollBand
- BBlength = 20
- BBsrc = close
- BBmult = 2.0
- basis = sma(BBsrc, BBlength)
- BBdev = BBmult * stdev(BBsrc, BBlength)
- upperBB = basis + BBdev
- lowerBB = basis - BBdev
- bbSignal = na
- bbSignalScore = na
- bbWasNeutral = false
- bbWasNeutral := nz(close[1]) < upperBB and nz(close[1]) > lowerBB or bbWasNeutral[1]
- bblong = ((crossunder(close, lowerBB) and bbSignalScore[1] <= 0 and bbWasNeutral) ? 1 : 0) + ((crossunder(close, upperBB) and bbSignalScore[1] <= -1 and bbWasNeutral) ? 1 : 0)
- bbshort = ((crossover(close, upperBB) and bbSignalScore[1] >= 0 and bbWasNeutral) ? -1 : 0) + ((crossover(close, lowerBB) and bbSignalScore[1] >= 1 and bbWasNeutral) ? -1 : 0)
- bbSignal := bblong + bbshort
- bbSignalScore := nz(bbSignalScore[1]) + nz(bbSignal)
- ////EMA's
- M1=ema(close,13)
- M2=ema(close,48)
- emaSignal = na
- emaSignalScore = na
- emaWasNeutral = false
- emaWasNeutral := nz(emaSignal[1]) != 0 or emaWasNeutral[1]
- emalong = ((crossover(M1, close) and emaSignalScore[1] <= 0) ? (emaWasNeutral ? 2 : 1) : 0)
- emashort = ((crossunder(M1, close) and emaSignalScore[1] >= 0) ? (emaWasNeutral ? -2 : -1) : 0)
- emaSignal := emalong + emashort
- emaSignalScore := nz(emaSignalScore[1]) + nz(emaSignal)
- ////Stoch
- periodK = 14
- periodD = 3
- smoothK = 3
- k = sma(stoch(close, high, low, periodK), smoothK)
- d = sma(k, periodD)
- stochSignal = na
- stochSignalScore = na
- stochWasNeutral = false
- stochWasNeutral := nz(k[1]) < 90 and nz(k[1]) > 10 or stochWasNeutral[1]
- stochlong = ((crossunder(k, 10) and stochSignalScore[1] <= 0 and stochWasNeutral) ? 1 : 0) + ((crossunder(k, 90) and stochSignalScore[1] <= -1 and stochWasNeutral) ? 1 : 0)
- stochshort = ((crossover(k, 90) and stochSignalScore[1] >= 0 and stochWasNeutral) ? -1 : 0) + ((crossover(k, 10) and stochSignalScore[1] >= 1 and stochWasNeutral) ? -1 : 0)
- stochSignal := stochlong + stochshort
- stochSignalScore := nz(stochSignalScore[1]) + nz(stochSignal)
- ////CCI
- ccilength = 20
- ccisrc = close
- ccima = sma(ccisrc, ccilength)
- cci = (ccisrc - ccima) / (0.015 * dev(ccisrc, ccilength))
- cciSignal = na
- cciSignalScore = na
- cciWasNeutral = false
- cciWasNeutral := nz(cci[1]) < 250 and nz(cci[1]) > -250 or cciWasNeutral[1]
- ccilong = ((crossunder(cci, -250) and cciSignalScore[1] <= 0 and cciWasNeutral) ? 1 : 0) + ((crossunder(cci, 250) and cciSignalScore[1] <= -1 and cciWasNeutral) ? 1 : 0)
- ccishort = ((crossover(cci, 250) and cciSignalScore[1] >= 0 and cciWasNeutral) ? -1 : 0) + ((crossover(cci, -250) and cciSignalScore[1] >= 1 and cciWasNeutral) ? -1 : 0)
- cciSignal := ccilong + ccishort
- cciSignalScore := nz(cciSignalScore[1]) + nz(cciSignal)
- ////VWMA
- vwshortsrc = close, vwshortlen = 1
- vwlongsrc = close, vwlonglen = 72
- vwmashortlength = vwma(vwshortsrc, vwshortlen)
- vwmalonglength = vwma(vwlongsrc, vwlonglen)
- vwmaSignal = na
- vwmaSignalScore = na
- vwmaWasNeutral = false
- vwmaWasNeutral := nz(vwmaSignal[1]) != 0 or vwmaWasNeutral[1]
- vwmalong = ((crossunder(close, vwmalonglength) and vwmaSignalScore[1] <= 0) ? (vwmaWasNeutral ? 2 : 1) : 0)
- vwmashort = ((crossover(close, vwmalonglength) and vwmaSignalScore[1] >= 0) ? (vwmaWasNeutral ? -2 : -1) : 0)
- vwmaSignal := vwmalong + vwmashort
- vwmaSignalScore := nz(vwmaSignalScore[1]) + nz(vwmaSignal)
- ////TRIX
- trixlength = 9
- trixout = 10000 * change(ema(ema(ema(log(close), trixlength), trixlength), trixlength))
- trixSignal = na
- trixSignalScore = na
- trixWasNeutral = false
- trixWasNeutral := nz(trixout[1]) < 20 and nz(trixout[1]) > -20 or trixWasNeutral[1]
- trixlong = ((crossunder(trixout, -20) and trixSignalScore[1] <= 0 and trixWasNeutral) ? 1 : 0) + ((crossunder(trixout, 20) and trixSignalScore[1] <= -1 and trixWasNeutral) ? 1 : 0)
- trixshort = ((crossover(trixout, 20) and trixSignalScore[1] >= 0 and trixWasNeutral) ? -1 : 0) + ((crossover(trixout, -20) and trixSignalScore[1] >= 1 and trixWasNeutral) ? -1 : 0)
- trixSignal := trixlong + trixshort
- trixSignalScore := nz(trixSignalScore[1]) + nz(trixSignal)
- ////Williams R
- wrlength = 14
- upper = highest(wrlength)
- lower = lowest(wrlength)
- wrout = 100 * (close - upper) / (upper - lower)
- wrSignal = na
- wrSignalScore = na
- wrWasNeutral = false
- wrWasNeutral := nz(wrout[1]) < -10 and nz(wrout[1]) > -90 or wrWasNeutral[1]
- wrlong = ((crossunder(wrout, -90) and wrSignalScore[1] <= 0 and wrWasNeutral) ? 1 : 0) + ((crossunder(wrout, -10) and wrSignalScore[1] <= -1 and wrWasNeutral) ? 1 : 0)
- wrshort = ((crossover(wrout, -10) and wrSignalScore[1] >= 0 and wrWasNeutral) ? -1 : 0) + ((crossover(wrout,-90) and wrSignalScore[1] >= 1 and wrWasNeutral) ? -1 : 0)
- wrSignal := wrlong + wrshort
- wrSignalScore := nz(wrSignalScore[1]) + nz(wrSignal)
- ////DMI + ADX
- dmilen = 14
- lensig = 14
- dmiup = change(high)
- dmidown = -change(low)
- plusDM = na(dmiup) ? na : (dmiup > dmidown and dmiup > 0 ? dmiup : 0)
- minusDM = na(dmidown) ? na : (dmidown > dmiup and dmidown > 0 ? dmidown : 0)
- trur = rma(tr, dmilen)
- plus = fixnan(100 * rma(plusDM, dmilen) / trur)
- minus = fixnan(100 * rma(minusDM, dmilen) / trur)
- dmisum = plus + minus
- dmiadx = 100 * rma(abs(plus - minus) / (dmisum == 0 ? 1 : dmisum), lensig)
- dmiSignal = na
- dmiSignalScore = na
- dmiWasNeutral = false
- dmiWasNeutral := nz(dmiSignal[1]) != 0 or dmiWasNeutral[1]
- dmilong = ((crossunder(plus,minus) and dmiSignalScore[1] <= 0) ? (dmiWasNeutral ? 2 : 1) : 0)
- dmishort = ((crossover(plus,minus) and dmiSignalScore[1] >= 0) ? (dmiWasNeutral ? -2 : -1) : 0)
- dmiSignal := dmilong + dmishort
- dmiSignalScore := nz(dmiSignalScore[1]) + nz(dmiSignal)
- adxSignal = na
- adxSignalScore = na
- adxWasNeutral = false
- adxWasNeutral := nz(adxSignal[1]) != 0 or adxWasNeutral[1]
- adxlong = ((crossunder(dmiadx, 40) and adxSignalScore[1] <= 0) ? (adxWasNeutral ? 2 : 1) : 0)
- adxshort = ((crossover(dmiadx, 40) and adxSignalScore[1] >= 0) ? (adxWasNeutral ? -2 : -1) : 0)
- adxSignal := adxlong + adxshort
- adxSignalScore := nz(adxSignalScore[1]) + nz(adxSignal)
- ////MOM
- mtmlen = 10
- mtmsrc = close
- mom = mtmsrc - mtmsrc[mtmlen]
- momSignal = na
- momSignalScore = na
- momWasNeutral = false
- momWasNeutral := nz(mom[1]) <4 and nz(mom[1]) > -4 or momWasNeutral[1]
- momlong = ((crossunder(mom, -4) and momSignalScore[1] <= 0 and momWasNeutral) ? 1 : 0) + ((crossunder(mom,4) and momSignalScore[1] <= -1 and momWasNeutral) ? 1 : 0)
- momshort = ((crossover(mom,4) and momSignalScore[1] >= 0 and momWasNeutral) ? -1 : 0) + ((crossover(mom, -4) and momSignalScore[1] >= 1 and momWasNeutral) ? -1 : 0)
- momSignal := momlong + momshort
- momSignalScore := nz(momSignalScore[1]) + nz(momSignal)
- ////Parabolic SAR
- sarstart = 0.02
- increment = 0.02
- maximum = 0.2
- sarout = sar(sarstart, increment, maximum)
- sarSignal = na
- sarSignalScore = na
- sarWasNeutral = false
- sarWasNeutral := nz(sarSignal[1]) != 0 or sarWasNeutral[1]
- sarlong = ((crossunder(close, sarout) and sarSignalScore[1] <= 0) ? (sarWasNeutral ? 2 : 1) : 0)
- sarshort = ((crossover(close, sarout) and sarSignalScore[1] >= 0) ? (sarWasNeutral ? -2 : -1) : 0)
- sarSignal := sarlong + sarshort
- sarSignalScore := nz(sarSignalScore[1]) + nz(sarSignal)
- ////EOM
- emvdiv = 10000
- emvlength = 14
- eom = sma(emvdiv * change(hl2) * (high - low) / volume, emvlength)
- topBand = 0.5
- bottomBand = -0.5
- eomSignal = na
- eomSignalScore = na
- eomWasNeutral = false
- eomWasNeutral := nz(eom[1]) < topBand and nz(eom[1]) > bottomBand or eomWasNeutral[1]
- eomlong = ((crossunder(eom, bottomBand) and eomSignalScore[1] <= 0 and eomWasNeutral) ? 1 : 0) + ((crossunder(eom,topBand) and eomSignalScore[1] <= -1 and eomWasNeutral) ? 1 : 0)
- eomshort = ((crossover(eom,topBand) and eomSignalScore[1] >= 0 and eomWasNeutral) ? -1 : 0) + ((crossover(eom, bottomBand) and eomSignalScore[1] >= 1 and eomWasNeutral) ? -1 : 0)
- eomSignal := eomlong + eomshort
- eomSignalScore := nz(eomSignalScore[1]) + nz(eomSignal)
- ////AutoFib (FIX THIS BEFORE USING)
- fiblength=265
- maxr = highest(close, fiblength)
- minr = lowest(close, fiblength)
- ranr = maxr - minr
- autofiblong = 0 + (crossunder(close, (maxr - 0.786 * ranr)) ? 1 : 0) + (crossunder(close, (maxr - 0.236 * ranr)) ? 1 : 0)
- autofibshort = 0 - (crossover(close, (maxr - 0.236 * ranr)) ? 1 : 0) - (crossover(close, (maxr - 0.786 * ranr)) ? 1 : 0)
- autofibSignal = autofiblong + autofibshort
- ////Vwap
- vwapsrc = hlc3
- t = time("D")
- vwapstart = na(t[1]) or t > t[1]
- vwapsumSrc = vwapsrc * volume
- vwapsumVol = volume
- vwapsumSrc := vwapstart ? vwapsumSrc : vwapsumSrc + vwapsumSrc[1]
- vwapsumVol := vwapstart ? vwapsumVol : vwapsumVol + vwapsumVol[1]
- vWap= vwapsumSrc/vwapsumVol
- vwapSignal = na
- vwapSignalScore = na
- vwapWasNeutral = false
- vwapWasNeutral := nz(vwapSignal[1]) != 0 or vwapWasNeutral[1]
- vwaplong = ((crossunder(close, vWap) and vwapSignalScore[1] <= 0) ? (vwapWasNeutral ? 2 : 1) : 0)
- vwapshort = ((crossover(close, vWap) and vwapSignalScore[1] >= 0) ? (vwapWasNeutral ? -2 : -1) : 0)
- vwapSignal := vwaplong + vwapshort
- vwapSignalScore := nz(vwapSignalScore[1]) + nz(vwapSignal)
- ////Fisher Transform
- fishlen = 9
- fishhigh_ = highest(hl2, fishlen)
- fishlow_ = lowest(hl2, fishlen)
- fishround_(val) => val > .99 ? .999 : val < -.99 ? -.999 : val
- value = 0.0
- value := fishround_(.66 * ((hl2 - fishlow_) / max(fishhigh_ - fishlow_, .001) - .5) + .67 * nz(value[1]))
- fish1 = 0.0
- fish1 := .5 * log((1 + value) / max(1 - value, .001)) + .5 * nz(fish1[1])
- fish2 = fish1[1]
- topFishLevel= 3
- bottomFishLevel= -3
- fishSignal = na
- fishSignalScore = na
- fishWasNeutral = false
- fishWasNeutral := nz(fish1[1]) < topFishLevel and nz(fish1[1]) > bottomFishLevel or fishWasNeutral[1]
- fishlong = ((crossunder(fish1, bottomFishLevel) and fishSignalScore[1] <= 0 and fishWasNeutral) ? 1 : 0) + ((crossunder(fish1,topFishLevel) and fishSignalScore[1] <= -1 and fishWasNeutral) ? 1 : 0)
- fishshort = ((crossover(fish1,topFishLevel) and fishSignalScore[1] >= 0 and fishWasNeutral) ? -1 : 0) + ((crossover(fish1, bottomFishLevel) and fishSignalScore[1] >= 1 and fishWasNeutral) ? -1 : 0)
- fishSignal := fishlong + fishshort
- fishSignalScore := nz(fishSignalScore[1]) + nz(fishSignal)
- ////VW Keltner bands
- emaLenLong = 3
- emaLenShort = 3
- atrLen = 10
- multiplier = 1
- srcLong = low
- srcShort = high
- emLong = vwma(srcLong, emaLenLong)
- emShort = vwma(srcShort, emaLenShort)
- mATRLong = multiplier * atr(atrLen)
- mATRShort = multiplier * atr(atrLen)
- kcSignal = na
- kcSignalScore = na
- kcWasNeutral = false
- kcWasNeutral := nz(low[1]) > (emLong - mATRLong) and nz(high[1]) < (emShort + mATRShort) or kcWasNeutral[1]
- kclong = ((crossunder(low, (emLong - mATRLong)) and kcSignalScore[1] <= 0 and kcWasNeutral) ? 1 : 0) + ((crossunder(high, (emShort + mATRShort)) and kcSignalScore[1] <= -1 and kcWasNeutral) ? 1 : 0)
- kcshort = ((crossover(high, (emShort + mATRShort)) and kcSignalScore[1] >= 0 and kcWasNeutral) ? -1 : 0) + ((crossover(low, (emLong - mATRLong)) and kcSignalScore[1] >= 1 and kcWasNeutral) ? -1 : 0)
- kcSignal := kclong + kcshort
- kcSignalScore := nz(kcSignalScore[1]) + nz(kcSignal)
- ////////////////////////////////////////////////////////////////////////////////
- signalScore = na
- signalScore:= nz(signalScore[1]) + bbSignal + cciSignal + eomSignal + stochSignal + trixSignal + dmiSignal + macdSignal + rsiSignal + wrSignal + momSignal + ichiSignal + vwapSignal + fishSignal + kcSignal + emaSignal
- //signalScore:= nz(signalScore[1]) + kcSignal
- ////not in use: sarSignal + adxSignal + vwmaSignal + kdjSignal
- plot(signalScore, color = signalScore >= 0 ? green : red, linewidth = 1, style = histogram)
- hline(0)
- longEntryRequirment= input(title="Long entry requirment", type=integer, defval=13)
- longExitRequirment= input(title="Long exit requirment", type=integer, defval=-13)
- shortEntryRequirment= input(title="Short entry requirment", type=integer, defval=-10)
- shortExitRequirment= input(title="Short exit requirment", type=integer, defval=10)
- signalScoreLongEntry = signalScore==longEntryRequirment
- signalScoreLongExit = signalScore==longExitRequirment
- signalScoreShortEntry = signalScore==shortEntryRequirment
- signalScoreShortExit = signalScore==shortExitRequirment
- previousSignalScoreLong = signalScoreLongEntry[1] or signalScoreLongEntry[2] or signalScoreLongEntry[3] or signalScoreLongEntry[4] or signalScoreLongEntry[5]
- previousSignalScoreShort = signalScoreShortEntry[1] or signalScoreShortEntry[2] or signalScoreShortEntry[3] or signalScoreShortEntry[4] or signalScoreShortEntry[5]
- longEntryCondition= signalScoreLongEntry and not (previousSignalScoreLong or strategy.position_size < 0)
- longExitCondition= signalScoreLongExit
- shortEntryCondition= signalScoreShortEntry and not (previousSignalScoreShort or strategy.position_size > 0)
- shortExitCondition= signalScoreShortExit
- strategy.entry("Long", strategy.long, when= longEntryCondition)
- //strategy.entry("Short", strategy.short, when= shortEntryCondition)
- strategy.close("Long", when= longExitCondition)
- //strategy.close("Short", when= shortExitCondition)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement