Advertisement
Guest User

Market Cipher Source Code

a guest
Mar 15th, 2021
3,881
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.88 KB | None | 0 0
  1. //@version=4
  2.  
  3. // Implemented ideas based on the analysis of https://marketcipherreview.com <3
  4. // Thanks to falconCoin for https://www.tradingview.com/script/KVfgBvDd-Market-Cipher-B-Free-version-with-Buy-and-sell/ inspired me to start this.
  5. // Thanks to LazyBear for WaveTrend Oscillator https://www.tradingview.com/script/2KE8wTuF-Indicator-WaveTrend-Oscillator-WT/
  6. // Thanks to RicardoSantos for https://www.tradingview.com/script/3oeDh0Yq-RS-Price-Divergence-Detector-V2/
  7. // Thanks to LucemAnb for Plain Stochastic Divergence https://www.tradingview.com/script/FCUgF8ag-Plain-Stochastic-Divergence/
  8. // Thanks to andreholanda73 for MFI+RSI Area https://www.tradingview.com/script/UlGZzUAr/
  9. // I especially thanks to TradingView for its platform that facilitates development and learning.
  10. //
  11. // CIRCLES & TRIANGLES:
  12. // - LITTLE CIRCLE: They appear at all WaveTrend wave crossings.
  13. // - GREEN CIRCLE: The wavetrend waves are at the oversold level and have crossed up (bullish).
  14. // - RED CIRCLE: The wavetrend waves are at the overbought level and have crossed down (bearish).
  15. // - GOLD/ORANGE CIRCLE: When RSI is below 20, WaveTrend waves are below or equal to -80 and have crossed up after good bullish divergence (DONT BUY WHEN GOLD CIRCLE APPEAR).
  16. // - None of these circles are certain signs to trade. It is only information that can help you.
  17. // - PURPLE TRIANGLE: Appear when a bullish or bearish divergence is formed and WaveTrend waves crosses at overbought and oversold points.
  18. //
  19. // NOTES:
  20. // - I am not an expert trader or know how to program pine script as such, in fact it is my first indicator only to study and all the code is copied and modified from other codes that are published in TradingView.
  21. // - I am very grateful to the entire TV community that publishes codes so that other newbies like me can learn and present their results. This is an attempt to imitate Market Cipher B.
  22. // - Settings by default are for 4h timeframe, divergences are more stronger and accurate. Haven't tested in all timeframes, only 2h and 4h.
  23. // - If you get an interesting result in other timeframes I would be very grateful if you would comment your configuration to implement it or at least check it.
  24. //
  25. // CONTRIBUTIONS:
  26. // - User: Sommi
  27. // - Tip/Idea: Add higher timeframe analysis for bearish/bullish patterns at the current timeframe.
  28. // + Bearish/Bullish FLAG:
  29. // - MFI+RSI Area are RED (Below 0).
  30. // - Wavetrend waves are above 0 and crosses down.
  31. // - VWAP Area are below 0 on higher timeframe.
  32. // - This pattern reversed becomes bullish.
  33. // - Tip/Idea: Check the last heikinashi candle from 2 higher timeframe
  34. // + Bearish/Bullish DIAMOND:
  35. // - HT Candle is red
  36. // - WT > 0 and crossed down
  37.  
  38. study(title = 'Agora Algo', shorttitle = 'Agora Algo Market Cipher')
  39.  
  40. // PARAMETERS {
  41.  
  42. // WaveTrend
  43. wtShow = input(true, title = 'Show WaveTrend', type = input.bool)
  44. wtBuyShow = input(true, title = 'Show Buy dots', type = input.bool)
  45. wtGoldShow = input(true, title = 'Show Gold dots', type = input.bool)
  46. wtSellShow = input(true, title = 'Show Sell dots', type = input.bool)
  47. wtDivShow = input(true, title = 'Show Div. dots', type = input.bool)
  48. vwapShow = input(true, title = 'Show Fast WT', type = input.bool)
  49. wtChannelLen = input(9, title = 'WT Channel Length', type = input.integer)
  50. wtAverageLen = input(13, title = 'WT Average Length', type = input.integer)
  51. wtMASource = input(ohlc4, title = 'WT MA Source', type = input.source)
  52. wtMALen = input(3, title = 'WT MA Length', type = input.integer)
  53.  
  54. // WaveTrend Overbought & Oversold lines
  55. obLevel = input(53, title = 'WT Overbought Level 1', type = input.integer)
  56. obLevel2 = input(60, title = 'WT Overbought Level 2', type = input.integer)
  57. obLevel3 = input(100, title = 'WT Overbought Level 3', type = input.integer)
  58. osLevel = input(-53, title = 'WT Oversold Level 1', type = input.integer)
  59. osLevel2 = input(-60, title = 'WT Oversold Level 2', type = input.integer)
  60. osLevel3 = input(-75, title = 'WT Oversold Level 3', type = input.integer)
  61.  
  62. // Divergence WT
  63. wtShowDiv = input(true, title = 'Show WT Regular Divergences', type = input.bool)
  64. wtShowHiddenDiv = input(false, title = 'Show WT Hidden Divergences', type = input.bool)
  65. showHiddenDiv_nl = input(true, title = 'Not apply OB/OS Limits on Hidden Divergences', type = input.bool)
  66. wtDivOBLevel = input(45, title = 'WT Bearish Divergence min', type = input.integer)
  67. wtDivOSLevel = input(-65, title = 'WT Bullish Divergence min', type = input.integer)
  68.  
  69. // Divergence extra range
  70. wtDivOBLevel_addshow = input(true, title = 'Show 2nd WT Regular Divergences', type = input.bool)
  71. wtDivOBLevel_add = input(15, title = 'WT 2nd Bearish Divergence', type = input.integer)
  72. wtDivOSLevel_add = input(-40, title = 'WT 2nd Bullish Divergence 15 min', type = input.integer)
  73.  
  74. // RSI+MFI
  75. rsiMFIShow = input(true, title = 'Show MFI', type = input.bool)
  76. rsiMFIperiod = input(60,title = 'MFI Period', type = input.integer)
  77. rsiMFIMultiplier = input(150, title = 'MFI Area multiplier', type = input.float)
  78. rsiMFIPosY = input(2.5, title = 'MFI Area Y Pos', type = input.float)
  79.  
  80. // RSI
  81. rsiShow = input(false, title = 'Show RSI', type = input.bool)
  82. rsiSRC = input(close, title = 'RSI Source', type = input.source)
  83. rsiLen = input(14, title = 'RSI Length', type = input.integer)
  84. rsiOversold = input(30, title = 'RSI Oversold', minval = 50, maxval = 100, type = input.integer)
  85. rsiOverbought = input(60, title = 'RSI Overbought', minval = 0, maxval = 50, type = input.integer)
  86.  
  87. // Divergence RSI
  88. rsiShowDiv = input(false, title = 'Show RSI Regular Divergences', type = input.bool)
  89. rsiShowHiddenDiv = input(false, title = 'Show RSI Hidden Divergences', type = input.bool)
  90. rsiDivOBLevel = input(60, title = 'RSI Bearish Divergence min', type = input.integer)
  91. rsiDivOSLevel = input(30, title = 'RSI Bullish Divergence min', type = input.integer)
  92.  
  93. // RSI Stochastic
  94. stochShow = input(true, title = 'Show Stochastic RSI', type = input.bool)
  95. stochUseLog = input(true, title=' Use Log?', type = input.bool)
  96. stochAvg = input(false, title='Use Average of both K & D', type = input.bool)
  97. stochSRC = input(close, title = 'Stochastic RSI Source', type = input.source)
  98. stochLen = input(14, title = 'Stochastic RSI Length', type = input.integer)
  99. stochRsiLen = input(14, title = 'RSI Length ', type = input.integer)
  100. stochKSmooth = input(3, title = 'Stochastic RSI K Smooth', type = input.integer)
  101. stochDSmooth = input(3, title = 'Stochastic RSI D Smooth', type = input.integer)
  102.  
  103. // Divergence stoch
  104. stochShowDiv = input(false, title = 'Show Stoch Regular Divergences', type = input.bool)
  105. stochShowHiddenDiv = input(false, title = 'Show Stoch Hidden Divergences', type = input.bool)
  106.  
  107. // Schaff Trend Cycle
  108. tcLine = input(false, title="Show Schaff TC line", type=input.bool)
  109. tcSRC = input(close, title = 'Schaff TC Source', type = input.source)
  110. tclength = input(10, title="Schaff TC", type=input.integer)
  111. tcfastLength = input(23, title="Schaff TC Fast Lenght", type=input.integer)
  112. tcslowLength = input(50, title="Schaff TC Slow Length", type=input.integer)
  113. tcfactor = input(0.5, title="Schaff TC Factor", type=input.float)
  114.  
  115. // Sommi Flag
  116. sommiFlagShow = input(false, title = 'Show Sommi flag', type = input.bool)
  117. sommiShowVwap = input(false, title = 'Show Sommi F. Wave', type = input.bool)
  118. sommiVwapTF = input('720', title = 'Sommi F. Wave timeframe', type = input.string)
  119. sommiVwapBearLevel = input(0, title = 'F. Wave Bear Level (less than)', type = input.integer)
  120. sommiVwapBullLevel = input(0, title = 'F. Wave Bull Level (more than)', type = input.integer)
  121. soomiFlagWTBearLevel = input(0, title = 'WT Bear Level (more than)', type = input.integer)
  122. soomiFlagWTBullLevel = input(0, title = 'WT Bull Level (less than)', type = input.integer)
  123. soomiRSIMFIBearLevel = input(0, title = 'Money flow Bear Level (less than)', type = input.integer)
  124. soomiRSIMFIBullLevel = input(0, title = 'Money flow Bull Level (more than)', type = input.integer)
  125.  
  126. // Sommi Diamond
  127. sommiDiamondShow = input(false, title = 'Show Sommi diamond', type = input.bool)
  128. sommiHTCRes = input('60', title = 'HTF Candle Res. 1', type = input.string)
  129. sommiHTCRes2 = input('240', title = 'HTF Candle Res. 2', type = input.string)
  130. soomiDiamondWTBearLevel = input(0, title = 'WT Bear Level (More than)', type = input.integer)
  131. soomiDiamondWTBullLevel = input(0, title = 'WT Bull Level (Less than)', type = input.integer)
  132.  
  133. // macd Colors
  134. macdWTColorsShow = input(false, title = 'Show MACD Colors', type = input.bool)
  135. macdWTColorsTF = input('240', title = 'MACD Colors MACD TF', type = input.string)
  136.  
  137. darkMode = input(false, title = 'Dark mode', type = input.bool)
  138.  
  139.  
  140. // Colors
  141. colorRed = #ff0000
  142. colorPurple = #e600e6
  143. colorGreen = #3fff00
  144. colorOrange = #e2a400
  145. colorYellow = #ffe500
  146. colorWhite = #ffffff
  147. colorPink = #ff00f0
  148. colorBluelight = #31c0ff
  149.  
  150. colorWT1 = #90caf9
  151. colorWT2 = #0d47a1
  152.  
  153. colorWT2_ = #131722
  154.  
  155. colormacdWT1a = #4caf58
  156. colormacdWT1b = #af4c4c
  157. colormacdWT1c = #7ee57e
  158. colormacdWT1d = #ff3535
  159.  
  160. colormacdWT2a = #305630
  161. colormacdWT2b = #310101
  162. colormacdWT2c = #132213
  163. colormacdWT2d = #770000
  164.  
  165. // } PARAMETERS
  166.  
  167.  
  168. // FUNCTIONS {
  169.  
  170. // Divergences
  171. f_top_fractal(src) => src[4] < src[2] and src[3] < src[2] and src[2] > src[1] and src[2] > src[0]
  172. f_bot_fractal(src) => src[4] > src[2] and src[3] > src[2] and src[2] < src[1] and src[2] < src[0]
  173. f_fractalize(src) => f_top_fractal(src) ? 1 : f_bot_fractal(src) ? -1 : 0
  174.  
  175. f_findDivs(src, topLimit, botLimit, useLimits) =>
  176. fractalTop = f_fractalize(src) > 0 and (useLimits ? src[2] >= topLimit : true) ? src[2] : na
  177. fractalBot = f_fractalize(src) < 0 and (useLimits ? src[2] <= botLimit : true) ? src[2] : na
  178. highPrev = valuewhen(fractalTop, src[2], 0)[2]
  179. highPrice = valuewhen(fractalTop, high[2], 0)[2]
  180. lowPrev = valuewhen(fractalBot, src[2], 0)[2]
  181. lowPrice = valuewhen(fractalBot, low[2], 0)[2]
  182. bearSignal = fractalTop and high[2] > highPrice and src[2] < highPrev
  183. bullSignal = fractalBot and low[2] < lowPrice and src[2] > lowPrev
  184. bearDivHidden = fractalTop and high[2] < highPrice and src[2] > highPrev
  185. bullDivHidden = fractalBot and low[2] > lowPrice and src[2] < lowPrev
  186. [fractalTop, fractalBot, lowPrev, bearSignal, bullSignal, bearDivHidden, bullDivHidden]
  187.  
  188. // RSI+MFI
  189. f_rsimfi(_period, _multiplier, _tf) => security(syminfo.tickerid, _tf, sma(((close - open) / (high - low)) * _multiplier, _period) - rsiMFIPosY)
  190.  
  191. // WaveTrend
  192. f_wavetrend(src, chlen, avg, malen, tf) =>
  193. tfsrc = security(syminfo.tickerid, tf, src)
  194. esa = ema(tfsrc, chlen)
  195. de = ema(abs(tfsrc - esa), chlen)
  196. ci = (tfsrc - esa) / (0.015 * de)
  197. wt1 = security(syminfo.tickerid, tf, ema(ci, avg))
  198. wt2 = security(syminfo.tickerid, tf, sma(wt1, malen))
  199. wtVwap = wt1 - wt2
  200. wtOversold = wt2 <= osLevel
  201. wtOverbought = wt2 >= obLevel
  202. wtCross = cross(wt1, wt2)
  203. wtCrossUp = wt2 - wt1 <= 0
  204. wtCrossDown = wt2 - wt1 >= 0
  205. wtCrosslast = cross(wt1[2], wt2[2])
  206. wtCrossUplast = wt2[2] - wt1[2] <= 0
  207. wtCrossDownlast = wt2[2] - wt1[2] >= 0
  208. [wt1, wt2, wtOversold, wtOverbought, wtCross, wtCrossUp, wtCrossDown, wtCrosslast, wtCrossUplast, wtCrossDownlast, wtVwap]
  209.  
  210. // Schaff Trend Cycle
  211. f_tc(src, length, fastLength, slowLength) =>
  212. ema1 = ema(src, fastLength)
  213. ema2 = ema(src, slowLength)
  214. macdVal = ema1 - ema2
  215. alpha = lowest(macdVal, length)
  216. beta = highest(macdVal, length) - alpha
  217. gamma = (macdVal - alpha) / beta * 100
  218. gamma := beta > 0 ? gamma : nz(gamma[1])
  219. delta = gamma
  220. delta := na(delta[1]) ? delta : delta[1] + tcfactor * (gamma - delta[1])
  221. epsilon = lowest(delta, length)
  222. zeta = highest(delta, length) - epsilon
  223. eta = (delta - epsilon) / zeta * 100
  224. eta := zeta > 0 ? eta : nz(eta[1])
  225. stcReturn = eta
  226. stcReturn := na(stcReturn[1]) ? stcReturn : stcReturn[1] + tcfactor * (eta - stcReturn[1])
  227. stcReturn
  228.  
  229. // Stochastic RSI
  230. f_stochrsi(_src, _stochlen, _rsilen, _smoothk, _smoothd, _log, _avg) =>
  231. src = _log ? log(_src) : _src
  232. rsi = rsi(src, _rsilen)
  233. kk = sma(stoch(rsi, rsi, rsi, _stochlen), _smoothk)
  234. d1 = sma(kk, _smoothd)
  235. avg_1 = avg(kk, d1)
  236. k = _avg ? avg_1 : kk
  237. [k, d1]
  238.  
  239. // MACD
  240. f_macd(src, fastlen, slowlen, sigsmooth, tf) =>
  241. fast_ma = security(syminfo.tickerid, tf, ema(src, fastlen))
  242. slow_ma = security(syminfo.tickerid, tf, ema(src, slowlen))
  243. macd = fast_ma - slow_ma,
  244. signal = security(syminfo.tickerid, tf, sma(macd, sigsmooth))
  245. hist = macd - signal
  246. [macd, signal, hist]
  247.  
  248. // MACD Colors on WT
  249. f_macdWTColors(tf) =>
  250. hrsimfi = f_rsimfi(rsiMFIperiod, rsiMFIMultiplier, tf)
  251. [macd, signal, hist] = f_macd(close, 28, 42, 9, macdWTColorsTF)
  252. macdup = macd >= signal
  253. macddown = macd <= signal
  254. macdWT1Color = macdup ? hrsimfi > 0 ? colormacdWT1c : colormacdWT1a : macddown ? hrsimfi < 0 ? colormacdWT1d : colormacdWT1b : na
  255. macdWT2Color = macdup ? hrsimfi < 0 ? colormacdWT2c : colormacdWT2a : macddown ? hrsimfi < 0 ? colormacdWT2d : colormacdWT2b : na
  256. [macdWT1Color, macdWT2Color]
  257.  
  258. // Get higher timeframe candle
  259. f_getTFCandle(_tf) =>
  260. _open = security(heikinashi(syminfo.tickerid), _tf, open, barmerge.gaps_off, barmerge.lookahead_on)
  261. _close = security(heikinashi(syminfo.tickerid), _tf, close, barmerge.gaps_off, barmerge.lookahead_on)
  262. _high = security(heikinashi(syminfo.tickerid), _tf, high, barmerge.gaps_off, barmerge.lookahead_on)
  263. _low = security(heikinashi(syminfo.tickerid), _tf, low, barmerge.gaps_off, barmerge.lookahead_on)
  264. hl2 = (_high + _low) / 2.0
  265. newBar = change(_open)
  266. candleBodyDir = _close > _open
  267. [candleBodyDir, newBar]
  268.  
  269. // Sommi flag
  270. f_findSommiFlag(tf, wt1, wt2, rsimfi, wtCross, wtCrossUp, wtCrossDown) =>
  271. [hwt1, hwt2, hwtOversold, hwtOverbought, hwtCross, hwtCrossUp, hwtCrossDown, hwtCrosslast, hwtCrossUplast, hwtCrossDownlast, hwtVwap] = f_wavetrend(wtMASource, wtChannelLen, wtAverageLen, wtMALen, tf)
  272.  
  273. bearPattern = rsimfi < soomiRSIMFIBearLevel and
  274. wt2 > soomiFlagWTBearLevel and
  275. wtCross and
  276. wtCrossDown and
  277. hwtVwap < sommiVwapBearLevel
  278.  
  279. bullPattern = rsimfi > soomiRSIMFIBullLevel and
  280. wt2 < soomiFlagWTBullLevel and
  281. wtCross and
  282. wtCrossUp and
  283. hwtVwap > sommiVwapBullLevel
  284.  
  285. [bearPattern, bullPattern, hwtVwap]
  286.  
  287. f_findSommiDiamond(tf, tf2, wt1, wt2, wtCross, wtCrossUp, wtCrossDown) =>
  288. [candleBodyDir, newBar] = f_getTFCandle(tf)
  289. [candleBodyDir2, newBar2] = f_getTFCandle(tf2)
  290. bearPattern = wt2 >= soomiDiamondWTBearLevel and
  291. wtCross and
  292. wtCrossDown and
  293. not candleBodyDir and
  294. not candleBodyDir2
  295. bullPattern = wt2 <= soomiDiamondWTBullLevel and
  296. wtCross and
  297. wtCrossUp and
  298. candleBodyDir and
  299. candleBodyDir2
  300. [bearPattern, bullPattern]
  301.  
  302. // } FUNCTIONS
  303.  
  304. // CALCULATE INDICATORS {
  305.  
  306. // RSI
  307. rsi = rsi(rsiSRC, rsiLen)
  308. rsiColor = rsi <= rsiOversold ? colorGreen : rsi >= rsiOverbought ? colorRed : colorPurple
  309.  
  310. // RSI + MFI Area
  311. rsiMFI = f_rsimfi(rsiMFIperiod, rsiMFIMultiplier, timeframe.period)
  312. rsiMFIColor = rsiMFI > 0 ? #3ee145 : #ff3d2e
  313.  
  314. // Calculates WaveTrend
  315. [wt1, wt2, wtOversold, wtOverbought, wtCross, wtCrossUp, wtCrossDown, wtCross_last, wtCrossUp_last, wtCrossDown_last, wtVwap] = f_wavetrend(wtMASource, wtChannelLen, wtAverageLen, wtMALen, timeframe.period)
  316.  
  317. // Stochastic RSI
  318. [stochK, stochD] = f_stochrsi(stochSRC, stochLen, stochRsiLen, stochKSmooth, stochDSmooth, stochUseLog, stochAvg)
  319.  
  320. // Schaff Trend Cycle
  321. tcVal = f_tc(tcSRC, tclength, tcfastLength, tcslowLength)
  322.  
  323. // Sommi flag
  324. [sommiBearish, sommiBullish, hvwap] = f_findSommiFlag(sommiVwapTF, wt1, wt2, rsiMFI, wtCross, wtCrossUp, wtCrossDown)
  325.  
  326. //Sommi diamond
  327. [sommiBearishDiamond, sommiBullishDiamond] = f_findSommiDiamond(sommiHTCRes, sommiHTCRes2, wt1, wt2, wtCross, wtCrossUp, wtCrossDown)
  328.  
  329. // macd colors
  330. [macdWT1Color, macdWT2Color] = f_macdWTColors(macdWTColorsTF)
  331.  
  332. // WT Divergences
  333. [wtFractalTop, wtFractalBot, wtLow_prev, wtBearDiv, wtBullDiv, wtBearDivHidden, wtBullDivHidden] = f_findDivs(wt2, wtDivOBLevel, wtDivOSLevel, true)
  334.  
  335. [wtFractalTop_add, wtFractalBot_add, wtLow_prev_add, wtBearDiv_add, wtBullDiv_add, wtBearDivHidden_add, wtBullDivHidden_add] = f_findDivs(wt2, wtDivOBLevel_add, wtDivOSLevel_add, true)
  336. [wtFractalTop_nl, wtFractalBot_nl, wtLow_prev_nl, wtBearDiv_nl, wtBullDiv_nl, wtBearDivHidden_nl, wtBullDivHidden_nl] = f_findDivs(wt2, 0, 0, false)
  337.  
  338. wtBearDivHidden_ = showHiddenDiv_nl ? wtBearDivHidden_nl : wtBearDivHidden
  339. wtBullDivHidden_ = showHiddenDiv_nl ? wtBullDivHidden_nl : wtBullDivHidden
  340.  
  341. wtBearDivColor = (wtShowDiv and wtBearDiv) or (wtShowHiddenDiv and wtBearDivHidden_) ? colorRed : na
  342. wtBullDivColor = (wtShowDiv and wtBullDiv) or (wtShowHiddenDiv and wtBullDivHidden_) ? colorGreen : na
  343.  
  344. wtBearDivColor_add = (wtShowDiv and (wtDivOBLevel_addshow and wtBearDiv_add)) or (wtShowHiddenDiv and (wtDivOBLevel_addshow and wtBearDivHidden_add)) ? #9a0202 : na
  345. wtBullDivColor_add = (wtShowDiv and (wtDivOBLevel_addshow and wtBullDiv_add)) or (wtShowHiddenDiv and (wtDivOBLevel_addshow and wtBullDivHidden_add)) ? #1b5e20 : na
  346.  
  347. // RSI Divergences
  348. [rsiFractalTop, rsiFractalBot, rsiLow_prev, rsiBearDiv, rsiBullDiv, rsiBearDivHidden, rsiBullDivHidden] = f_findDivs(rsi, rsiDivOBLevel, rsiDivOSLevel, true)
  349. [rsiFractalTop_nl, rsiFractalBot_nl, rsiLow_prev_nl, rsiBearDiv_nl, rsiBullDiv_nl, rsiBearDivHidden_nl, rsiBullDivHidden_nl] = f_findDivs(rsi, 0, 0, false)
  350.  
  351. rsiBearDivHidden_ = showHiddenDiv_nl ? rsiBearDivHidden_nl : rsiBearDivHidden
  352. rsiBullDivHidden_ = showHiddenDiv_nl ? rsiBullDivHidden_nl : rsiBullDivHidden
  353.  
  354. rsiBearDivColor = (rsiShowDiv and rsiBearDiv) or (rsiShowHiddenDiv and rsiBearDivHidden_) ? colorRed : na
  355. rsiBullDivColor = (rsiShowDiv and rsiBullDiv) or (rsiShowHiddenDiv and rsiBullDivHidden_) ? colorGreen : na
  356.  
  357. // Stoch Divergences
  358. [stochFractalTop, stochFractalBot, stochLow_prev, stochBearDiv, stochBullDiv, stochBearDivHidden, stochBullDivHidden] = f_findDivs(stochK, 0, 0, false)
  359.  
  360. stochBearDivColor = (stochShowDiv and stochBearDiv) or (stochShowHiddenDiv and stochBearDivHidden) ? colorRed : na
  361. stochBullDivColor = (stochShowDiv and stochBullDiv) or (stochShowHiddenDiv and stochBullDivHidden) ? colorGreen : na
  362.  
  363.  
  364. // Small Circles WT Cross
  365. signalColor = wt2 - wt1 > 0 ? color.red : color.lime
  366.  
  367. // Buy signal.
  368. buySignal = wtCross and wtCrossUp and wtOversold
  369.  
  370. buySignalDiv = (wtShowDiv and wtBullDiv) or
  371. (wtShowDiv and wtBullDiv_add) or
  372. (stochShowDiv and stochBullDiv) or
  373. (rsiShowDiv and rsiBullDiv)
  374.  
  375. buySignalDiv_color = wtBullDiv ? colorGreen :
  376. wtBullDiv_add ? color.new(colorGreen, 60) :
  377. rsiShowDiv ? colorGreen : na
  378.  
  379. // Sell signal
  380. sellSignal = wtCross and wtCrossDown and wtOverbought
  381.  
  382. sellSignalDiv = (wtShowDiv and wtBearDiv) or
  383. (wtShowDiv and wtBearDiv_add) or
  384. (stochShowDiv and stochBearDiv) or
  385. (rsiShowDiv and rsiBearDiv)
  386.  
  387. sellSignalDiv_color = wtBearDiv ? colorRed :
  388. wtBearDiv_add ? color.new(colorRed, 60) :
  389. rsiBearDiv ? colorRed : na
  390.  
  391. // Gold Buy
  392. lastRsi = valuewhen(wtFractalBot, rsi[2], 0)[2]
  393. wtGoldBuy = ((wtShowDiv and wtBullDiv) or (rsiShowDiv and rsiBullDiv)) and
  394. wtLow_prev <= osLevel3 and
  395. wt2 > osLevel3 and
  396. wtLow_prev - wt2 <= -5 and
  397. lastRsi < 30
  398.  
  399. // } CALCULATE INDICATORS
  400.  
  401.  
  402. // DRAW {
  403. bgcolor(darkMode ? color.new(#000000, 80) : na)
  404. zLine = plot(0, color = color.new(colorWhite, 50))
  405.  
  406. // MFI BAR
  407. rsiMfiBarTopLine = plot(rsiMFIShow ? -95 : na, title = 'MFI Bar TOP Line', transp = 100)
  408. rsiMfiBarBottomLine = plot(rsiMFIShow ? -99 : na, title = 'MFI Bar BOTTOM Line', transp = 100)
  409. fill(rsiMfiBarTopLine, rsiMfiBarBottomLine, title = 'MFI Bar Colors', color = rsiMFIColor, transp = 75)
  410.  
  411. // WT Areas
  412. plot(wtShow ? wt1 : na, style = plot.style_area, title = 'WT Wave 1', color = macdWTColorsShow ? macdWT1Color : colorWT1, transp = 0)
  413. plot(wtShow ? wt2 : na, style = plot.style_area, title = 'WT Wave 2', color = macdWTColorsShow ? macdWT2Color : darkMode ? colorWT2_ : colorWT2 , transp = 20)
  414.  
  415. // VWAP
  416. plot(vwapShow ? wtVwap : na, title = 'VWAP', color = colorYellow, style = plot.style_area, linewidth = 2, transp = 45)
  417.  
  418. // MFI AREA
  419. rsiMFIplot = plot(rsiMFIShow ? rsiMFI: na, title = 'RSI+MFI Area', color = rsiMFIColor, transp = 20)
  420. fill(rsiMFIplot, zLine, rsiMFIColor, transp = 40)
  421.  
  422. // WT Div
  423.  
  424. plot(series = wtFractalTop ? wt2[2] : na, title = 'WT Bearish Divergence', color = wtBearDivColor, linewidth = 2, offset = -2)
  425. plot(series = wtFractalBot ? wt2[2] : na, title = 'WT Bullish Divergence', color = wtBullDivColor, linewidth = 2, offset = -2)
  426.  
  427. // WT 2nd Div
  428. plot(series = wtFractalTop_add ? wt2[2] : na, title = 'WT 2nd Bearish Divergence', color = wtBearDivColor_add, linewidth = 2, offset = -2)
  429. plot(series = wtFractalBot_add ? wt2[2] : na, title = 'WT 2nd Bullish Divergence', color = wtBullDivColor_add, linewidth = 2, offset = -2)
  430.  
  431. // RSI
  432. plot(rsiShow ? rsi : na, title = 'RSI', color = rsiColor, linewidth = 2, transp = 25)
  433.  
  434. // RSI Div
  435. plot(series = rsiFractalTop ? rsi[2] : na, title='RSI Bearish Divergence', color = rsiBearDivColor, linewidth = 1, offset = -2)
  436. plot(series = rsiFractalBot ? rsi[2] : na, title='RSI Bullish Divergence', color = rsiBullDivColor, linewidth = 1, offset = -2)
  437.  
  438. // Stochastic RSI
  439. stochKplot = plot(stochShow ? stochK : na, title = 'Stoch K', color = color.new(#21baf3, 0), linewidth = 2)
  440. stochDplot = plot(stochShow ? stochD : na, title = 'Stoch D', color = color.new(#673ab7, 60), linewidth = 1)
  441. stochFillColor = stochK >= stochD ? color.new(#21baf3, 75) : color.new(#673ab7, 60)
  442. fill(stochKplot, stochDplot, title='KD Fill', color=stochFillColor)
  443.  
  444. // Stoch Div
  445. plot(series = stochFractalTop ? stochK[2] : na, title='Stoch Bearish Divergence', color = stochBearDivColor, linewidth = 1, offset = -2)
  446. plot(series = stochFractalBot ? stochK[2] : na, title='Stoch Bullish Divergence', color = stochBullDivColor, linewidth = 1, offset = -2)
  447.  
  448. // Schaff Trend Cycle
  449. plot(tcLine ? tcVal : na, color = color.new(#673ab7, 25), linewidth = 2, title = "Schaff Trend Cycle 1")
  450. plot(tcLine ? tcVal : na, color = color.new(colorWhite, 50), linewidth = 1, title = "Schaff Trend Cycle 2")
  451.  
  452.  
  453. // Draw Overbought & Oversold lines
  454. //plot(obLevel, title = 'Over Bought Level 1', color = colorWhite, linewidth = 1, style = plot.style_circles, transp = 85)
  455. plot(obLevel2, title = 'Over Bought Level 2', color = colorWhite, linewidth = 1, style = plot.style_stepline, transp = 85)
  456. plot(obLevel3, title = 'Over Bought Level 3', color = colorWhite, linewidth = 1, style = plot.style_circles, transp = 95)
  457.  
  458. //plot(osLevel, title = 'Over Sold Level 1', color = colorWhite, linewidth = 1, style = plot.style_circles, transp = 85)
  459. plot(osLevel2, title = 'Over Sold Level 2', color = colorWhite, linewidth = 1, style = plot.style_stepline, transp = 85)
  460.  
  461. // Sommi flag
  462. plotchar(sommiFlagShow and sommiBearish ? 108 : na, title = 'Sommi bearish flag', char='⚑', color = colorPink, location = location.absolute, size = size.tiny, transp = 0)
  463. plotchar(sommiFlagShow and sommiBullish ? -108 : na, title = 'Sommi bullish flag', char='⚑', color = colorBluelight, location = location.absolute, size = size.tiny, transp = 0)
  464. plot(sommiShowVwap ? ema(hvwap, 3) : na, title = 'Sommi higher VWAP', color = colorYellow, linewidth = 2, style = plot.style_line, transp = 15)
  465.  
  466. // Sommi diamond
  467. plotchar(sommiDiamondShow and sommiBearishDiamond ? 108 : na, title = 'Sommi bearish diamond', char='◆', color = colorPink, location = location.absolute, size = size.tiny, transp = 0)
  468. plotchar(sommiDiamondShow and sommiBullishDiamond ? -108 : na, title = 'Sommi bullish diamond', char='◆', color = colorBluelight, location = location.absolute, size = size.tiny, transp = 0)
  469.  
  470. // Circles
  471. plot(wtCross ? wt2 : na, title = 'Buy and sell circle', color = signalColor, style = plot.style_circles, linewidth = 3, transp = 15)
  472.  
  473. plotchar(wtBuyShow and buySignal ? -107 : na, title = 'Buy circle', char='·', color = colorGreen, location = location.absolute, size = size.small, transp = 50)
  474. plotchar(wtSellShow and sellSignal ? 105 : na , title = 'Sell circle', char='·', color = colorRed, location = location.absolute, size = size.small, transp = 50)
  475.  
  476. plotchar(wtDivShow and buySignalDiv ? -106 : na, title = 'Divergence buy circle', char='•', color = buySignalDiv_color, location = location.absolute, size = size.small, offset = -2, transp = 15)
  477. plotchar(wtDivShow and sellSignalDiv ? 106 : na, title = 'Divergence sell circle', char='•', color = sellSignalDiv_color, location = location.absolute, size = size.small, offset = -2, transp = 15)
  478.  
  479. plotchar(wtGoldBuy and wtGoldShow ? -106 : na, title = 'Gold buy gold circle', char='•', color = colorOrange, location = location.absolute, size = size.small, offset = -2, transp = 15)
  480.  
  481. // } DRAW
  482.  
  483.  
  484. // ALERTS {
  485.  
  486. // BUY
  487. alertcondition(buySignal, 'Buy (Big green circle)', 'Green circle WaveTrend Oversold')
  488. alertcondition(buySignalDiv, 'Buy (Big green circle + Div)', 'Buy & WT Bullish Divergence & WT Overbought')
  489. alertcondition(wtGoldBuy, 'GOLD Buy (Big GOLDEN circle)', 'Green & GOLD circle WaveTrend Overbought')
  490. alertcondition(sommiBullish or sommiBullishDiamond, 'Sommi bullish flag/diamond', 'Blue flag/diamond')
  491.  
  492. // SELL
  493. alertcondition(sommiBearish or sommiBearishDiamond, 'Sommi bearish flag/diamond', 'Purple flag/diamond')
  494. alertcondition(sellSignal, 'Sell (Big red circle)', 'Red Circle WaveTrend Overbought')
  495. alertcondition(sellSignalDiv, 'Sell (Big red circle + Div)', 'Buy & WT Bearish Divergence & WT Overbought')
  496.  
  497. // } ALERTS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement