Advertisement
frentzy

Tradeview

Dec 31st, 2020 (edited)
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.97 KB | None | 0 0
  1. //@version=4
  2.  
  3. //https://discord.gg/85GkC9Uk6z
  4. // https://discord.gg/McQAZQzwgH
  5. // bps https://discord.gg/fpnD4mTvUv
  6. study(title = 'Market Cipher B [WEA] Beta + Divergeces', shorttitle = 'WEACipher_B_Divergences')
  7.  
  8.  
  9. // PARAMETERS {
  10.  
  11.  
  12. // WaveTrend
  13.  
  14. wtShow = input(true, title = 'Show WaveTrend', type = input.bool)
  15.  
  16. wtBuyShow = input(true, title = 'Show Buy dots', type = input.bool)
  17.  
  18. wtGoldShow = input(true, title = 'Show Gold dots', type = input.bool)
  19.  
  20. wtSellShow = input(true, title = 'Show Sell dots', type = input.bool)
  21.  
  22. wtDivShow = input(true, title = 'Show Div. dots', type = input.bool)
  23.  
  24. vwapShow = input(true, title = 'Show Fast WT', type = input.bool)
  25.  
  26. wtChannelLen = input(9, title = 'WT Channel Length', type = input.integer)
  27.  
  28. wtAverageLen = input(13, title = 'WT Average Length', type = input.integer)
  29.  
  30. wtMASource = input(ohlc4, title = 'WT MA Source', type = input.source)
  31.  
  32. wtMALen = input(3, title = 'WT MA Length', type = input.integer)
  33.  
  34.  
  35. // WaveTrend Overbought & Oversold lines
  36.  
  37. obLevel = input(53, title = 'WT Overbought Level 1', type = input.integer)
  38.  
  39. obLevel2 = input(60, title = 'WT Overbought Level 2', type = input.integer)
  40.  
  41. obLevel3 = input(100, title = 'WT Overbought Level 3', type = input.integer)
  42.  
  43. osLevel = input(-53, title = 'WT Oversold Level 1', type = input.integer)
  44.  
  45. osLevel2 = input(-60, title = 'WT Oversold Level 2', type = input.integer)
  46.  
  47. osLevel3 = input(-75, title = 'WT Oversold Level 3', type = input.integer)
  48.  
  49.  
  50. // Divergence WT
  51.  
  52. wtShowDiv = input(true, title = 'Show WT Regular Divergences', type = input.bool)
  53.  
  54. wtShowHiddenDiv = input(false, title = 'Show WT Hidden Divergences', type = input.bool)
  55.  
  56. showHiddenDiv_nl = input(true, title = 'Not apply OB/OS Limits on Hidden Divergences', type = input.bool)
  57.  
  58. wtDivOBLevel = input(45, title = 'WT Bearish Divergence min', type = input.integer)
  59.  
  60. wtDivOSLevel = input(-65, title = 'WT Bullish Divergence min', type = input.integer)
  61.  
  62.  
  63. // Divergence extra range
  64.  
  65. wtDivOBLevel_addshow = input(true, title = 'Show 2nd WT Regular Divergences', type = input.bool)
  66.  
  67. wtDivOBLevel_add = input(15, title = 'WT 2nd Bearish Divergence', type = input.integer)
  68.  
  69. wtDivOSLevel_add = input(-40, title = 'WT 2nd Bullish Divergence 15 min', type = input.integer)
  70.  
  71.  
  72. // RSI+MFI
  73.  
  74. rsiMFIShow = input(true, title = 'Show MFI', type = input.bool)
  75.  
  76. rsiMFIperiod = input(60,title = 'MFI Period', type = input.integer)
  77.  
  78. rsiMFIMultiplier = input(150, title = 'MFI Area multiplier', type = input.float)
  79.  
  80. rsiMFIPosY = input(2.5, title = 'MFI Area Y Pos', type = input.float)
  81.  
  82.  
  83. // RSI
  84.  
  85. rsiShow = input(false, title = 'Show RSI', type = input.bool)
  86.  
  87. rsiSRC = input(close, title = 'RSI Source', type = input.source)
  88.  
  89. rsiLen = input(14, title = 'RSI Length', type = input.integer)
  90.  
  91. rsiOversold = input(30, title = 'RSI Oversold', minval = 50, maxval = 100, type = input.integer)
  92.  
  93. rsiOverbought = input(60, title = 'RSI Overbought', minval = 0, maxval = 50, type = input.integer)
  94.  
  95.  
  96. // Divergence RSI
  97.  
  98. rsiShowDiv = input(false, title = 'Show RSI Regular Divergences', type = input.bool)
  99.  
  100. rsiShowHiddenDiv = input(false, title = 'Show RSI Hidden Divergences', type = input.bool)
  101.  
  102. rsiDivOBLevel = input(60, title = 'RSI Bearish Divergence min', type = input.integer)
  103.  
  104. rsiDivOSLevel = input(30, title = 'RSI Bullish Divergence min', type = input.integer)
  105.  
  106.  
  107. // RSI Stochastic
  108.  
  109. stochShow = input(true, title = 'Show Stochastic RSI', type = input.bool)
  110.  
  111. stochUseLog = input(true, title=' Use Log?', type = input.bool)
  112.  
  113. stochAvg = input(false, title='Use Average of both K & D', type = input.bool)
  114.  
  115. stochSRC = input(close, title = 'Stochastic RSI Source', type = input.source)
  116.  
  117. stochLen = input(14, title = 'Stochastic RSI Length', type = input.integer)
  118.  
  119. stochRsiLen = input(14, title = 'RSI Length ', type = input.integer)
  120.  
  121. stochKSmooth = input(3, title = 'Stochastic RSI K Smooth', type = input.integer)
  122.  
  123. stochDSmooth = input(3, title = 'Stochastic RSI D Smooth', type = input.integer)
  124.  
  125.  
  126. // Divergence stoch
  127.  
  128. stochShowDiv = input(false, title = 'Show Stoch Regular Divergences', type = input.bool)
  129.  
  130. stochShowHiddenDiv = input(false, title = 'Show Stoch Hidden Divergences', type = input.bool)
  131.  
  132.  
  133. // Schaff Trend Cycle
  134.  
  135. tcLine = input(false, title="Show Schaff TC line", type=input.bool)
  136.  
  137. tcSRC = input(close, title = 'Schaff TC Source', type = input.source)
  138.  
  139. tclength = input(10, title="Schaff TC", type=input.integer)
  140.  
  141. tcfastLength = input(23, title="Schaff TC Fast Lenght", type=input.integer)
  142.  
  143. tcslowLength = input(50, title="Schaff TC Slow Length", type=input.integer)
  144.  
  145. tcfactor = input(0.5, title="Schaff TC Factor", type=input.float)
  146.  
  147.  
  148. // Sommi Flag
  149.  
  150. sommiFlagShow = input(false, title = 'Show Sommi flag', type = input.bool)
  151.  
  152. sommiShowVwap = input(false, title = 'Show Sommi F. Wave', type = input.bool)
  153.  
  154. sommiVwapTF = input('720', title = 'Sommi F. Wave timeframe', type = input.string)
  155.  
  156. sommiVwapBearLevel = input(0, title = 'F. Wave Bear Level (less than)', type = input.integer)
  157.  
  158. sommiVwapBullLevel = input(0, title = 'F. Wave Bull Level (more than)', type = input.integer)
  159.  
  160. soomiFlagWTBearLevel = input(0, title = 'WT Bear Level (more than)', type = input.integer)
  161.  
  162. soomiFlagWTBullLevel = input(0, title = 'WT Bull Level (less than)', type = input.integer)
  163.  
  164. soomiRSIMFIBearLevel = input(0, title = 'Money flow Bear Level (less than)', type = input.integer)
  165.  
  166. soomiRSIMFIBullLevel = input(0, title = 'Money flow Bull Level (more than)', type = input.integer)
  167.  
  168.  
  169. // Sommi Diamond
  170.  
  171. sommiDiamondShow = input(false, title = 'Show Sommi diamond', type = input.bool)
  172.  
  173. sommiHTCRes = input('60', title = 'HTF Candle Res. 1', type = input.string)
  174.  
  175. sommiHTCRes2 = input('240', title = 'HTF Candle Res. 2', type = input.string)
  176.  
  177. soomiDiamondWTBearLevel = input(0, title = 'WT Bear Level (More than)', type = input.integer)
  178.  
  179. soomiDiamondWTBullLevel = input(0, title = 'WT Bull Level (Less than)', type = input.integer)
  180.  
  181.  
  182. // macd Colors
  183.  
  184. macdWTColorsShow = input(false, title = 'Show MACD Colors', type = input.bool)
  185.  
  186. macdWTColorsTF = input('240', title = 'MACD Colors MACD TF', type = input.string)
  187.  
  188.  
  189. darkMode = input(false, title = 'Dark mode', type = input.bool)
  190.  
  191.  
  192.  
  193. // Colors
  194.  
  195. colorRed = #ff0000
  196.  
  197. colorPurple = #e600e6
  198.  
  199. colorGreen = #3fff00
  200.  
  201. colorOrange = #e2a400
  202.  
  203. colorYellow = #ffe500
  204.  
  205. colorWhite = #ffffff
  206.  
  207. colorPink = #ff00f0
  208.  
  209. colorBluelight = #31c0ff
  210.  
  211.  
  212. colorWT1 = #90caf9
  213.  
  214. colorWT2 = #0d47a1
  215.  
  216.  
  217. colorWT2_ = #131722
  218.  
  219.  
  220. colormacdWT1a = #4caf58
  221.  
  222. colormacdWT1b = #af4c4c
  223.  
  224. colormacdWT1c = #7ee57e
  225.  
  226. colormacdWT1d = #ff3535
  227.  
  228.  
  229. colormacdWT2a = #305630
  230.  
  231. colormacdWT2b = #310101
  232.  
  233. colormacdWT2c = #132213
  234.  
  235. colormacdWT2d = #770000
  236.  
  237.  
  238. // } PARAMETERS
  239.  
  240.  
  241.  
  242. // FUNCTIONS {
  243.  
  244.  
  245.  
  246. // Divergences
  247.  
  248. f_top_fractal(src) => src[4] < src[2] and src[3] < src[2] and src[2] > src[1] and src[2] > src[0]
  249.  
  250. f_bot_fractal(src) => src[4] > src[2] and src[3] > src[2] and src[2] < src[1] and src[2] < src[0]
  251.  
  252. f_fractalize(src) => f_top_fractal(src) ? 1 : f_bot_fractal(src) ? -1 : 0
  253.  
  254.  
  255. f_findDivs(src, topLimit, botLimit, useLimits) =>
  256.  
  257. fractalTop = f_fractalize(src) > 0 and (useLimits ? src[2] >= topLimit : true) ? src[2] : na
  258.  
  259. fractalBot = f_fractalize(src) < 0 and (useLimits ? src[2] <= botLimit : true) ? src[2] : na
  260.  
  261. highPrev = valuewhen(fractalTop, src[2], 0)[2]
  262.  
  263. highPrice = valuewhen(fractalTop, high[2], 0)[2]
  264.  
  265. lowPrev = valuewhen(fractalBot, src[2], 0)[2]
  266.  
  267. lowPrice = valuewhen(fractalBot, low[2], 0)[2]
  268.  
  269. bearSignal = fractalTop and high[2] > highPrice and src[2] < highPrev
  270.  
  271. bullSignal = fractalBot and low[2] < lowPrice and src[2] > lowPrev
  272.  
  273. bearDivHidden = fractalTop and high[2] < highPrice and src[2] > highPrev
  274.  
  275. bullDivHidden = fractalBot and low[2] > lowPrice and src[2] < lowPrev
  276.  
  277. [fractalTop, fractalBot, lowPrev, bearSignal, bullSignal, bearDivHidden, bullDivHidden]
  278.  
  279.  
  280.  
  281. // RSI+MFI
  282.  
  283. f_rsimfi(_period, _multiplier, _tf) => security(syminfo.tickerid, _tf, sma(((close - open) / (high - low)) * _multiplier, _period) - rsiMFIPosY)
  284.  
  285.  
  286.  
  287. // WaveTrend
  288.  
  289. f_wavetrend(src, chlen, avg, malen, tf) =>
  290.  
  291. tfsrc = security(syminfo.tickerid, tf, src)
  292.  
  293. esa = ema(tfsrc, chlen)
  294.  
  295. de = ema(abs(tfsrc - esa), chlen)
  296.  
  297. ci = (tfsrc - esa) / (0.015 * de)
  298.  
  299. wt1 = security(syminfo.tickerid, tf, ema(ci, avg))
  300.  
  301. wt2 = security(syminfo.tickerid, tf, sma(wt1, malen))
  302.  
  303. wtVwap = wt1 - wt2
  304.  
  305. wtOversold = wt2 <= osLevel
  306.  
  307. wtOverbought = wt2 >= obLevel
  308.  
  309. wtCross = cross(wt1, wt2)
  310.  
  311. wtCrossUp = wt2 - wt1 <= 0
  312.  
  313. wtCrossDown = wt2 - wt1 >= 0
  314.  
  315. wtCrosslast = cross(wt1[2], wt2[2])
  316.  
  317. wtCrossUplast = wt2[2] - wt1[2] <= 0
  318.  
  319. wtCrossDownlast = wt2[2] - wt1[2] >= 0
  320.  
  321. [wt1, wt2, wtOversold, wtOverbought, wtCross, wtCrossUp, wtCrossDown, wtCrosslast, wtCrossUplast, wtCrossDownlast, wtVwap]
  322.  
  323.  
  324. // Schaff Trend Cycle
  325.  
  326. f_tc(src, length, fastLength, slowLength) =>
  327.  
  328. ema1 = ema(src, fastLength)
  329.  
  330. ema2 = ema(src, slowLength)
  331.  
  332. macdVal = ema1 - ema2
  333.  
  334. alpha = lowest(macdVal, length)
  335.  
  336. beta = highest(macdVal, length) - alpha
  337.  
  338. gamma = (macdVal - alpha) / beta * 100
  339.  
  340. gamma := beta > 0 ? gamma : nz(gamma[1])
  341.  
  342. delta = gamma
  343.  
  344. delta := na(delta[1]) ? delta : delta[1] + tcfactor * (gamma - delta[1])
  345.  
  346. epsilon = lowest(delta, length)
  347.  
  348. zeta = highest(delta, length) - epsilon
  349.  
  350. eta = (delta - epsilon) / zeta * 100
  351.  
  352. eta := zeta > 0 ? eta : nz(eta[1])
  353.  
  354. stcReturn = eta
  355.  
  356. stcReturn := na(stcReturn[1]) ? stcReturn : stcReturn[1] + tcfactor * (eta - stcReturn[1])
  357.  
  358. stcReturn
  359.  
  360.  
  361. // Stochastic RSI
  362.  
  363. f_stochrsi(_src, _stochlen, _rsilen, _smoothk, _smoothd, _log, _avg) =>
  364.  
  365. src = _log ? log(_src) : _src
  366.  
  367. rsi = rsi(src, _rsilen)
  368.  
  369. kk = sma(stoch(rsi, rsi, rsi, _stochlen), _smoothk)
  370.  
  371. d1 = sma(kk, _smoothd)
  372.  
  373. avg_1 = avg(kk, d1)
  374.  
  375. k = _avg ? avg_1 : kk
  376.  
  377. [k, d1]
  378.  
  379.  
  380. // MACD
  381.  
  382. f_macd(src, fastlen, slowlen, sigsmooth, tf) =>
  383.  
  384. fast_ma = security(syminfo.tickerid, tf, ema(src, fastlen))
  385.  
  386. slow_ma = security(syminfo.tickerid, tf, ema(src, slowlen))
  387.  
  388. macd = fast_ma - slow_ma,
  389.  
  390. signal = security(syminfo.tickerid, tf, sma(macd, sigsmooth))
  391.  
  392. hist = macd - signal
  393.  
  394. [macd, signal, hist]
  395.  
  396.  
  397. // MACD Colors on WT
  398.  
  399. f_macdWTColors(tf) =>
  400.  
  401. hrsimfi = f_rsimfi(rsiMFIperiod, rsiMFIMultiplier, tf)
  402.  
  403. [macd, signal, hist] = f_macd(close, 28, 42, 9, macdWTColorsTF)
  404.  
  405. macdup = macd >= signal
  406.  
  407. macddown = macd <= signal
  408.  
  409. macdWT1Color = macdup ? hrsimfi > 0 ? colormacdWT1c : colormacdWT1a : macddown ? hrsimfi < 0 ? colormacdWT1d : colormacdWT1b : na
  410.  
  411. macdWT2Color = macdup ? hrsimfi < 0 ? colormacdWT2c : colormacdWT2a : macddown ? hrsimfi < 0 ? colormacdWT2d : colormacdWT2b : na
  412.  
  413. [macdWT1Color, macdWT2Color]
  414.  
  415.  
  416.  
  417. // Get higher timeframe candle
  418.  
  419. f_getTFCandle(_tf) =>
  420.  
  421. _open = security(heikinashi(syminfo.tickerid), _tf, open, barmerge.gaps_off, barmerge.lookahead_on)
  422.  
  423. _close = security(heikinashi(syminfo.tickerid), _tf, close, barmerge.gaps_off, barmerge.lookahead_on)
  424.  
  425. _high = security(heikinashi(syminfo.tickerid), _tf, high, barmerge.gaps_off, barmerge.lookahead_on)
  426.  
  427. _low = security(heikinashi(syminfo.tickerid), _tf, low, barmerge.gaps_off, barmerge.lookahead_on)
  428.  
  429. hl2 = (_high + _low) / 2.0
  430.  
  431. newBar = change(_open)
  432.  
  433. candleBodyDir = _close > _open
  434.  
  435. [candleBodyDir, newBar]
  436.  
  437.  
  438. // Sommi flag
  439.  
  440. f_findSommiFlag(tf, wt1, wt2, rsimfi, wtCross, wtCrossUp, wtCrossDown) =>
  441.  
  442. [hwt1, hwt2, hwtOversold, hwtOverbought, hwtCross, hwtCrossUp, hwtCrossDown, hwtCrosslast, hwtCrossUplast, hwtCrossDownlast, hwtVwap] = f_wavetrend(wtMASource, wtChannelLen, wtAverageLen, wtMALen, tf)
  443.  
  444.  
  445.  
  446. bearPattern = rsimfi < soomiRSIMFIBearLevel and
  447.  
  448. wt2 > soomiFlagWTBearLevel and
  449.  
  450. wtCross and
  451.  
  452. wtCrossDown and
  453.  
  454. hwtVwap < sommiVwapBearLevel
  455.  
  456.  
  457.  
  458. bullPattern = rsimfi > soomiRSIMFIBullLevel and
  459.  
  460. wt2 < soomiFlagWTBullLevel and
  461.  
  462. wtCross and
  463.  
  464. wtCrossUp and
  465.  
  466. hwtVwap > sommiVwapBullLevel
  467.  
  468.  
  469.  
  470. [bearPattern, bullPattern, hwtVwap]
  471.  
  472.  
  473.  
  474. f_findSommiDiamond(tf, tf2, wt1, wt2, wtCross, wtCrossUp, wtCrossDown) =>
  475.  
  476. [candleBodyDir, newBar] = f_getTFCandle(tf)
  477.  
  478. [candleBodyDir2, newBar2] = f_getTFCandle(tf2)
  479.  
  480. bearPattern = wt2 >= soomiDiamondWTBearLevel and
  481.  
  482. wtCross and
  483.  
  484. wtCrossDown and
  485.  
  486. not candleBodyDir and
  487.  
  488. not candleBodyDir2
  489.  
  490. bullPattern = wt2 <= soomiDiamondWTBullLevel and
  491.  
  492. wtCross and
  493.  
  494. wtCrossUp and
  495.  
  496. candleBodyDir and
  497.  
  498. candleBodyDir2
  499.  
  500. [bearPattern, bullPattern]
  501.  
  502.  
  503.  
  504. // } FUNCTIONS
  505.  
  506.  
  507. // CALCULATE INDICATORS {
  508.  
  509.  
  510. // RSI
  511.  
  512. rsi = rsi(rsiSRC, rsiLen)
  513.  
  514. rsiColor = rsi <= rsiOversold ? colorGreen : rsi >= rsiOverbought ? colorRed : colorPurple
  515.  
  516.  
  517. // RSI + MFI Area
  518.  
  519. rsiMFI = f_rsimfi(rsiMFIperiod, rsiMFIMultiplier, timeframe.period)
  520.  
  521. rsiMFIColor = rsiMFI > 0 ? #3ee145 : #ff3d2e
  522.  
  523.  
  524. // Calculates WaveTrend
  525.  
  526. [wt1, wt2, wtOversold, wtOverbought, wtCross, wtCrossUp, wtCrossDown, wtCross_last, wtCrossUp_last, wtCrossDown_last, wtVwap] = f_wavetrend(wtMASource, wtChannelLen, wtAverageLen, wtMALen, timeframe.period)
  527.  
  528.  
  529.  
  530. // Stochastic RSI
  531.  
  532. [stochK, stochD] = f_stochrsi(stochSRC, stochLen, stochRsiLen, stochKSmooth, stochDSmooth, stochUseLog, stochAvg)
  533.  
  534.  
  535. // Schaff Trend Cycle
  536.  
  537. tcVal = f_tc(tcSRC, tclength, tcfastLength, tcslowLength)
  538.  
  539.  
  540. // Sommi flag
  541.  
  542. [sommiBearish, sommiBullish, hvwap] = f_findSommiFlag(sommiVwapTF, wt1, wt2, rsiMFI, wtCross, wtCrossUp, wtCrossDown)
  543.  
  544.  
  545. //Sommi diamond
  546.  
  547. [sommiBearishDiamond, sommiBullishDiamond] = f_findSommiDiamond(sommiHTCRes, sommiHTCRes2, wt1, wt2, wtCross, wtCrossUp, wtCrossDown)
  548.  
  549.  
  550. // macd colors
  551.  
  552. [macdWT1Color, macdWT2Color] = f_macdWTColors(macdWTColorsTF)
  553.  
  554.  
  555. // WT Divergences
  556.  
  557. [wtFractalTop, wtFractalBot, wtLow_prev, wtBearDiv, wtBullDiv, wtBearDivHidden, wtBullDivHidden] = f_findDivs(wt2, wtDivOBLevel, wtDivOSLevel, true)
  558.  
  559.  
  560.  
  561. [wtFractalTop_add, wtFractalBot_add, wtLow_prev_add, wtBearDiv_add, wtBullDiv_add, wtBearDivHidden_add, wtBullDivHidden_add] = f_findDivs(wt2, wtDivOBLevel_add, wtDivOSLevel_add, true)
  562.  
  563. [wtFractalTop_nl, wtFractalBot_nl, wtLow_prev_nl, wtBearDiv_nl, wtBullDiv_nl, wtBearDivHidden_nl, wtBullDivHidden_nl] = f_findDivs(wt2, 0, 0, false)
  564.  
  565.  
  566. wtBearDivHidden_ = showHiddenDiv_nl ? wtBearDivHidden_nl : wtBearDivHidden
  567.  
  568. wtBullDivHidden_ = showHiddenDiv_nl ? wtBullDivHidden_nl : wtBullDivHidden
  569.  
  570.  
  571. wtBearDivColor = (wtShowDiv and wtBearDiv) or (wtShowHiddenDiv and wtBearDivHidden_) ? colorRed : na
  572.  
  573. wtBullDivColor = (wtShowDiv and wtBullDiv) or (wtShowHiddenDiv and wtBullDivHidden_) ? colorGreen : na
  574.  
  575.  
  576. wtBearDivColor_add = (wtShowDiv and (wtDivOBLevel_addshow and wtBearDiv_add)) or (wtShowHiddenDiv and (wtDivOBLevel_addshow and wtBearDivHidden_add)) ? #9a0202 : na
  577.  
  578. wtBullDivColor_add = (wtShowDiv and (wtDivOBLevel_addshow and wtBullDiv_add)) or (wtShowHiddenDiv and (wtDivOBLevel_addshow and wtBullDivHidden_add)) ? #1b5e20 : na
  579.  
  580.  
  581. // RSI Divergences
  582.  
  583. [rsiFractalTop, rsiFractalBot, rsiLow_prev, rsiBearDiv, rsiBullDiv, rsiBearDivHidden, rsiBullDivHidden] = f_findDivs(rsi, rsiDivOBLevel, rsiDivOSLevel, true)
  584.  
  585. [rsiFractalTop_nl, rsiFractalBot_nl, rsiLow_prev_nl, rsiBearDiv_nl, rsiBullDiv_nl, rsiBearDivHidden_nl, rsiBullDivHidden_nl] = f_findDivs(rsi, 0, 0, false)
  586.  
  587.  
  588. rsiBearDivHidden_ = showHiddenDiv_nl ? rsiBearDivHidden_nl : rsiBearDivHidden
  589.  
  590. rsiBullDivHidden_ = showHiddenDiv_nl ? rsiBullDivHidden_nl : rsiBullDivHidden
  591.  
  592.  
  593. rsiBearDivColor = (rsiShowDiv and rsiBearDiv) or (rsiShowHiddenDiv and rsiBearDivHidden_) ? colorRed : na
  594.  
  595. rsiBullDivColor = (rsiShowDiv and rsiBullDiv) or (rsiShowHiddenDiv and rsiBullDivHidden_) ? colorGreen : na
  596.  
  597.  
  598.  
  599. // Stoch Divergences
  600.  
  601. [stochFractalTop, stochFractalBot, stochLow_prev, stochBearDiv, stochBullDiv, stochBearDivHidden, stochBullDivHidden] = f_findDivs(stochK, 0, 0, false)
  602.  
  603.  
  604. stochBearDivColor = (stochShowDiv and stochBearDiv) or (stochShowHiddenDiv and stochBearDivHidden) ? colorRed : na
  605.  
  606. stochBullDivColor = (stochShowDiv and stochBullDiv) or (stochShowHiddenDiv and stochBullDivHidden) ? colorGreen : na
  607.  
  608.  
  609.  
  610. // Small Circles WT Cross
  611.  
  612. signalColor = wt2 - wt1 > 0 ? color.red : color.lime
  613.  
  614.  
  615. // Buy signal.
  616.  
  617. buySignal = wtCross and wtCrossUp and wtOversold
  618.  
  619.  
  620. buySignalDiv = (wtShowDiv and wtBullDiv) or
  621.  
  622. (wtShowDiv and wtBullDiv_add) or
  623.  
  624. (stochShowDiv and stochBullDiv) or
  625.  
  626. (rsiShowDiv and rsiBullDiv)
  627.  
  628.  
  629.  
  630. buySignalDiv_color = wtBullDiv ? colorGreen :
  631.  
  632. wtBullDiv_add ? color.new(colorGreen, 60) :
  633.  
  634. rsiShowDiv ? colorGreen : na
  635.  
  636.  
  637. // Sell signal
  638.  
  639. sellSignal = wtCross and wtCrossDown and wtOverbought
  640.  
  641.  
  642.  
  643. sellSignalDiv = (wtShowDiv and wtBearDiv) or
  644.  
  645. (wtShowDiv and wtBearDiv_add) or
  646.  
  647. (stochShowDiv and stochBearDiv) or
  648.  
  649. (rsiShowDiv and rsiBearDiv)
  650.  
  651.  
  652.  
  653. sellSignalDiv_color = wtBearDiv ? colorRed :
  654.  
  655. wtBearDiv_add ? color.new(colorRed, 60) :
  656.  
  657. rsiBearDiv ? colorRed : na
  658.  
  659.  
  660. // Gold Buy
  661.  
  662. lastRsi = valuewhen(wtFractalBot, rsi[2], 0)[2]
  663.  
  664. wtGoldBuy = ((wtShowDiv and wtBullDiv) or (rsiShowDiv and rsiBullDiv)) and
  665.  
  666. wtLow_prev <= osLevel3 and
  667.  
  668. wt2 > osLevel3 and
  669.  
  670. wtLow_prev - wt2 <= -5 and
  671.  
  672. lastRsi < 30
  673.  
  674.  
  675.  
  676. // } CALCULATE INDICATORS
  677.  
  678.  
  679.  
  680. // DRAW {
  681.  
  682. bgcolor(darkMode ? color.new(#000000, 80) : na)
  683.  
  684. zLine = plot(0, color = color.new(colorWhite, 50))
  685.  
  686.  
  687. // MFI BAR
  688.  
  689. rsiMfiBarTopLine = plot(rsiMFIShow ? -95 : na, title = 'MFI Bar TOP Line', transp = 100)
  690.  
  691. rsiMfiBarBottomLine = plot(rsiMFIShow ? -99 : na, title = 'MFI Bar BOTTOM Line', transp = 100)
  692.  
  693. fill(rsiMfiBarTopLine, rsiMfiBarBottomLine, title = 'MFI Bar Colors', color = rsiMFIColor, transp = 75)
  694.  
  695.  
  696. // WT Areas
  697.  
  698. plot(wtShow ? wt1 : na, style = plot.style_area, title = 'WT Wave 1', color = macdWTColorsShow ? macdWT1Color : colorWT1, transp = 0)
  699.  
  700. plot(wtShow ? wt2 : na, style = plot.style_area, title = 'WT Wave 2', color = macdWTColorsShow ? macdWT2Color : darkMode ? colorWT2_ : colorWT2 , transp = 20)
  701.  
  702.  
  703. // VWAP
  704.  
  705. plot(vwapShow ? wtVwap : na, title = 'VWAP', color = colorYellow, style = plot.style_area, linewidth = 2, transp = 45)
  706.  
  707.  
  708. // MFI AREA
  709.  
  710. rsiMFIplot = plot(rsiMFIShow ? rsiMFI: na, title = 'RSI+MFI Area', color = rsiMFIColor, transp = 20)
  711.  
  712. fill(rsiMFIplot, zLine, rsiMFIColor, transp = 40)
  713.  
  714.  
  715. // WT Div
  716.  
  717.  
  718. plot(series = wtFractalTop ? wt2[2] : na, title = 'WT Bearish Divergence', color = wtBearDivColor, linewidth = 2, offset = -2)
  719.  
  720. plot(series = wtFractalBot ? wt2[2] : na, title = 'WT Bullish Divergence', color = wtBullDivColor, linewidth = 2, offset = -2)
  721.  
  722.  
  723. // WT 2nd Div
  724.  
  725. plot(series = wtFractalTop_add ? wt2[2] : na, title = 'WT 2nd Bearish Divergence', color = wtBearDivColor_add, linewidth = 2, offset = -2)
  726.  
  727. plot(series = wtFractalBot_add ? wt2[2] : na, title = 'WT 2nd Bullish Divergence', color = wtBullDivColor_add, linewidth = 2, offset = -2)
  728.  
  729.  
  730. // RSI
  731.  
  732. plot(rsiShow ? rsi : na, title = 'RSI', color = rsiColor, linewidth = 2, transp = 25)
  733.  
  734.  
  735. // RSI Div
  736.  
  737. plot(series = rsiFractalTop ? rsi[2] : na, title='RSI Bearish Divergence', color = rsiBearDivColor, linewidth = 1, offset = -2)
  738.  
  739. plot(series = rsiFractalBot ? rsi[2] : na, title='RSI Bullish Divergence', color = rsiBullDivColor, linewidth = 1, offset = -2)
  740.  
  741.  
  742. // Stochastic RSI
  743.  
  744. stochKplot = plot(stochShow ? stochK : na, title = 'Stoch K', color = color.new(#21baf3, 0), linewidth = 2)
  745.  
  746. stochDplot = plot(stochShow ? stochD : na, title = 'Stoch D', color = color.new(#673ab7, 60), linewidth = 1)
  747.  
  748. stochFillColor = stochK >= stochD ? color.new(#21baf3, 75) : color.new(#673ab7, 60)
  749.  
  750. fill(stochKplot, stochDplot, title='KD Fill', color=stochFillColor)
  751.  
  752.  
  753. // Stoch Div
  754.  
  755. plot(series = stochFractalTop ? stochK[2] : na, title='Stoch Bearish Divergence', color = stochBearDivColor, linewidth = 1, offset = -2)
  756.  
  757. plot(series = stochFractalBot ? stochK[2] : na, title='Stoch Bullish Divergence', color = stochBullDivColor, linewidth = 1, offset = -2)
  758.  
  759.  
  760. // Schaff Trend Cycle
  761.  
  762. plot(tcLine ? tcVal : na, color = color.new(#673ab7, 25), linewidth = 2, title = "Schaff Trend Cycle 1")
  763.  
  764. plot(tcLine ? tcVal : na, color = color.new(colorWhite, 50), linewidth = 1, title = "Schaff Trend Cycle 2")
  765.  
  766.  
  767.  
  768. // Draw Overbought & Oversold lines
  769.  
  770. //plot(obLevel, title = 'Over Bought Level 1', color = colorWhite, linewidth = 1, style = plot.style_circles, transp = 85)
  771.  
  772. plot(obLevel2, title = 'Over Bought Level 2', color = colorWhite, linewidth = 1, style = plot.style_stepline, transp = 85)
  773.  
  774. plot(obLevel3, title = 'Over Bought Level 3', color = colorWhite, linewidth = 1, style = plot.style_circles, transp = 95)
  775.  
  776.  
  777. //plot(osLevel, title = 'Over Sold Level 1', color = colorWhite, linewidth = 1, style = plot.style_circles, transp = 85)
  778.  
  779. plot(osLevel2, title = 'Over Sold Level 2', color = colorWhite, linewidth = 1, style = plot.style_stepline, transp = 85)
  780.  
  781.  
  782. // Sommi flag
  783.  
  784. plotchar(sommiFlagShow and sommiBearish ? 108 : na, title = 'Sommi bearish flag', char='⚑', color = colorPink, location = location.absolute, size = size.tiny, transp = 0)
  785.  
  786. plotchar(sommiFlagShow and sommiBullish ? -108 : na, title = 'Sommi bullish flag', char='⚑', color = colorBluelight, location = location.absolute, size = size.tiny, transp = 0)
  787.  
  788. plot(sommiShowVwap ? ema(hvwap, 3) : na, title = 'Sommi higher VWAP', color = colorYellow, linewidth = 2, style = plot.style_line, transp = 15)
  789.  
  790.  
  791. // Sommi diamond
  792.  
  793. plotchar(sommiDiamondShow and sommiBearishDiamond ? 108 : na, title = 'Sommi bearish diamond', char='◆', color = colorPink, location = location.absolute, size = size.tiny, transp = 0)
  794.  
  795. plotchar(sommiDiamondShow and sommiBullishDiamond ? -108 : na, title = 'Sommi bullish diamond', char='◆', color = colorBluelight, location = location.absolute, size = size.tiny, transp = 0)
  796.  
  797.  
  798. // Circles
  799.  
  800. plot(wtCross ? wt2 : na, title = 'Buy and sell circle', color = signalColor, style = plot.style_circles, linewidth = 3, transp = 15)
  801.  
  802.  
  803. plotchar(wtBuyShow and buySignal ? -107 : na, title = 'Buy circle', char='·', color = colorGreen, location = location.absolute, size = size.small, transp = 50)
  804.  
  805. plotchar(wtSellShow and sellSignal ? 105 : na , title = 'Sell circle', char='·', color = colorRed, location = location.absolute, size = size.small, transp = 50)
  806.  
  807.  
  808. plotchar(wtDivShow and buySignalDiv ? -106 : na, title = 'Divergence buy circle', char='•', color = buySignalDiv_color, location = location.absolute, size = size.small, offset = -2, transp = 15)
  809.  
  810. plotchar(wtDivShow and sellSignalDiv ? 106 : na, title = 'Divergence sell circle', char='•', color = sellSignalDiv_color, location = location.absolute, size = size.small, offset = -2, transp = 15)
  811.  
  812.  
  813. plotchar(wtGoldBuy and wtGoldShow ? -106 : na, title = 'Gold buy gold circle', char='•', color = colorOrange, location = location.absolute, size = size.small, offset = -2, transp = 15)
  814.  
  815.  
  816. // } DRAW
  817.  
  818.  
  819.  
  820. // ALERTS {
  821.  
  822.  
  823.  
  824. // BUY
  825.  
  826. alertcondition(buySignal, 'Buy (Big green circle)', 'Green circle WaveTrend Oversold')
  827.  
  828. alertcondition(buySignalDiv, 'Buy (Big green circle + Div)', 'Buy & WT Bullish Divergence & WT Overbought')
  829.  
  830. alertcondition(wtGoldBuy, 'GOLD Buy (Big GOLDEN circle)', 'Green & GOLD circle WaveTrend Overbought')
  831.  
  832. alertcondition(sommiBullish or sommiBullishDiamond, 'Sommi bullish flag/diamond', 'Blue flag/diamond')
  833.  
  834.  
  835. // SELL
  836.  
  837. alertcondition(sommiBearish or sommiBearishDiamond, 'Sommi bearish flag/diamond', 'Purple flag/diamond')
  838.  
  839. alertcondition(sellSignal, 'Sell (Big red circle)', 'Red Circle WaveTrend Overbought')
  840.  
  841. alertcondition(sellSignalDiv, 'Sell (Big red circle + Div)', 'Buy & WT Bearish Divergence & WT Overbought')
  842.  
  843.  
  844. // } ALERTS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement