├── .gitignore ├── README.md ├── averages └── trivwma.pine ├── bands └── vwma-bands.pine ├── bayesian ├── indicators │ └── bbsma.pine └── strategies │ └── bbsmastrat.pine ├── divergences ├── ao.pine ├── cci-high-low.pine ├── cci.pine ├── mfi.pine ├── obv.pine └── stochastic-rsi.pine ├── histograms └── cm-williams-vix-fix-red-green.pine ├── oscillators └── moneyflow.pine ├── pivots └── dailypivots.pine └── reversals ├── engulfing-ema.pine └── engulfing-vwma.pine /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/macos 3 | # Edit at https://www.gitignore.io/?templates=macos 4 | 5 | ### macOS ### 6 | # General 7 | .DS_Store 8 | .AppleDouble 9 | .LSOverride 10 | 11 | # Icon must end with two \r 12 | Icon 13 | 14 | # Thumbnails 15 | ._* 16 | 17 | # Files that might appear in the root of a volume 18 | .DocumentRevisions-V100 19 | .fseventsd 20 | .Spotlight-V100 21 | .TemporaryItems 22 | .Trashes 23 | .VolumeIcon.icns 24 | .com.apple.timemachine.donotpresent 25 | 26 | # Directories potentially created on remote AFP share 27 | .AppleDB 28 | .AppleDesktop 29 | Network Trash Folder 30 | Temporary Items 31 | .apdisk 32 | 33 | # End of https://www.gitignore.io/api/macos 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TradingView Scripts 2 | 3 | This repo contains all of the scripts I wrote for TradingView. 4 | 5 | ## Bands 6 | 7 | The scripts here are bands with usually an upper, mid and bottom ranges. 8 | 9 | ### VWMA Bands 10 | 11 | The bands are composed of these: 12 | 13 | * Upper: VWMA with highs as source 14 | * Mid: VWMA with HL2 as source 15 | * Bottom: VWMA with lows as source 16 | 17 | I find the best period for the band is `5`. It's important for the band to be closer to the price. VWMA is a volume based average, to widen the band, volume must increase. 18 | 19 | There is a threshold setting which is gonna be different for assets and timeframes. Experiment with your own ideas. 20 | 21 | ![VWMA Bands](https://www.tradingview.com/x/bz2mnFAo/) 22 | 23 | ## Oscillators 24 | 25 | The scripts here are oscillators usually being used to spot overbought or oversold conditions which is a load of crap. Using these as divergences spotter bodes well. 26 | 27 | ### Money Flow Index 28 | 29 | Money Flow Index indicator script taken from [https://www.tradingview.com/script/g58H59ub-Money-Flow-Index-Beasley-Savage/](https://www.tradingview.com/script/g58H59ub-Money-Flow-Index-Beasley-Savage/). 30 | 31 | ## Histograms 32 | 33 | The scripts are are histograms to spot weaknesses we can exploit. Also good for divergences if applicable. 34 | 35 | ### CM Williams Fix Vix Red Green 36 | 37 | Modified from [https://www.tradingview.com/script/og7JPrRA-CM-Williams-Vix-Fix-Finds-Market-Bottoms/](https://www.tradingview.com/script/og7JPrRA-CM-Williams-Vix-Fix-Finds-Market-Bottoms/) to also draw red bars for shorting opportunities. 38 | 39 | ## Divergences 40 | 41 | The scripts here will plot bullish and bearish divergences both hiddens or regulars. 42 | 43 | ### Awesome Oscillator Divergences 44 | 45 | This is by far the most accurate divergence indicator in any timeframe. It's hard to go wrong with AO. 46 | 47 | ![AO Divergence](https://www.tradingview.com/x/gvF1C5F3/) 48 | 49 | ### CCI Divergences 50 | 51 | Modified TradingView's built-in `Divergences Indicator` script to use [Commodity Channel Index](https://www.investopedia.com/terms/c/commoditychannelindex.asp) indicator as the oscillator. 52 | 53 | ![CCI Divergence](https://www.tradingview.com/x/hNbi7Dnp/) 54 | 55 | ### CCI High/Low Divergences 56 | 57 | Modified TradingView's built-in `Divergences Indicator` script to use [Commodity Channel Index](https://www.investopedia.com/terms/c/commoditychannelindex.asp) indicator as the oscillator. There are 2 oscillators with bullish divergences calculated from candle lows while bearish divergences are calculated from candle highs. 58 | 59 | ![CCI High/Low Divergence](https://www.tradingview.com/x/jLaK5H5Q/) 60 | 61 | ### MFI Divergences 62 | 63 | Modified TradingView's built in `Divergences Indicator` script to use [Money Flow Index](https://www.investopedia.com/terms/m/mfi.asp) indicator as the oscillator. Money Flow Index indicator script taken from [https://www.tradingview.com/script/g58H59ub-Money-Flow-Index-Beasley-Savage/](https://www.tradingview.com/script/g58H59ub-Money-Flow-Index-Beasley-Savage/). 64 | 65 | ![MFI Divergence](https://www.tradingview.com/x/W1sAty3D/) 66 | 67 | ### OBV Divergences 68 | 69 | This indicator uses On Balance Volume indicator as the oscillator to spot for divergences. 70 | 71 | ![OBV Divergence](https://www.tradingview.com/x/EGrGG5IM/) 72 | 73 | ### Stochastic RSI Divergence 74 | 75 | This indicator uses Stochastic RSI indicator as the oscillator to spot for divergences. 76 | 77 | ![Stochastic RSI Divergence](https://www.tradingview.com/x/7EYAukaG/) 78 | 79 | ## Averages 80 | 81 | The scripts here will plot moving average indicators. 82 | 83 | ### Tri VWMA 84 | 85 | Use 3 VWMA ribbons with only 1 indicator. 86 | 87 | ![Tri VWMA](https://www.tradingview.com/x/ihqC6HRE/) 88 | 89 | ## Reversals 90 | 91 | The scripts here mainly highlight reversals. 92 | 93 | ### Engulfing - EMA 94 | 95 | This script will highlight bullish and bearish engulfing candles with arrows on your chart. Using EMA as a confirmation if you wish to draw the arrows. 96 | 97 | ![Engulfing Candles - EMA](https://www.tradingview.com/x/MLs4ArAb/) 98 | 99 | ### Engulfing - VWMA 100 | 101 | This script will highlight bullish and bearish engulfing candles with arrows on your chart. Using VWMA as a confirmation if you wish to draw the arrows. Also shows a second VWMA line for reference. 102 | 103 | ![Engulfing Candles - VWMA](https://www.tradingview.com/x/jP4lbLP8/) 104 | 105 | ## Pivots 106 | 107 | Pivot Points to show support/resistance. 108 | 109 | ### Daily Pivot Points 110 | 111 | Uses the previous day's values to project today's pivots. Automatically updated when daily candles are closed. 112 | 113 | ![Daily Pivot Points](https://www.tradingview.com/x/Q7Q9yWad/) 114 | -------------------------------------------------------------------------------- /averages/trivwma.pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © tista 3 | 4 | //@version=4 5 | study("Tri VWMA", shorttitle="TriVWMA", precision=2, overlay=true) 6 | 7 | vwma1_length = input(title="VWMA1 Length", type=input.integer, defval=21) 8 | vwma2_length = input(title="VWMA2 Length", type=input.integer, defval=55) 9 | vwma3_length = input(title="VWMA3 Length", type=input.integer, defval=224) 10 | 11 | vwma1 = vwma(close, vwma1_length) 12 | vwma2 = vwma(close, vwma2_length) 13 | vwma3 = vwma(close, vwma3_length) 14 | 15 | plot(vwma1, title="VWMA1", color=#00bcd4, linewidth=3) 16 | plot(vwma2, title="VWMA2", color=#66bb6a, linewidth=3) 17 | plot(vwma3, title="VWMA3", color=#e91e62, linewidth=3) 18 | -------------------------------------------------------------------------------- /bands/vwma-bands.pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © tista 3 | 4 | //@version=4 5 | study("VWMA Band", overlay=true) 6 | 7 | vwmaPeriod = input(title="VWMA Period", defval=5) 8 | showVwmaBand = input(title="Show VWMA Band", defval=true) 9 | minThreshold = input(title="Minimum Threshold", defval=26.0) 10 | 11 | vwmaHigh = vwma(high, vwmaPeriod) 12 | vwmaLow = vwma(low, vwmaPeriod) 13 | vwmaHl2 = vwma(hl2, vwmaPeriod) 14 | vwmaClose = vwma(close, vwmaPeriod) 15 | diff = vwmaHigh - vwmaLow 16 | 17 | closeUnderHL2 = crossunder(vwmaClose, vwmaHl2) and open > vwmaClose and diff >= minThreshold ? -1 : na 18 | closeOverHL2 = crossover(vwmaClose, vwmaHl2) and open < vwmaClose and diff >= minThreshold ? 1 : na 19 | 20 | alertcondition(closeUnderHL2, title="VWMA Band - Short", message="VWMA Close just crossed under VWMA HL2, time to short.") 21 | alertcondition(closeOverHL2, title="VWMA Band - Long", message="VWMA Close just crossed over VWMA HL2, time to long.") 22 | 23 | bandHigh = plot(showVwmaBand ? vwmaHigh : na, title="VWMA High", color=color.white, linewidth=1, transp=80) 24 | bandLow = plot(showVwmaBand ? vwmaLow : na, title="VWMA Low", color=color.white, linewidth=1, transp=80) 25 | plot(showVwmaBand ? vwmaHl2 : na, title="VWMA HL2", color=color.white, linewidth=1, transp=80) 26 | plot(vwmaClose, title="VWMA Close", color=color.blue, linewidth=2, transp=0) 27 | 28 | plotarrow(closeUnderHL2, title="Close Under HL2", colordown=color.orange, colorup=color.green, maxheight=15) 29 | plotarrow(closeOverHL2, title="Close Over HL2", colordown=color.orange, colorup=color.green, maxheight=15) 30 | fill(bandLow, bandHigh, title="VWMA Band", color=color.white, transp=95) 31 | 32 | -------------------------------------------------------------------------------- /bayesian/indicators/bbsma.pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © tista 3 | 4 | //@version=4 5 | study("Bayesian BBSMA Oscillator", shorttitle="BayesBbSmaOsc") 6 | 7 | bbSmaPeriod = input(20, title="BB SMA Period") 8 | bbStdDevMult = input(2.5, title="BB Standard Deviation", maxval=50.0) 9 | 10 | bbBasis = sma(close, bbSmaPeriod) 11 | bbStdDev = bbStdDevMult * stdev(close, bbSmaPeriod) 12 | 13 | bbUpper = bbBasis + bbStdDev 14 | bbLower = bbBasis - bbStdDev 15 | 16 | // SMA 17 | smaPeriod = input(20, title="SMA Period") 18 | smaValues = sma(close, smaPeriod) 19 | 20 | 21 | // Bayesian Theorem Starts 22 | bayesPeriod = input(20, title="Bayesian Lookback Period") 23 | 24 | // Next candles are breaking Down 25 | probBbUpperUpSeq = close > bbUpper ? 1 : 0 26 | probBbUpperUp = sum(probBbUpperUpSeq, bayesPeriod) / bayesPeriod 27 | probBbUpperDownSeq = close < bbUpper ? 1 : 0 28 | probBbUpperDown = sum(probBbUpperDownSeq, bayesPeriod) / bayesPeriod 29 | 30 | probUpBbUpper = probBbUpperUp / (probBbUpperUp + probBbUpperDown) 31 | 32 | probBbBasisUpSeq = close > bbBasis ? 1 : 0 33 | probBbBasisUp = sum(probBbBasisUpSeq, bayesPeriod) / bayesPeriod 34 | probBbBasisDownSeq = close < bbBasis ? 1 : 0 35 | probBbBasisDown = sum(probBbBasisDownSeq, bayesPeriod) / bayesPeriod 36 | 37 | probUpBbBasis = probBbBasisUp / (probBbBasisUp + probBbBasisDown) 38 | 39 | probSmaUpSeq = close > smaValues ? 1 : 0 40 | probSmaUp = sum(probSmaUpSeq, bayesPeriod) / bayesPeriod 41 | probSmaDownSeq = close < smaValues ? 1 : 0 42 | probSmaDown = sum(probSmaDownSeq, bayesPeriod) / bayesPeriod 43 | 44 | probUpSma = probSmaUp / (probSmaUp + probSmaDown) 45 | 46 | sigmaProbsDown = nz(probUpBbUpper * probUpBbBasis * probUpSma / probUpBbUpper * probUpBbBasis * probUpSma + ((1 - probUpBbUpper) * (1 - probUpBbBasis) * (1 - probUpSma))) 47 | 48 | // Next candles are breaking Up 49 | probDownBbUpper = probBbUpperDown / (probBbUpperDown + probBbUpperUp) 50 | probDownBbBasis = probBbBasisDown / (probBbBasisDown + probBbBasisUp) 51 | probDownSma = probSmaDown / (probSmaDown + probSmaUp) 52 | 53 | sigmaProbsUp = nz(probDownBbUpper * probDownBbBasis * probDownSma / probDownBbUpper * probDownBbBasis * probDownSma + ( (1 - probDownBbUpper) * (1 - probDownBbBasis) * (1 - probDownSma) )) 54 | 55 | showNextCandleDown = input(true, title="Plot Next Candles Breaking Down?") 56 | plot(showNextCandleDown ? sigmaProbsDown * 100 : na, title="Next Candle Breaking Down Probs", transp=0, color=color.red, linewidth=2) 57 | 58 | showNextCandleUp = input(true, title="Plot Next Candles Breaking Up?") 59 | plot(showNextCandleUp ? sigmaProbsUp * 100 : na, title="Next Candle Breaking Up Probs", transp=0, color=color.green, linewidth=2) 60 | 61 | probPrime = nz(sigmaProbsDown * sigmaProbsUp / sigmaProbsDown * sigmaProbsUp + ( (1 - sigmaProbsDown) * (1 - sigmaProbsUp) )) 62 | 63 | showPrime = input(true, title="Plot Prime Probability?") 64 | plot(showPrime ? probPrime * 100 : na, title="Prime Probability", transp=0, color=color.blue, linewidth=2) 65 | 66 | lowerThreshold = input(15.0, title="Lower Threshold") 67 | 68 | sideways = probPrime < lowerThreshold / 100 and sigmaProbsUp < lowerThreshold / 100 and sigmaProbsDown < lowerThreshold / 100 69 | 70 | longUsingProbPrime = probPrime > lowerThreshold / 100 and probPrime[1] == 0 71 | longUsingSigmaProbsUp = sigmaProbsUp < 1 and sigmaProbsUp[1] == 1 72 | 73 | shortUsingProbPrime = probPrime == 0 and probPrime[1] > lowerThreshold / 100 74 | shortUsingSigmaProbsDown = sigmaProbsDown < 1 and sigmaProbsDown[1] == 1 75 | 76 | longSignal = longUsingProbPrime or longUsingSigmaProbsUp 77 | shortSignal = shortUsingProbPrime or shortUsingSigmaProbsDown 78 | 79 | barcolor(longSignal ? color.lime : na, title="Long Bars") 80 | barcolor(shortSignal ? color.maroon : na, title="Short Bars") 81 | 82 | hzl3 = hline(lowerThreshold, color=#333333, linestyle=hline.style_solid) 83 | hzl4 = hline(0, color=#333333, linestyle=hline.style_solid) 84 | fill(hzl3, hzl4, title="Lower Threshold", color=sideways ? color.gray : color.maroon, transp=70) 85 | 86 | alertcondition(longSignal, title="Long!", message="Bayesian BBSMA - LONG - {{exchange}}:{{ticker}} at {{close}}") 87 | alertcondition(shortSignal, title="Short!", message="Bayesian BBSMA - SHORT - {{exchange}}:{{ticker}} at {{close}}") 88 | -------------------------------------------------------------------------------- /bayesian/strategies/bbsmastrat.pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © tista 3 | 4 | //@version=4 5 | strategy("Bayesian BBSMA Oscillator Strategy", shorttitle="BayesBBSMAOscStrategy", default_qty_type=strategy.percent_of_equity, default_qty_value=100, currency="USD") 6 | 7 | bbSmaPeriod = input(20, title="BB SMA Period") 8 | bbStdDevMult = input(2.5, title="BB Standard Deviation", maxval=50.0) 9 | 10 | bbBasis = sma(close, bbSmaPeriod) 11 | bbStdDev = bbStdDevMult * stdev(close, bbSmaPeriod) 12 | 13 | bbUpper = bbBasis + bbStdDev 14 | bbLower = bbBasis - bbStdDev 15 | 16 | // SMA 17 | smaPeriod = input(20, title="SMA Period") 18 | smaValues = sma(close, smaPeriod) 19 | 20 | 21 | // Bayesian Theorem Starts 22 | bayesPeriod = input(20, title="Bayesian Lookback Period") 23 | 24 | // Next candles are breaking Down 25 | probBbUpperUpSeq = close > bbUpper ? 1 : 0 26 | probBbUpperUp = sum(probBbUpperUpSeq, bayesPeriod) / bayesPeriod 27 | probBbUpperDownSeq = close < bbUpper ? 1 : 0 28 | probBbUpperDown = sum(probBbUpperDownSeq, bayesPeriod) / bayesPeriod 29 | 30 | probUpBbUpper = probBbUpperUp / (probBbUpperUp + probBbUpperDown) 31 | 32 | probBbBasisUpSeq = close > bbBasis ? 1 : 0 33 | probBbBasisUp = sum(probBbBasisUpSeq, bayesPeriod) / bayesPeriod 34 | probBbBasisDownSeq = close < bbBasis ? 1 : 0 35 | probBbBasisDown = sum(probBbBasisDownSeq, bayesPeriod) / bayesPeriod 36 | 37 | probUpBbBasis = probBbBasisUp / (probBbBasisUp + probBbBasisDown) 38 | 39 | probSmaUpSeq = close > smaValues ? 1 : 0 40 | probSmaUp = sum(probSmaUpSeq, bayesPeriod) / bayesPeriod 41 | probSmaDownSeq = close < smaValues ? 1 : 0 42 | probSmaDown = sum(probSmaDownSeq, bayesPeriod) / bayesPeriod 43 | 44 | probUpSma = probSmaUp / (probSmaUp + probSmaDown) 45 | 46 | sigmaProbsDown = nz(probUpBbUpper * probUpBbBasis * probUpSma / probUpBbUpper * probUpBbBasis * probUpSma + ((1 - probUpBbUpper) * (1 - probUpBbBasis) * (1 - probUpSma))) * 100 47 | 48 | // Next candles are breaking Up 49 | probDownBbUpper = probBbUpperDown / (probBbUpperDown + probBbUpperUp) 50 | probDownBbBasis = probBbBasisDown / (probBbBasisDown + probBbBasisUp) 51 | probDownSma = probSmaDown / (probSmaDown + probSmaUp) 52 | 53 | sigmaProbsUp = nz(probDownBbUpper * probDownBbBasis * probDownSma / probDownBbUpper * probDownBbBasis * probDownSma + ( (1 - probDownBbUpper) * (1 - probDownBbBasis) * (1 - probDownSma) )) * 100 54 | 55 | showNextCandleDown = input(true, title="Plot Next Candles Breaking Down?") 56 | plot(showNextCandleDown ? sigmaProbsDown : na, title="Next Candle Breaking Down Probs", transp=0, color=color.red) 57 | 58 | showNextCandleUp = input(true, title="Plot Next Candles Breaking Up?") 59 | plot(showNextCandleUp ? sigmaProbsUp : na, title="Next Candle Breaking Up Probs", transp=0, color=color.green) 60 | 61 | longSignal = sigmaProbsUp < 100 and sigmaProbsUp[1] == 100 62 | shortSignal = sigmaProbsDown < 100 and sigmaProbsDown[1] == 100 63 | 64 | longTrailPerc = input(title="Trail Long Loss (%)", type=input.float, minval=0.0, step=0.1, defval=4) * 0.01 65 | longStopPrice = 0.0 66 | 67 | longStopPrice := if (strategy.position_size > 0) 68 | stopValue = close * (1 - longTrailPerc) 69 | max(stopValue, longStopPrice[1]) 70 | else 71 | 0 72 | 73 | shortTrailPerc = input(title="Trail Short Loss (%)", type=input.float, minval=0.0, step=0.1, defval=4) * 0.01 74 | shortStopPrice = 0.0 75 | 76 | shortStopPrice := if (strategy.position_size < 0) 77 | stopValue = close * (1 + shortTrailPerc) 78 | min(stopValue, shortStopPrice[1]) 79 | else 80 | 999999999 81 | 82 | startingYear = input(2019, title="Year started") 83 | 84 | doLongs = input(true, title="Calculate longs?") 85 | strategy.entry("Long", strategy.long, when=strategy.position_size == 0 and longSignal and year >= startingYear and doLongs) 86 | if (strategy.position_size > 0) 87 | strategy.exit(id="Long Trail Stop", stop=longStopPrice) 88 | 89 | doShorts = input(true, title="Calculate shorts?") 90 | strategy.entry("Short", strategy.short, when=strategy.position_size == 0 and shortSignal and year >= startingYear and doShorts) 91 | if (strategy.position_size < 0) 92 | strategy.exit(id="Short Trail Stop", stop=shortStopPrice) 93 | -------------------------------------------------------------------------------- /divergences/ao.pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © tista 3 | 4 | //@version=4 5 | study("Awesome Oscillator Divergences", shorttitle="AO Divergences") 6 | 7 | ao_fast = input(5, "AO Fast EMA Lenth") 8 | ao_slow = input(34, "AO Slow EMA Length") 9 | lbR = input(title="Pivot Lookback Right", defval=5) 10 | lbL = input(title="Pivot Lookback Left", defval=5) 11 | rangeUpper = input(title="Max of Lookback Range", defval=60) 12 | rangeLower = input(title="Min of Lookback Range", defval=5) 13 | plotBull = input(title="Plot Bullish", defval=true) 14 | plotHiddenBull = input(title="Plot Hidden Bullish", defval=false) 15 | plotBear = input(title="Plot Bearish", defval=true) 16 | plotHiddenBear = input(title="Plot Hidden Bearish", defval=false) 17 | 18 | bearColor = color.red 19 | bullColor = color.green 20 | hiddenBullColor = color.green 21 | hiddenBearColor = color.red 22 | textColor = color.white 23 | noneColor = color.new(color.white, 100) 24 | 25 | osc = ema(hl2, ao_fast) - ema(hl2, ao_slow) 26 | color_ao = change(osc) > 0 ? #115500 : #992211 27 | 28 | plot(osc, title="OBV", style=plot.style_line, color=color_ao, transp=0, linewidth=2) 29 | 30 | plFound = na(pivotlow(osc, lbL, lbR)) ? false : true 31 | phFound = na(pivothigh(osc, lbL, lbR)) ? false : true 32 | 33 | _inRange(cond) => 34 | bars = barssince(cond == true) 35 | rangeLower <= bars and bars <= rangeUpper 36 | 37 | //------------------------------------------------------------------------------ 38 | // Regular Bullish 39 | 40 | // Osc: Higher Low 41 | oscHL = osc[lbR] > valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1]) 42 | 43 | // Price: Lower Low 44 | priceLL = low[lbR] < valuewhen(plFound, low[lbR], 1) 45 | 46 | bullCond = plotBull and priceLL and oscHL and plFound 47 | 48 | plot( 49 | plFound ? osc[lbR] : na, 50 | offset=-lbR, 51 | title="Regular Bullish", 52 | linewidth=2, 53 | color=(bullCond ? bullColor : noneColor), 54 | transp=0 55 | ) 56 | 57 | plotshape( 58 | bullCond ? osc[lbR] : na, 59 | offset=-lbR, 60 | title="Regular Bullish Label", 61 | text=" Bull ", 62 | style=shape.labelup, 63 | location=location.absolute, 64 | color=bullColor, 65 | textcolor=textColor, 66 | transp=0 67 | ) 68 | 69 | alertcondition(bullCond, title="Regular bullish divergence in AO found", message="Check charts for a regular bullish divergence found with AO") 70 | 71 | //------------------------------------------------------------------------------ 72 | // Hidden Bullish 73 | 74 | // Osc: Lower Low 75 | oscLL = osc[lbR] < valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1]) 76 | 77 | // Price: Higher Low 78 | priceHL = low[lbR] > valuewhen(plFound, low[lbR], 1) 79 | 80 | hiddenBullCond = plotHiddenBull and priceHL and oscLL and plFound 81 | 82 | plot( 83 | plFound ? osc[lbR] : na, 84 | offset=-lbR, 85 | title="Hidden Bullish", 86 | linewidth=2, 87 | color=(hiddenBullCond ? hiddenBullColor : noneColor), 88 | transp=0 89 | ) 90 | 91 | plotshape( 92 | hiddenBullCond ? osc[lbR] : na, 93 | offset=-lbR, 94 | title="Hidden Bullish Label", 95 | text=" H Bull ", 96 | style=shape.labelup, 97 | location=location.absolute, 98 | color=bullColor, 99 | textcolor=textColor, 100 | transp=0 101 | ) 102 | 103 | alertcondition(hiddenBullCond, title="Hidden bullish divergence in AO found", message="Check charts for a hidden bullish divergence found with AO") 104 | 105 | //------------------------------------------------------------------------------ 106 | // Regular Bearish 107 | 108 | // Osc: Lower High 109 | oscLH = osc[lbR] < valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1]) 110 | 111 | // Price: Higher High 112 | priceHH = high[lbR] > valuewhen(phFound, high[lbR], 1) 113 | 114 | bearCond = plotBear and priceHH and oscLH and phFound 115 | 116 | plot( 117 | phFound ? osc[lbR] : na, 118 | offset=-lbR, 119 | title="Regular Bearish", 120 | linewidth=2, 121 | color=(bearCond ? bearColor : noneColor), 122 | transp=0 123 | ) 124 | 125 | plotshape( 126 | bearCond ? osc[lbR] : na, 127 | offset=-lbR, 128 | title="Regular Bearish Label", 129 | text=" Bear ", 130 | style=shape.labeldown, 131 | location=location.absolute, 132 | color=bearColor, 133 | textcolor=textColor, 134 | transp=0 135 | ) 136 | 137 | alertcondition(bearCond, title="Regular bearish divergence in AO found", message="Check charts for a regular bearish divergence found with AO") 138 | 139 | //------------------------------------------------------------------------------ 140 | // Hidden Bearish 141 | 142 | // Osc: Higher High 143 | oscHH = osc[lbR] > valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1]) 144 | 145 | // Price: Lower High 146 | priceLH = high[lbR] < valuewhen(phFound, high[lbR], 1) 147 | 148 | hiddenBearCond = plotHiddenBear and priceLH and oscHH and phFound 149 | 150 | plot( 151 | phFound ? osc[lbR] : na, 152 | offset=-lbR, 153 | title="Hidden Bearish", 154 | linewidth=2, 155 | color=(hiddenBearCond ? hiddenBearColor : noneColor), 156 | transp=0 157 | ) 158 | 159 | plotshape( 160 | hiddenBearCond ? osc[lbR] : na, 161 | offset=-lbR, 162 | title="Hidden Bearish Label", 163 | text=" H Bear ", 164 | style=shape.labeldown, 165 | location=location.absolute, 166 | color=bearColor, 167 | textcolor=textColor, 168 | transp=0 169 | ) 170 | 171 | alertcondition(hiddenBearCond, title="Hidden bearish divergence in AO found", message="Check charts for a hidden bearish divergence found with AO") 172 | -------------------------------------------------------------------------------- /divergences/cci-high-low.pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © tista 3 | 4 | //@version=4 5 | study(title="CCI Low/High Divergences", format=format.price) 6 | 7 | len = input(title="CCI Period", minval=1, defval=14) 8 | lbR = input(title="Pivot Lookback Right", defval=5) 9 | lbL = input(title="Pivot Lookback Left", defval=5) 10 | rangeUpper = input(title="Max of Lookback Range", defval=60) 11 | rangeLower = input(title="Min of Lookback Range", defval=5) 12 | plotBull = input(title="Plot Bullish", defval=true) 13 | plotHiddenBull = input(title="Plot Hidden Bullish", defval=false) 14 | plotBear = input(title="Plot Bearish", defval=true) 15 | plotHiddenBear = input(title="Plot Hidden Bearish", defval=false) 16 | 17 | bearColor = color.red 18 | bullColor = color.green 19 | hiddenBullColor = color.green 20 | hiddenBearColor = color.red 21 | textColor = color.white 22 | noneColor = color.new(color.white, 100) 23 | 24 | oscBull = cci(low, len) 25 | oscBear = cci(close, len) 26 | 27 | plot(oscBull, title="Lows", linewidth=1, color=color.green, transp=0) 28 | plot(oscBear, title="Highs", linewidth=1, color=color.red, transp=0) 29 | obLevel = hline(100, title="Overbought", linestyle=hline.style_dotted) 30 | osLevel = hline(-100, title="Oversold", linestyle=hline.style_dotted) 31 | fill(obLevel, osLevel, title="Background", color=color.gray, transp=80) 32 | 33 | plFound = na(pivotlow(oscBull, lbL, lbR)) ? false : true 34 | phFound = na(pivothigh(oscBear, lbL, lbR)) ? false : true 35 | 36 | _inRange(cond) => 37 | bars = barssince(cond == true) 38 | rangeLower <= bars and bars <= rangeUpper 39 | 40 | //------------------------------------------------------------------------------ 41 | // Regular Bullish 42 | 43 | // Osc: Higher Low 44 | oscHL = oscBull[lbR] > valuewhen(plFound, oscBull[lbR], 1) and _inRange(plFound[1]) 45 | 46 | // Price: Lower Low 47 | priceLL = low[lbR] < valuewhen(plFound, low[lbR], 1) 48 | 49 | bullCond = plotBull and priceLL and oscHL and plFound 50 | 51 | plot( 52 | plFound ? oscBull[lbR] : na, 53 | offset=-lbR, 54 | title="Regular Bullish", 55 | linewidth=2, 56 | color=(bullCond ? bullColor : noneColor), 57 | transp=0 58 | ) 59 | 60 | plotshape( 61 | bullCond ? oscBull[lbR] : na, 62 | offset=-lbR, 63 | title="Regular Bullish Label", 64 | text=" Bull ", 65 | style=shape.labelup, 66 | location=location.absolute, 67 | color=bullColor, 68 | textcolor=textColor, 69 | transp=0 70 | ) 71 | 72 | alertcondition(bullCond, title="Regular bullish divergence in CCI found", message="Check charts for a regular bullish divergence found with CCI") 73 | 74 | //------------------------------------------------------------------------------ 75 | // Hidden Bullish 76 | 77 | // Osc: Lower Low 78 | oscLL = oscBull[lbR] < valuewhen(plFound, oscBull[lbR], 1) and _inRange(plFound[1]) 79 | 80 | // Price: Higher Low 81 | priceHL = low[lbR] > valuewhen(plFound, low[lbR], 1) 82 | 83 | hiddenBullCond = plotHiddenBull and priceHL and oscLL and plFound 84 | 85 | plot( 86 | plFound ? oscBull[lbR] : na, 87 | offset=-lbR, 88 | title="Hidden Bullish", 89 | linewidth=2, 90 | color=(hiddenBullCond ? hiddenBullColor : noneColor), 91 | transp=0 92 | ) 93 | 94 | plotshape( 95 | hiddenBullCond ? oscBull[lbR] : na, 96 | offset=-lbR, 97 | title="Hidden Bullish Label", 98 | text=" H Bull ", 99 | style=shape.labelup, 100 | location=location.absolute, 101 | color=bullColor, 102 | textcolor=textColor, 103 | transp=0 104 | ) 105 | 106 | alertcondition(hiddenBullCond, title="Hidden bullish divergence in CCI found", message="Check charts for a hidden bullish divergence found with CCI") 107 | 108 | //------------------------------------------------------------------------------ 109 | // Regular Bearish 110 | 111 | // Osc: Lower High 112 | oscLH = oscBear[lbR] < valuewhen(phFound, oscBear[lbR], 1) and _inRange(phFound[1]) 113 | 114 | // Price: Higher High 115 | priceHH = high[lbR] > valuewhen(phFound, high[lbR], 1) 116 | 117 | bearCond = plotBear and priceHH and oscLH and phFound 118 | 119 | plot( 120 | phFound ? oscBear[lbR] : na, 121 | offset=-lbR, 122 | title="Regular Bearish", 123 | linewidth=2, 124 | color=(bearCond ? bearColor : noneColor), 125 | transp=0 126 | ) 127 | 128 | plotshape( 129 | bearCond ? oscBear[lbR] : na, 130 | offset=-lbR, 131 | title="Regular Bearish Label", 132 | text=" Bear ", 133 | style=shape.labeldown, 134 | location=location.absolute, 135 | color=bearColor, 136 | textcolor=textColor, 137 | transp=0 138 | ) 139 | 140 | alertcondition(bearCond, title="Regular bearish divergence in CCI found", message="Check charts for a regular bearish divergence found with CCI") 141 | 142 | //------------------------------------------------------------------------------ 143 | // Hidden Bearish 144 | 145 | // Osc: Higher High 146 | oscHH = oscBear[lbR] > valuewhen(phFound, oscBear[lbR], 1) and _inRange(phFound[1]) 147 | 148 | // Price: Lower High 149 | priceLH = high[lbR] < valuewhen(phFound, high[lbR], 1) 150 | 151 | hiddenBearCond = plotHiddenBear and priceLH and oscHH and phFound 152 | 153 | plot( 154 | phFound ? oscBear[lbR] : na, 155 | offset=-lbR, 156 | title="Hidden Bearish", 157 | linewidth=2, 158 | color=(hiddenBearCond ? hiddenBearColor : noneColor), 159 | transp=0 160 | ) 161 | 162 | plotshape( 163 | hiddenBearCond ? oscBear[lbR] : na, 164 | offset=-lbR, 165 | title="Hidden Bearish Label", 166 | text=" H Bear ", 167 | style=shape.labeldown, 168 | location=location.absolute, 169 | color=bearColor, 170 | textcolor=textColor, 171 | transp=0 172 | ) 173 | 174 | alertcondition(hiddenBearCond, title="Hidden bearish divergence in CCI found", message="Check charts for a hidden bearish divergence found with CCI") 175 | -------------------------------------------------------------------------------- /divergences/cci.pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © tista 3 | 4 | //@version=4 5 | study(title="CCI Divergences", format=format.price) 6 | 7 | len = input(title="CCI Period", minval=1, defval=14) 8 | src = input(title="CCI Source", defval=close) 9 | lbR = input(title="Pivot Lookback Right", defval=5) 10 | lbL = input(title="Pivot Lookback Left", defval=5) 11 | rangeUpper = input(title="Max of Lookback Range", defval=60) 12 | rangeLower = input(title="Min of Lookback Range", defval=5) 13 | plotBull = input(title="Plot Bullish", defval=true) 14 | plotHiddenBull = input(title="Plot Hidden Bullish", defval=false) 15 | plotBear = input(title="Plot Bearish", defval=true) 16 | plotHiddenBear = input(title="Plot Hidden Bearish", defval=false) 17 | 18 | bearColor = color.red 19 | bullColor = color.green 20 | hiddenBullColor = color.green 21 | hiddenBearColor = color.red 22 | textColor = color.white 23 | noneColor = color.new(color.white, 100) 24 | 25 | osc = cci(src, len) 26 | 27 | plot(osc, title="CCI", linewidth=2, color=color.yellow) 28 | obLevel = hline(100, title="Overbought", linestyle=hline.style_dotted) 29 | osLevel = hline(-100, title="Oversold", linestyle=hline.style_dotted) 30 | fill(obLevel, osLevel, title="Background", color=color.gray, transp=80) 31 | 32 | plFound = na(pivotlow(osc, lbL, lbR)) ? false : true 33 | phFound = na(pivothigh(osc, lbL, lbR)) ? false : true 34 | 35 | _inRange(cond) => 36 | bars = barssince(cond == true) 37 | rangeLower <= bars and bars <= rangeUpper 38 | 39 | alertcondition(osc[1] > 100.0 and osc[2] < 100.0, title="CCI value crosses over 100.0", message="Check charts for a CCI cross over 100.0") 40 | alertcondition(osc[1] < 100.0 and osc[2] > 100.0, title="CCI value crosses under 100.0", message="Check charts for a CCI cross under 100.0") 41 | alertcondition(osc[1] > -100. and osc[2] < -100.0, title="CCI value crosses over -100.0", message="Check charts for a CCI cross over -100.0") 42 | alertcondition(osc[1] < -100.0 and osc[2] > -100.0, title="CCI value crosses under -100.0", message="Check charts for a CCI cross under -100.0") 43 | 44 | //------------------------------------------------------------------------------ 45 | // Regular Bullish 46 | 47 | // Osc: Higher Low 48 | oscHL = osc[lbR] > valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1]) 49 | 50 | // Price: Lower Low 51 | priceLL = low[lbR] < valuewhen(plFound, low[lbR], 1) 52 | 53 | bullCond = plotBull and priceLL and oscHL and plFound 54 | 55 | plot( 56 | plFound ? osc[lbR] : na, 57 | offset=-lbR, 58 | title="Regular Bullish", 59 | linewidth=2, 60 | color=(bullCond ? bullColor : noneColor), 61 | transp=0 62 | ) 63 | 64 | plotshape( 65 | bullCond ? osc[lbR] : na, 66 | offset=-lbR, 67 | title="Regular Bullish Label", 68 | text=" Bull ", 69 | style=shape.labelup, 70 | location=location.absolute, 71 | color=bullColor, 72 | textcolor=textColor, 73 | transp=0 74 | ) 75 | 76 | alertcondition(bullCond, title="Regular bullish divergence in CCI found", message="Check charts for a regular bullish divergence found with CCI") 77 | 78 | //------------------------------------------------------------------------------ 79 | // Hidden Bullish 80 | 81 | // Osc: Lower Low 82 | oscLL = osc[lbR] < valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1]) 83 | 84 | // Price: Higher Low 85 | priceHL = low[lbR] > valuewhen(plFound, low[lbR], 1) 86 | 87 | hiddenBullCond = plotHiddenBull and priceHL and oscLL and plFound 88 | 89 | plot( 90 | plFound ? osc[lbR] : na, 91 | offset=-lbR, 92 | title="Hidden Bullish", 93 | linewidth=2, 94 | color=(hiddenBullCond ? hiddenBullColor : noneColor), 95 | transp=0 96 | ) 97 | 98 | plotshape( 99 | hiddenBullCond ? osc[lbR] : na, 100 | offset=-lbR, 101 | title="Hidden Bullish Label", 102 | text=" H Bull ", 103 | style=shape.labelup, 104 | location=location.absolute, 105 | color=bullColor, 106 | textcolor=textColor, 107 | transp=0 108 | ) 109 | 110 | alertcondition(hiddenBullCond, title="Hidden bullish divergence in CCI found", message="Check charts for a hidden bullish divergence found with CCI") 111 | 112 | //------------------------------------------------------------------------------ 113 | // Regular Bearish 114 | 115 | // Osc: Lower High 116 | oscLH = osc[lbR] < valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1]) 117 | 118 | // Price: Higher High 119 | priceHH = high[lbR] > valuewhen(phFound, high[lbR], 1) 120 | 121 | bearCond = plotBear and priceHH and oscLH and phFound 122 | 123 | plot( 124 | phFound ? osc[lbR] : na, 125 | offset=-lbR, 126 | title="Regular Bearish", 127 | linewidth=2, 128 | color=(bearCond ? bearColor : noneColor), 129 | transp=0 130 | ) 131 | 132 | plotshape( 133 | bearCond ? osc[lbR] : na, 134 | offset=-lbR, 135 | title="Regular Bearish Label", 136 | text=" Bear ", 137 | style=shape.labeldown, 138 | location=location.absolute, 139 | color=bearColor, 140 | textcolor=textColor, 141 | transp=0 142 | ) 143 | 144 | alertcondition(bearCond, title="Regular bearish divergence in CCI found", message="Check charts for a regular bearish divergence found with CCI") 145 | 146 | //------------------------------------------------------------------------------ 147 | // Hidden Bearish 148 | 149 | // Osc: Higher High 150 | oscHH = osc[lbR] > valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1]) 151 | 152 | // Price: Lower High 153 | priceLH = high[lbR] < valuewhen(phFound, high[lbR], 1) 154 | 155 | hiddenBearCond = plotHiddenBear and priceLH and oscHH and phFound 156 | 157 | plot( 158 | phFound ? osc[lbR] : na, 159 | offset=-lbR, 160 | title="Hidden Bearish", 161 | linewidth=2, 162 | color=(hiddenBearCond ? hiddenBearColor : noneColor), 163 | transp=0 164 | ) 165 | 166 | plotshape( 167 | hiddenBearCond ? osc[lbR] : na, 168 | offset=-lbR, 169 | title="Hidden Bearish Label", 170 | text=" H Bear ", 171 | style=shape.labeldown, 172 | location=location.absolute, 173 | color=bearColor, 174 | textcolor=textColor, 175 | transp=0 176 | ) 177 | 178 | alertcondition(hiddenBearCond, title="Hidden bearish divergence in CCI found", message="Check charts for a hidden bearish divergence found with CCI") 179 | -------------------------------------------------------------------------------- /divergences/mfi.pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © tista 3 | 4 | //@version=4 5 | study(title="MFI Divergences", format=format.price) 6 | 7 | len = input(title="Money Flow Period", minval=1, defval=14) 8 | src = input(title="Money Flow Source", defval=close) 9 | lbR = input(title="Pivot Lookback Right", defval=5) 10 | lbL = input(title="Pivot Lookback Left", defval=5) 11 | rangeUpper = input(title="Max of Lookback Range", defval=60) 12 | rangeLower = input(title="Min of Lookback Range", defval=5) 13 | plotBull = input(title="Plot Bullish", defval=true) 14 | plotHiddenBull = input(title="Plot Hidden Bullish", defval=false) 15 | plotBear = input(title="Plot Bearish", defval=true) 16 | plotHiddenBear = input(title="Plot Hidden Bearish", defval=false) 17 | 18 | bearColor = color.red 19 | bullColor = color.green 20 | hiddenBullColor = color.green 21 | hiddenBearColor = color.red 22 | textColor = color.white 23 | noneColor = color.new(color.white, 100) 24 | 25 | rawMoneyFlow = hlc3 * volume 26 | positiveMoneyFlow() => 27 | a = 0.0 28 | a := hlc3 > hlc3[1] ? a + rawMoneyFlow : a 29 | negativeMoneyFlow() => 30 | b = 0.0 31 | b := hlc3 < hlc3[1] ? b + rawMoneyFlow : b 32 | 33 | moneyflow(period) => 34 | moneyFlowRatio = sma(positiveMoneyFlow(), period) / sma(negativeMoneyFlow(), period) 35 | moneyFlowIndex = security(syminfo.tickerid, timeframe.period, 100 - 100 / (1 + moneyFlowRatio)) 36 | 37 | osc = moneyflow(len) 38 | 39 | plot(osc, title="Money Flow", linewidth=2, color=color.yellow) 40 | obLevel = hline(80, title="Overbought", linestyle=hline.style_dotted) 41 | osLevel = hline(20, title="Oversold", linestyle=hline.style_dotted) 42 | fill(obLevel, osLevel, title="Background", color=color.gray, transp=80) 43 | 44 | plFound = na(pivotlow(osc, lbL, lbR)) ? false : true 45 | phFound = na(pivothigh(osc, lbL, lbR)) ? false : true 46 | 47 | _inRange(cond) => 48 | bars = barssince(cond == true) 49 | rangeLower <= bars and bars <= rangeUpper 50 | 51 | //------------------------------------------------------------------------------ 52 | // Regular Bullish 53 | 54 | // Osc: Higher Low 55 | oscHL = osc[lbR] > valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1]) 56 | 57 | // Price: Lower Low 58 | priceLL = low[lbR] < valuewhen(plFound, low[lbR], 1) 59 | 60 | bullCond = plotBull and priceLL and oscHL and plFound 61 | 62 | plot( 63 | plFound ? osc[lbR] : na, 64 | offset=-lbR, 65 | title="Regular Bullish", 66 | linewidth=2, 67 | color=(bullCond ? bullColor : noneColor), 68 | transp=0 69 | ) 70 | 71 | plotshape( 72 | bullCond ? osc[lbR] : na, 73 | offset=-lbR, 74 | title="Regular Bullish Label", 75 | text=" Bull ", 76 | style=shape.labelup, 77 | location=location.absolute, 78 | color=bullColor, 79 | textcolor=textColor, 80 | transp=0 81 | ) 82 | 83 | alertcondition(bullCond, title="Regular bullish divergence in MFI found", message="Check charts for a regular bullish divergence found with MFI") 84 | 85 | //------------------------------------------------------------------------------ 86 | // Hidden Bullish 87 | 88 | // Osc: Lower Low 89 | oscLL = osc[lbR] < valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1]) 90 | 91 | // Price: Higher Low 92 | priceHL = low[lbR] > valuewhen(plFound, low[lbR], 1) 93 | 94 | hiddenBullCond = plotHiddenBull and priceHL and oscLL and plFound 95 | 96 | plot( 97 | plFound ? osc[lbR] : na, 98 | offset=-lbR, 99 | title="Hidden Bullish", 100 | linewidth=2, 101 | color=(hiddenBullCond ? hiddenBullColor : noneColor), 102 | transp=0 103 | ) 104 | 105 | plotshape( 106 | hiddenBullCond ? osc[lbR] : na, 107 | offset=-lbR, 108 | title="Hidden Bullish Label", 109 | text=" H Bull ", 110 | style=shape.labelup, 111 | location=location.absolute, 112 | color=bullColor, 113 | textcolor=textColor, 114 | transp=0 115 | ) 116 | 117 | alertcondition(hiddenBullCond, title="Hidden bullish divergence in MFI found", message="Check charts for a hidden bullish divergence found with MFI") 118 | 119 | //------------------------------------------------------------------------------ 120 | // Regular Bearish 121 | 122 | // Osc: Lower High 123 | oscLH = osc[lbR] < valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1]) 124 | 125 | // Price: Higher High 126 | priceHH = high[lbR] > valuewhen(phFound, high[lbR], 1) 127 | 128 | bearCond = plotBear and priceHH and oscLH and phFound 129 | 130 | plot( 131 | phFound ? osc[lbR] : na, 132 | offset=-lbR, 133 | title="Regular Bearish", 134 | linewidth=2, 135 | color=(bearCond ? bearColor : noneColor), 136 | transp=0 137 | ) 138 | 139 | plotshape( 140 | bearCond ? osc[lbR] : na, 141 | offset=-lbR, 142 | title="Regular Bearish Label", 143 | text=" Bear ", 144 | style=shape.labeldown, 145 | location=location.absolute, 146 | color=bearColor, 147 | textcolor=textColor, 148 | transp=0 149 | ) 150 | 151 | alertcondition(bearCond, title="Regular bearish divergence in MFI found", message="Check charts for a regular bearish divergence found with MFI") 152 | 153 | //------------------------------------------------------------------------------ 154 | // Hidden Bearish 155 | 156 | // Osc: Higher High 157 | oscHH = osc[lbR] > valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1]) 158 | 159 | // Price: Lower High 160 | priceLH = high[lbR] < valuewhen(phFound, high[lbR], 1) 161 | 162 | hiddenBearCond = plotHiddenBear and priceLH and oscHH and phFound 163 | 164 | plot( 165 | phFound ? osc[lbR] : na, 166 | offset=-lbR, 167 | title="Hidden Bearish", 168 | linewidth=2, 169 | color=(hiddenBearCond ? hiddenBearColor : noneColor), 170 | transp=0 171 | ) 172 | 173 | plotshape( 174 | hiddenBearCond ? osc[lbR] : na, 175 | offset=-lbR, 176 | title="Hidden Bearish Label", 177 | text=" H Bear ", 178 | style=shape.labeldown, 179 | location=location.absolute, 180 | color=bearColor, 181 | textcolor=textColor, 182 | transp=0 183 | ) 184 | 185 | alertcondition(hiddenBearCond, title="Hidden bearish divergence in MFI found", message="Check charts for a hidden bearish divergence found with MFI") 186 | -------------------------------------------------------------------------------- /divergences/obv.pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © tista 3 | 4 | //@version=4 5 | study(title="OBV Divergences", format=format.price) 6 | 7 | lbR = input(title="Pivot Lookback Right", defval=5) 8 | lbL = input(title="Pivot Lookback Left", defval=5) 9 | rangeUpper = input(title="Max of Lookback Range", defval=60) 10 | rangeLower = input(title="Min of Lookback Range", defval=5) 11 | plotBull = input(title="Plot Bullish", defval=true) 12 | plotHiddenBull = input(title="Plot Hidden Bullish", defval=false) 13 | plotBear = input(title="Plot Bearish", defval=true) 14 | plotHiddenBear = input(title="Plot Hidden Bearish", defval=false) 15 | 16 | bearColor = color.red 17 | bullColor = color.green 18 | hiddenBullColor = color.green 19 | hiddenBearColor = color.red 20 | textColor = color.white 21 | noneColor = color.new(color.white, 100) 22 | 23 | new_volume = close > close[1] ? volume : close[1] > close ? -volume : 0 24 | osc = cum(new_volume) 25 | 26 | plot(osc, title="OBV", linewidth=2, color=color.yellow) 27 | 28 | plFound = na(pivotlow(osc, lbL, lbR)) ? false : true 29 | phFound = na(pivothigh(osc, lbL, lbR)) ? false : true 30 | 31 | _inRange(cond) => 32 | bars = barssince(cond == true) 33 | rangeLower <= bars and bars <= rangeUpper 34 | 35 | //------------------------------------------------------------------------------ 36 | // Regular Bullish 37 | 38 | // Osc: Higher Low 39 | oscHL = osc[lbR] > valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1]) 40 | 41 | // Price: Lower Low 42 | priceLL = low[lbR] < valuewhen(plFound, low[lbR], 1) 43 | 44 | bullCond = plotBull and priceLL and oscHL and plFound 45 | 46 | plot( 47 | plFound ? osc[lbR] : na, 48 | offset=-lbR, 49 | title="Regular Bullish", 50 | linewidth=2, 51 | color=(bullCond ? bullColor : noneColor), 52 | transp=0 53 | ) 54 | 55 | plotshape( 56 | bullCond ? osc[lbR] : na, 57 | offset=-lbR, 58 | title="Regular Bullish Label", 59 | text=" Bull ", 60 | style=shape.labelup, 61 | location=location.absolute, 62 | color=bullColor, 63 | textcolor=textColor, 64 | transp=0 65 | ) 66 | 67 | alertcondition(bullCond, title="Regular bullish divergence in OBV found", message="Check charts for a regular bullish divergence found with OBV") 68 | 69 | //------------------------------------------------------------------------------ 70 | // Hidden Bullish 71 | 72 | // Osc: Lower Low 73 | oscLL = osc[lbR] < valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1]) 74 | 75 | // Price: Higher Low 76 | priceHL = low[lbR] > valuewhen(plFound, low[lbR], 1) 77 | 78 | hiddenBullCond = plotHiddenBull and priceHL and oscLL and plFound 79 | 80 | plot( 81 | plFound ? osc[lbR] : na, 82 | offset=-lbR, 83 | title="Hidden Bullish", 84 | linewidth=2, 85 | color=(hiddenBullCond ? hiddenBullColor : noneColor), 86 | transp=0 87 | ) 88 | 89 | plotshape( 90 | hiddenBullCond ? osc[lbR] : na, 91 | offset=-lbR, 92 | title="Hidden Bullish Label", 93 | text=" H Bull ", 94 | style=shape.labelup, 95 | location=location.absolute, 96 | color=bullColor, 97 | textcolor=textColor, 98 | transp=0 99 | ) 100 | 101 | alertcondition(hiddenBullCond, title="Hidden bullish divergence in OBV found", message="Check charts for a hidden bullish divergence found with OBV") 102 | 103 | //------------------------------------------------------------------------------ 104 | // Regular Bearish 105 | 106 | // Osc: Lower High 107 | oscLH = osc[lbR] < valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1]) 108 | 109 | // Price: Higher High 110 | priceHH = high[lbR] > valuewhen(phFound, high[lbR], 1) 111 | 112 | bearCond = plotBear and priceHH and oscLH and phFound 113 | 114 | plot( 115 | phFound ? osc[lbR] : na, 116 | offset=-lbR, 117 | title="Regular Bearish", 118 | linewidth=2, 119 | color=(bearCond ? bearColor : noneColor), 120 | transp=0 121 | ) 122 | 123 | plotshape( 124 | bearCond ? osc[lbR] : na, 125 | offset=-lbR, 126 | title="Regular Bearish Label", 127 | text=" Bear ", 128 | style=shape.labeldown, 129 | location=location.absolute, 130 | color=bearColor, 131 | textcolor=textColor, 132 | transp=0 133 | ) 134 | 135 | alertcondition(bearCond, title="Regular bearish divergence in OBV found", message="Check charts for a regular bearish divergence found with OBV") 136 | 137 | //------------------------------------------------------------------------------ 138 | // Hidden Bearish 139 | 140 | // Osc: Higher High 141 | oscHH = osc[lbR] > valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1]) 142 | 143 | // Price: Lower High 144 | priceLH = high[lbR] < valuewhen(phFound, high[lbR], 1) 145 | 146 | hiddenBearCond = plotHiddenBear and priceLH and oscHH and phFound 147 | 148 | plot( 149 | phFound ? osc[lbR] : na, 150 | offset=-lbR, 151 | title="Hidden Bearish", 152 | linewidth=2, 153 | color=(hiddenBearCond ? hiddenBearColor : noneColor), 154 | transp=0 155 | ) 156 | 157 | plotshape( 158 | hiddenBearCond ? osc[lbR] : na, 159 | offset=-lbR, 160 | title="Hidden Bearish Label", 161 | text=" H Bear ", 162 | style=shape.labeldown, 163 | location=location.absolute, 164 | color=bearColor, 165 | textcolor=textColor, 166 | transp=0 167 | ) 168 | 169 | alertcondition(hiddenBearCond, title="Hidden bearish divergence in OBV found", message="Check charts for a hidden bearish divergence found with OBV") 170 | -------------------------------------------------------------------------------- /divergences/stochastic-rsi.pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © tista 3 | 4 | //@version=4 5 | study(title="Stochastic RSI Divergences", format=format.price) 6 | 7 | kPeriod = input(title="K Period", defval=3) 8 | dPeriod = input(title="D Period", defval=3) 9 | stochasticPeriod = input(title="Stochastic Period", defval=14) 10 | rsiPeriod = input(title="RSI Period", defval=14) 11 | lbR = input(title="Pivot Lookback Right", defval=5) 12 | lbL = input(title="Pivot Lookback Left", defval=5) 13 | rangeUpper = input(title="Max of Lookback Range", defval=60) 14 | rangeLower = input(title="Min of Lookback Range", defval=5) 15 | plotBull = input(title="Plot Bullish", defval=true) 16 | plotHiddenBull = input(title="Plot Hidden Bullish", defval=false) 17 | plotBear = input(title="Plot Bearish", defval=true) 18 | plotHiddenBear = input(title="Plot Hidden Bearish", defval=false) 19 | 20 | bearColor = color.red 21 | bullColor = color.green 22 | hiddenBullColor = color.green 23 | hiddenBearColor = color.red 24 | textColor = color.white 25 | noneColor = color.new(color.white, 100) 26 | 27 | rsi1 = rsi(close, rsiPeriod) 28 | k = sma(stoch(rsi1, rsi1, rsi1, stochasticPeriod), kPeriod) 29 | d = sma(k, dPeriod) 30 | osc = k 31 | 32 | plot(k, title="K", linewidth=2, color=color.yellow) 33 | plot(d, title="D", linewidth=2, color=color.white) 34 | 35 | plFound = na(pivotlow(osc, lbL, lbR)) ? false : true 36 | phFound = na(pivothigh(osc, lbL, lbR)) ? false : true 37 | 38 | _inRange(cond) => 39 | bars = barssince(cond == true) 40 | rangeLower <= bars and bars <= rangeUpper 41 | 42 | //------------------------------------------------------------------------------ 43 | // Regular Bullish 44 | 45 | // Osc: Higher Low 46 | oscHL = osc[lbR] > valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1]) 47 | 48 | // Price: Lower Low 49 | priceLL = low[lbR] < valuewhen(plFound, low[lbR], 1) 50 | 51 | bullCond = plotBull and priceLL and oscHL and plFound 52 | 53 | plot( 54 | plFound ? osc[lbR] : na, 55 | offset=-lbR, 56 | title="Regular Bullish", 57 | linewidth=2, 58 | color=(bullCond ? bullColor : noneColor), 59 | transp=0 60 | ) 61 | 62 | plotshape( 63 | bullCond ? osc[lbR] : na, 64 | offset=-lbR, 65 | title="Regular Bullish Label", 66 | text=" Bull ", 67 | style=shape.labelup, 68 | location=location.absolute, 69 | color=bullColor, 70 | textcolor=textColor, 71 | transp=0 72 | ) 73 | 74 | alertcondition(bullCond, title="Regular bullish divergence in OBV found", message="Check charts for a regular bullish divergence found with OBV") 75 | 76 | //------------------------------------------------------------------------------ 77 | // Hidden Bullish 78 | 79 | // Osc: Lower Low 80 | oscLL = osc[lbR] < valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1]) 81 | 82 | // Price: Higher Low 83 | priceHL = low[lbR] > valuewhen(plFound, low[lbR], 1) 84 | 85 | hiddenBullCond = plotHiddenBull and priceHL and oscLL and plFound 86 | 87 | plot( 88 | plFound ? osc[lbR] : na, 89 | offset=-lbR, 90 | title="Hidden Bullish", 91 | linewidth=2, 92 | color=(hiddenBullCond ? hiddenBullColor : noneColor), 93 | transp=0 94 | ) 95 | 96 | plotshape( 97 | hiddenBullCond ? osc[lbR] : na, 98 | offset=-lbR, 99 | title="Hidden Bullish Label", 100 | text=" H Bull ", 101 | style=shape.labelup, 102 | location=location.absolute, 103 | color=bullColor, 104 | textcolor=textColor, 105 | transp=0 106 | ) 107 | 108 | alertcondition(hiddenBullCond, title="Hidden bullish divergence in OBV found", message="Check charts for a hidden bullish divergence found with OBV") 109 | 110 | //------------------------------------------------------------------------------ 111 | // Regular Bearish 112 | 113 | // Osc: Lower High 114 | oscLH = osc[lbR] < valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1]) 115 | 116 | // Price: Higher High 117 | priceHH = high[lbR] > valuewhen(phFound, high[lbR], 1) 118 | 119 | bearCond = plotBear and priceHH and oscLH and phFound 120 | 121 | plot( 122 | phFound ? osc[lbR] : na, 123 | offset=-lbR, 124 | title="Regular Bearish", 125 | linewidth=2, 126 | color=(bearCond ? bearColor : noneColor), 127 | transp=0 128 | ) 129 | 130 | plotshape( 131 | bearCond ? osc[lbR] : na, 132 | offset=-lbR, 133 | title="Regular Bearish Label", 134 | text=" Bear ", 135 | style=shape.labeldown, 136 | location=location.absolute, 137 | color=bearColor, 138 | textcolor=textColor, 139 | transp=0 140 | ) 141 | 142 | alertcondition(bearCond, title="Regular bearish divergence in OBV found", message="Check charts for a regular bearish divergence found with OBV") 143 | 144 | //------------------------------------------------------------------------------ 145 | // Hidden Bearish 146 | 147 | // Osc: Higher High 148 | oscHH = osc[lbR] > valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1]) 149 | 150 | // Price: Lower High 151 | priceLH = high[lbR] < valuewhen(phFound, high[lbR], 1) 152 | 153 | hiddenBearCond = plotHiddenBear and priceLH and oscHH and phFound 154 | 155 | plot( 156 | phFound ? osc[lbR] : na, 157 | offset=-lbR, 158 | title="Hidden Bearish", 159 | linewidth=2, 160 | color=(hiddenBearCond ? hiddenBearColor : noneColor), 161 | transp=0 162 | ) 163 | 164 | plotshape( 165 | hiddenBearCond ? osc[lbR] : na, 166 | offset=-lbR, 167 | title="Hidden Bearish Label", 168 | text=" H Bear ", 169 | style=shape.labeldown, 170 | location=location.absolute, 171 | color=bearColor, 172 | textcolor=textColor, 173 | transp=0 174 | ) 175 | 176 | alertcondition(hiddenBearCond, title="Hidden bearish divergence in OBV found", message="Check charts for a hidden bearish divergence found with OBV") 177 | -------------------------------------------------------------------------------- /histograms/cm-williams-vix-fix-red-green.pine: -------------------------------------------------------------------------------- 1 | study("CM_Williams_Vix_Fix-redgreen", overlay=false) 2 | pd = input(22, title="LookBack Period Standard Deviation High") 3 | bbl = input(20, title="Bolinger Band Length") 4 | mult = input(2.0 , minval=1, maxval=5, title="Bollinger Band Standard Devaition Up") 5 | lb = input(50 , title="Look Back Period Percentile High") 6 | ph = input(.85, title="Highest Percentile - 0.90=90%, 0.95=95%, 0.99=99%") 7 | pl = input(1.01, title="Lowest Percentile - 1.10=90%, 1.05=95%, 1.01=99%") 8 | hp = input(false, title="Show High Range - Based on Percentile and LookBack Period?") 9 | sd = input(false, title="Show Standard Deviation Line?") 10 | 11 | wvf = ((highest(close, pd)-low)/(highest(close, pd)))*100 12 | 13 | sDev = mult * stdev(wvf, bbl) 14 | midLine = sma(wvf, bbl) 15 | lowerBand = midLine - sDev 16 | upperBand = midLine + sDev 17 | 18 | rangeHigh = (highest(wvf, lb)) * ph 19 | rangeLow = (lowest(wvf, lb)) * pl 20 | 21 | 22 | col = wvf <= lowerBand or wvf <= rangeLow ? red : wvf >= upperBand or wvf >= rangeHigh ? lime : gray 23 | 24 | 25 | plot(hp and rangeHigh ? rangeHigh : na, title="Range High Percentile", style=line, linewidth=4, color=orange) 26 | plot(hp and rangeLow ? rangeLow : na, title="Range High Percentile", style=line, linewidth=4, color=orange) 27 | plot(wvf, title="Williams Vix Fix", style=histogram, linewidth = 4, color=col) 28 | plot(sd and upperBand ? upperBand : na, title="Upper Band", style=line, linewidth = 3, color=aqua) -------------------------------------------------------------------------------- /oscillators/moneyflow.pine: -------------------------------------------------------------------------------- 1 | //@version=3 2 | 3 | study("Money Flow Index", overlay = false) 4 | 5 | //////////////////////////// 6 | // This study is based on the work of TV user Beasley Savage (https://www.tradingview.com/script/g58H59ub-Money-Flow-Index-Beasley-Savage/) 7 | // and all credit goes to them. 8 | // 9 | // Changes I've made: 10 | // 11 | // 1. Added a visual symbol of an overbought/oversold threshold cross in the form of a red/green circle, respectively. 12 | // Sometimes it can be hard to see when a cross actually occurs, and if your scaling isn't set up properly you can get 13 | // misleading visuals. This way removes all doubt. Bear in mind they aren't meant as trading signals, so DO NOT use them as such. 14 | // Research the MFI if you're unsure, but I use them as an early warning and that particular market/stock is added to my watchlist. 15 | // 16 | // 2. Added 60/40 lines as the MFI respects these incredibly well in trends. E.g. in a solid uptrend the MFI won't go below 40, 17 | // and vice versa. Use the idea of support and resistance levels on the indicator and it'll be a great help. 18 | // I've coloured the zones. Strong uptrends should stay above 60, strong downtrends should stay below 19 | // 40. The zone in between 40-60 I've called the transition zone. MFI often stays here in consolidation periods, and 20 | // in the last leg of a cycle/trend the MFI will often drop into this zone after being above 60 or below 40. This is a great 21 | // sign that you should get out and start looking to reverse your position. Hopefully it helps to spot divergences as well. 22 | // 23 | // 3. Added alerts based on an overbought/oversold cross. Also added an alert for when either condition is triggered, so hopefully 24 | // that's useful for those struggling with low alert limits. Feel free to change the overbought/oversold levels, the alerts + 25 | // crossover visual are set to adapt. 26 | // 27 | // Any queries please comment or PM me. 28 | // 29 | // Cheers, 30 | // RJR 31 | // 32 | //////////////////////////// 33 | // Version control 34 | // ======================== 35 | // 1.0 36 | // Initial Release 37 | // 1.1 38 | // Added support for multiple time frames 39 | // Cleaned up code 40 | // 1.1.1 41 | // Minor error fix 42 | //////////////////////////// 43 | 44 | //Inputs 45 | length = input(title="Length", defval=14) 46 | 47 | //MFI Calc 48 | rawMoneyFlow = hlc3 * volume 49 | 50 | positiveMoneyFlow() => 51 | a = 0.0 52 | a := hlc3 > hlc3[1] ? a + rawMoneyFlow : a 53 | negativeMoneyFlow() => 54 | b = 0.0 55 | b := hlc3 < hlc3[1] ? b + rawMoneyFlow : b 56 | 57 | moneyFlowRatio = sma(positiveMoneyFlow(), length) / sma(negativeMoneyFlow(), length) 58 | 59 | moneyFlowIndex = security(tickerid, period, 100 - 100 / (1 + moneyFlowRatio)) 60 | 61 | plot(moneyFlowIndex, color=yellow, linewidth=2) 62 | 63 | -------------------------------------------------------------------------------- /pivots/dailypivots.pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © tista 3 | 4 | //@version=4 5 | study("Daily Pivot Points", shorttitle="DailyPivots", overlay=true) 6 | 7 | ret() => [high[1], low[1], close[1]] 8 | [h, l, c] = security(syminfo.tickerid, "D", ret(), lookahead=true) 9 | 10 | pp = (h + l + c) / 3 11 | 12 | r4 = pp + (h - l) * 3 13 | r3 = pp + (h - l) * 2 14 | r2 = pp + (h - l) 15 | r1 = 2 * pp - l 16 | mpr0 = (pp + r1) / 2 17 | mpr1 = (r1 + r2) / 2 18 | mpr2 = (r2 + r3) / 2 19 | mpr3 = (r3 + r4) / 2 20 | 21 | s1 = 2 * pp - h 22 | s2 = pp - (h - l) 23 | s3 = pp - (h - l) * 2 24 | s4 = pp - (h - l) * 3 25 | mps0 = (pp + s1) / 2 26 | mps1 = (s1 + s2) / 2 27 | mps2 = (s2 + s3) / 2 28 | mps3 = (s3 + s4) / 2 29 | 30 | var line ppline = na 31 | var line r1line = na 32 | var line r2line = na 33 | var line r3line = na 34 | var line r4line = na 35 | var line mpr0line = na 36 | var line mpr1line = na 37 | var line mpr2line = na 38 | var line mpr3line = na 39 | var line s1line = na 40 | var line s2line = na 41 | var line s3line = na 42 | var line s4line = na 43 | var line mps0line = na 44 | var line mps1line = na 45 | var line mps2line = na 46 | var line mps3line = na 47 | 48 | if pp[1] != pp 49 | line.set_x2(ppline, bar_index) 50 | line.set_x2(r1line, bar_index) 51 | line.set_x2(r2line, bar_index) 52 | line.set_x2(r3line, bar_index) 53 | line.set_x2(r4line, bar_index) 54 | line.set_x2(mpr0line, bar_index) 55 | line.set_x2(mpr1line, bar_index) 56 | line.set_x2(mpr2line, bar_index) 57 | line.set_x2(mpr3line, bar_index) 58 | line.set_x2(s1line, bar_index) 59 | line.set_x2(s2line, bar_index) 60 | line.set_x2(s3line, bar_index) 61 | line.set_x2(s4line, bar_index) 62 | line.set_x2(mps0line, bar_index) 63 | line.set_x2(mps1line, bar_index) 64 | line.set_x2(mps2line, bar_index) 65 | line.set_x2(mps3line, bar_index) 66 | line.set_extend(ppline, extend.none) 67 | line.set_extend(r1line, extend.none) 68 | line.set_extend(r2line, extend.none) 69 | line.set_extend(r3line, extend.none) 70 | line.set_extend(r4line, extend.none) 71 | line.set_extend(mpr0line, extend.none) 72 | line.set_extend(mpr1line, extend.none) 73 | line.set_extend(mpr2line, extend.none) 74 | line.set_extend(mpr3line, extend.none) 75 | line.set_extend(s1line, extend.none) 76 | line.set_extend(s2line, extend.none) 77 | line.set_extend(s3line, extend.none) 78 | line.set_extend(s4line, extend.none) 79 | line.set_extend(mps0line, extend.none) 80 | line.set_extend(mps1line, extend.none) 81 | line.set_extend(mps2line, extend.none) 82 | line.set_extend(mps3line, extend.none) 83 | r4line := line.new(bar_index, r4, bar_index, r4, width=1, extend=extend.right, color=#ffffff80) 84 | r3line := line.new(bar_index, r3, bar_index, r3, width=1, extend=extend.right, color=#ffffff80) 85 | r2line := line.new(bar_index, r2, bar_index, r2, width=1, extend=extend.right, color=#ffffff80) 86 | r1line := line.new(bar_index, r1, bar_index, r1, width=1, extend=extend.right, color=#ffffff80) 87 | mpr3line := line.new(bar_index, mpr3, bar_index, mpr3, width=1, extend=extend.right, color=#ffffff40) 88 | mpr2line := line.new(bar_index, mpr2, bar_index, mpr2, width=1, extend=extend.right, color=#ffffff40) 89 | mpr1line := line.new(bar_index, mpr1, bar_index, mpr1, width=1, extend=extend.right, color=#ffffff40) 90 | mpr0line := line.new(bar_index, mpr0, bar_index, mpr0, width=1, extend=extend.right, color=#ffffff40) 91 | ppline := line.new(bar_index, pp, bar_index, pp, width=2, extend=extend.right, color=color.blue) 92 | mps0line := line.new(bar_index, mps0, bar_index, mps0, width=1, extend=extend.right, color=#ffffff40) 93 | mps1line := line.new(bar_index, mps1, bar_index, mps1, width=1, extend=extend.right, color=#ffffff40) 94 | mps2line := line.new(bar_index, mps2, bar_index, mps2, width=1, extend=extend.right, color=#ffffff40) 95 | mps3line := line.new(bar_index, mps3, bar_index, mps3, width=1, extend=extend.right, color=#ffffff40) 96 | s1line := line.new(bar_index, s1, bar_index, s1, width=1, extend=extend.right, color=#ffffff80) 97 | s2line := line.new(bar_index, s2, bar_index, s2, width=1, extend=extend.right, color=#ffffff80) 98 | s3line := line.new(bar_index, s3, bar_index, s3, width=1, extend=extend.right, color=#ffffff80) 99 | s4line := line.new(bar_index, s4, bar_index, s4, width=1, extend=extend.right, color=#ffffff80) 100 | label.new(bar_index, r4, "R4", style=label.style_none, textcolor=color.white) 101 | label.new(bar_index, r3, "R3", style=label.style_none, textcolor=color.white) 102 | label.new(bar_index, r2, "R2", style=label.style_none, textcolor=color.white) 103 | label.new(bar_index, r1, "R1", style=label.style_none, textcolor=color.white) 104 | label.new(bar_index, mpr3, "MP", style=label.style_none, textcolor=#ffffff40) 105 | label.new(bar_index, mpr2, "MP", style=label.style_none, textcolor=#ffffff40) 106 | label.new(bar_index, mpr1, "MP", style=label.style_none, textcolor=#ffffff40) 107 | label.new(bar_index, mpr0, "MP", style=label.style_none, textcolor=#ffffff40) 108 | label.new(bar_index, pp, "PP", style=label.style_none, textcolor=color.white) 109 | label.new(bar_index, mps0, "MP", style=label.style_none, textcolor=#ffffff40) 110 | label.new(bar_index, mps1, "MP", style=label.style_none, textcolor=#ffffff40) 111 | label.new(bar_index, mps2, "MP", style=label.style_none, textcolor=#ffffff40) 112 | label.new(bar_index, mps3, "MP", style=label.style_none, textcolor=#ffffff40) 113 | label.new(bar_index, s1, "S1", style=label.style_none, textcolor=color.white) 114 | label.new(bar_index, s2, "S2", style=label.style_none, textcolor=color.white) 115 | label.new(bar_index, s3, "S3", style=label.style_none, textcolor=color.white) 116 | label.new(bar_index, s4, "S4", style=label.style_none, textcolor=color.white) 117 | 118 | if not na(ppline) and line.get_x2(ppline) != bar_index 119 | line.set_x2(r4line, bar_index) 120 | line.set_x2(r3line, bar_index) 121 | line.set_x2(r2line, bar_index) 122 | line.set_x2(r1line, bar_index) 123 | line.set_x2(mpr3line, bar_index) 124 | line.set_x2(mpr2line, bar_index) 125 | line.set_x2(mpr1line, bar_index) 126 | line.set_x2(mpr0line, bar_index) 127 | line.set_x2(ppline, bar_index) 128 | line.set_x2(mps0line, bar_index) 129 | line.set_x2(mps1line, bar_index) 130 | line.set_x2(mps2line, bar_index) 131 | line.set_x2(mps3line, bar_index) 132 | line.set_x2(s1line, bar_index) 133 | line.set_x2(s2line, bar_index) 134 | line.set_x2(s3line, bar_index) 135 | line.set_x2(s4line, bar_index) 136 | -------------------------------------------------------------------------------- /reversals/engulfing-ema.pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © tista 3 | 4 | //@version=4 5 | study("Engulfing Candles", overlay=true) 6 | 7 | useEmaAsConfirmation = input(true, title="Use EMA As Confirmation?", defval=false) 8 | showEma = input(false, title="Show EMA Line?", defval=false) 9 | emaPeriod = input(200, title="EMA Period (Surpress noise with higher EMA periods)", defval=200) 10 | 11 | emaVals = ema(close, emaPeriod) 12 | 13 | isBullishEngulfing = open[1] > close[1] and open >= close[1] and open <= close[1] and close >= open[1] and (useEmaAsConfirmation ? close <= emaVals : true) 14 | isBearishEngulfing = open[1] < close[1] and open <= close[1] and open >= close[1] and close <= open[1] and (useEmaAsConfirmation ? close >= emaVals : true) 15 | 16 | vals = isBullishEngulfing ? 1 : isBearishEngulfing ? -1 : na 17 | 18 | // plotbar(open, high, low, close, title="Engulfing Candle", color = colors) 19 | plotarrow(vals, title="Engulfing Candles", colorup=color.teal, colordown=color.orange, transp=40, maxheight=15) 20 | plot(emaVals, title="EMA", color=showEma ? color.yellow : na, linewidth=2, transp=0) 21 | -------------------------------------------------------------------------------- /reversals/engulfing-vwma.pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © tista 3 | 4 | //@version=4 5 | study("Engulfing Candles - VWMA", overlay=true) 6 | 7 | useEmaAsConfirmation = input(true, title="Use VWMA As Confirmation?", defval=false) 8 | showEma = input(false, title="Show VWMA Line?", defval=false) 9 | emaPeriod = input(21, title="VWMA Period (Surpress noise with higher VWMA periods)", defval=21) 10 | emaPeriod2 = input(200, title="VWMA Period for second line (not used for calculation)", defval=200) 11 | 12 | emaVals = vwma(close, emaPeriod) 13 | ema2Vals = vwma(close, emaPeriod2) 14 | 15 | isBullishEngulfing = open[1] > close[1] and open >= close[1] and open <= close[1] and close >= open[1] and (useEmaAsConfirmation ? close <= emaVals : true) 16 | isBearishEngulfing = open[1] < close[1] and open <= close[1] and open >= close[1] and close <= open[1] and (useEmaAsConfirmation ? close >= emaVals : true) 17 | 18 | vals = isBullishEngulfing ? 1 : isBearishEngulfing ? -1 : na 19 | 20 | // plotbar(open, high, low, close, title="Engulfing Candle", color = colors) 21 | plotarrow(vals, title="Engulfing Candles", colorup=color.teal, colordown=color.orange, transp=40, maxheight=15) 22 | plot(showEma ? emaVals : na, title="VWMAPrimary", color=showEma ? color.blue : na, linewidth=2, transp=0) 23 | plot(showEma ? ema2Vals : na, title="VWMASecondary", color=showEma ? color.yellow : na, linewidth=2, transp=0) 24 | --------------------------------------------------------------------------------