sygma1982

Untitled

Apr 2nd, 2023 (edited)
138
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ActionScript 65.02 KB | Cryptocurrency | 0 0
  1. //@version=5
  2. strategy("Crypto_Wolf_Traders_V4.1", overlay=true, max_labels_count=500, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, initial_capital = 100)
  3. ///////////////////////////////////////////////////////////////////////////////
  4. //-----------------------------CRYPTO-WOLF-TRADERS----------------------------------//
  5. ///////////////////////////////////////////////////////////////////////////////
  6. // SIGNAL MEANINGS
  7. //"Buy Label" = Strong Buy
  8. //"Sell Label" = Strong Sell
  9. //"Don't Long" = Green Cross
  10. //"Don't Short" = Red Cross
  11. //"Weak Buy " = Green Circle
  12. //"Weak Sell" = Red Circle
  13. //"Reversal Buy" = Green Diamond
  14. //"Reversal Sell" = Red Diamond
  15.  
  16. // Get user settings
  17. res               = input.timeframe(title='TIMEFRAME', defval='15', group ="NON REPAINT")
  18. showBuySell       = input(true, "BUY/SELL SIGNALS ON/OFF", group="BUY & SELL SIGNALS")
  19. sensitivity       = input.float(2.07, "SENSITIVITY (1-6)", 0.1, 6, group="BUY & SELL SIGNALS")
  20. percentStop       = input.float(1, "STOP LOSS % (0 TO DISABLE)", 0, group="BUY & SELL SIGNALS")
  21. offsetSignal      = input.float(2, "SIGNAL OFFSET", 0, group="BUY & SELL SIGNALS")
  22. showReversal      = input(true, "REVERSAL SIGNALS ON/OFF", group="BUY & SELL SIGNALS")
  23. // Entry & Exit
  24. enableE           = input(true, "EXIT & ENTRY ON/OFF", group="EXIT & ENTRY")
  25. Stop              = input.color(color.new(#83868f, 5), "STOP LOSS", group="EXIT & ENTRY")
  26. Entry             = input.color(color.new(#8d020e, 5), "ENTRY", group="EXIT & ENTRY")
  27. Tp1               = input.color(color.new(#038007, 5), "TAKE PROFIT", group="EXIT & ENTRY")
  28. // Supply & Demand
  29. enableSD          = input(true, "SUPPLY & DEMAND ON/OFF", group="SUPPLY & DEMAND")
  30. mitigation        = input.string('Wick', 'MITIGATION', options = ['Wick', 'Close'], group ="SUPPLY & DEMAND")
  31. length            = input.int(20, 'VOLUME PIVOT', minval = 1, group ="SUPPLY & DEMAND")
  32. bull_ext_last     = input.int(1, 'DEMAND', minval = 1, inline = 'bull', group ="SUPPLY & DEMAND")
  33. bull_avg_css      = input.color(color.new(#019106, 1), '', inline = 'bull', group ="SUPPLY & DEMAND")
  34. bull_css          = input.color(color.new(#00000000, 100), '', inline = 'bull', group ="SUPPLY & DEMAND")
  35. bg_bull_css       = input.color(color.new(#00ff0a, 90), '', inline = 'bull', group ="SUPPLY & DEMAND")
  36. bear_ext_last     = input.int(1, 'SUPPLY', minval = 1 , inline = 'bear', group ="SUPPLY & DEMAND")
  37. bear_avg_css      = input.color(color.new(#86020d, 1), '', inline = 'bear', group ="SUPPLY & DEMAND")
  38. bear_css          = input.color(color.new(#00000000, 100), '', inline = 'bear', group ="SUPPLY & DEMAND")
  39. bg_bear_css       = input.color(color.new(#ff0015, 90), '', inline = 'bear', group ="SUPPLY & DEMAND")
  40. line_style        = input.string("Solid", "LINE STYLE", ["Solid", "Dotted", "Dashed"], group ="SUPPLY & DEMAND")
  41. line_width        = input.int(2, 'LINE WIDTH', minval = 1, group ="SUPPLY & DEMAND")
  42. // Support & Resistance
  43. enableSR          = input(true, "SUPPORT & RESISTANCE ON/Off", group="SUPPORT & RESISTANCE")
  44. colorSup          = input(#00dbff, "SUPPORT", group="SUPPORT & RESISTANCE")
  45. colorRes          = input(#E91E63, "RESISTANCE", group="SUPPORT & RESISTANCE")
  46. strengthSR        = input.int(6, "S/R STRENGTH", 1, group="SUPPORT & RESISTANCE")
  47. lineStyle1        = input.string("Solid", "LINE STYLE", ["Solid", "Dotted", "Dashed"], group="SUPPORT & RESISTANCE")
  48. lineWidth1        = input.int(2, "LINE WIDTH", 1, group="SUPPORT & RESISTANCE")
  49. expandSR          = input(true, "EXTEND LINES", group = "SUPPORT & RESISTANCE")
  50. useZones          = input(true, "ZONE ON/OFF", group="SUPPORT & RESISTANCE")
  51. useHLZones        = input(true, "HIGH LOW ZONES ON/OFF", group="SUPPORT & RESISTANCE")
  52. zoneWidth         = input.int(4, "ZONE WIDTH %", 0, tooltip="it's calculated using % of the distance between highest/lowest in last 300 bars", group="SUPPORT & RESISTANCE")
  53. // Trend Table
  54. showDashboard     = input(false, "TREND DASHBOARD ON/OFF", group="TREND DASHBOARD")
  55. locationDashboard = input.string("Middle Right", "Table Location", ["Top Right", "Middle Right", "Bottom Right", "Top Center", "Middle Center", "Bottom Center", "Top Left", "Middle Left", "Bottom Left"], group="TREND DASHBOARD")
  56. tableTextColor    = input(color.rgb(236, 233, 233), "TEXT", group="TREND DASHBOARD")
  57. tableBgColor      = input(color.black, "BACKGROUND", group="TREND DASHBOARD")
  58. sizeDashboard     = input.string("Small", "TABLE SIZE", ["Large", "Normal", "Small", "Tiny"], group="TREND DASHBOARD")
  59. showPdHlc         = input(false, "PREVIOUS DAY H/L/C", group="PREVIOUS DAY HIGH LOW CLOSE")
  60. lineColor         = input.color(#028a07, "LINE COLORS", group="PREVIOUS DAY HIGH LOW CLOSE")
  61. lineStyle         = input.string("Solid", "LINE STYLE", ["Solid", "Dotted", "Dashed"], group ="PREVIOUS DAY HIGH LOW CLOSE")
  62. lineWidth         = input.int(1, "LINE WIDTH", group="PREVIOUS DAY HIGH LOW CLOSE")
  63.  
  64. // Create non-repainting security function
  65. rp_security(_symbol, _res, _src) =>
  66.     request.security(_symbol, _res, _src[barstate.isrealtime ? 1 : 0])
  67.  
  68. htfHigh = rp_security(syminfo.tickerid, res, high)
  69. htfLow = rp_security(syminfo.tickerid, res, low)
  70.  
  71. // Main Indicator
  72. // Functions
  73. smoothrng(x, t, m) =>
  74.     wper = t * 2 - 1
  75.     avrng = ta.ema(math.abs(x - x[1]), t)
  76.     smoothrng = ta.ema(avrng, wper) * m
  77. rngfilt(x, r) =>
  78.     rngfilt = x
  79.     rngfilt := x > nz(rngfilt[1]) ? x - r < nz(rngfilt[1]) ? nz(rngfilt[1]) : x - r : x + r > nz(rngfilt[1]) ? nz(rngfilt[1]) : x + r
  80. percWidth(len, perc) => (ta.highest(len) - ta.lowest(len)) * perc / 100
  81. securityNoRep(sym, res, src) => request.security(sym, res, src, barmerge.gaps_off, barmerge.lookahead_on)
  82. swingPoints(prd) =>
  83.     pivHi = ta.pivothigh(prd, prd)
  84.     pivLo = ta.pivotlow (prd, prd)
  85.     last_pivHi = ta.valuewhen(pivHi, pivHi, 1)
  86.     last_pivLo = ta.valuewhen(pivLo, pivLo, 1)
  87.     hh = pivHi and pivHi > last_pivHi ? pivHi : na
  88.     lh = pivHi and pivHi < last_pivHi ? pivHi : na
  89.     hl = pivLo and pivLo > last_pivLo ? pivLo : na
  90.     ll = pivLo and pivLo < last_pivLo ? pivLo : na
  91.     [hh, lh, hl, ll]
  92. f_chartTfInMinutes() =>
  93.     float _resInMinutes = timeframe.multiplier * (
  94.       timeframe.isseconds ? 1                   :
  95.       timeframe.isminutes ? 1.                  :
  96.       timeframe.isdaily   ? 60. * 24            :
  97.       timeframe.isweekly  ? 60. * 24 * 7        :
  98.       timeframe.ismonthly ? 60. * 24 * 30.4375  : na)
  99. f_kc(src, len, sensitivity) =>
  100.     basis = ta.sma(src, len)
  101.     span  = ta.atr(len)
  102.     [basis + span * sensitivity, basis - span * sensitivity]
  103. wavetrend(src, chlLen, avgLen) =>
  104.     esa = ta.ema(src, chlLen)
  105.     d = ta.ema(math.abs(src - esa), chlLen)
  106.     ci = (src - esa) / (0.015 * d)
  107.     wt1 = ta.ema(ci, avgLen)
  108.     wt2 = ta.sma(wt1, 3)
  109.     [wt1, wt2]
  110. f_top_fractal(src) => src[4] < src[2] and src[3] < src[2] and src[2] > src[1] and src[2] > src[0]
  111. f_bot_fractal(src) => src[4] > src[2] and src[3] > src[2] and src[2] < src[1] and src[2] < src[0]
  112. f_fractalize (src) => f_top_fractal(src) ? 1 : f_bot_fractal(src) ? -1 : 0
  113. f_findDivs(src, topLimit, botLimit) =>
  114.     fractalTop = f_fractalize(src) > 0 and src[2] >= topLimit ? src[2] : na
  115.     fractalBot = f_fractalize(src) < 0 and src[2] <= botLimit ? src[2] : na
  116.     highPrev = ta.valuewhen(fractalTop, src[2], 0)[2]
  117.     highPrice = ta.valuewhen(fractalTop, high[2], 0)[2]
  118.     lowPrev = ta.valuewhen(fractalBot, src[2], 0)[2]
  119.     lowPrice = ta.valuewhen(fractalBot, low[2], 0)[2]
  120.     bearSignal = fractalTop and high[1] > highPrice and src[1] < highPrev
  121.     bullSignal = fractalBot and low[1] < lowPrice and src[1] > lowPrev
  122.     [bearSignal, bullSignal]
  123.  
  124. // Get components
  125. source    = input(close, title = "Smoothring Source", group = "Smoothing")
  126. smrng1_input= input.int(32, "Smring1", 1, 100 , 1 , group = "Smoothing")
  127. smrng1_sens = input.float(defval = 2.07,title = "sens",minval = 0.1, maxval = 5 , step = 0.01 , group = "Smoothing")
  128. smrng2_input= input.int(50, "Smring2", 1, 100 , 1 , group = "Smoothing")
  129. smrng1    = smoothrng(source, smrng1_input, smrng1_sens)
  130. smrng2    = smoothrng(source, smrng2_input, sensitivity)
  131. smrng     = (smrng1 + smrng2) / 2
  132. filt      = rngfilt(source, smrng)
  133. up        = 0.0, up := filt > filt[1] ? nz(up[1]) + 1 : filt < filt[1] ? 0 : nz(up[1])
  134. dn        = 0.0, dn := filt < filt[1] ? nz(dn[1]) + 1 : filt > filt[1] ? 0 : nz(dn[1])
  135. bullCond  = bool(na), bullCond := source > filt and source > source[1] and up > 0 or source > filt and source < source[1] and up > 0
  136. bearCond  = bool(na), bearCond := source < filt and source < source[1] and dn > 0 or source < filt and source > source[1] and dn > 0
  137. lastCond  = 0, lastCond := bullCond ? 1 : bearCond ? -1 : lastCond[1]
  138. bull      = bullCond and lastCond[1] == -1
  139. bear      = bearCond and lastCond[1] == 1
  140. countBull = ta.barssince(bull)
  141. countBear = ta.barssince(bear)
  142. trigger   = nz(countBull, bar_index) < nz(countBear, bar_index) ? 1 : 0
  143. rsi       = ta.rsi(close, 28)
  144. rsiOb     = rsi > 78 and rsi > ta.ema(rsi, 10)
  145. rsiOs     = rsi < 27 and rsi < ta.ema(rsi, 10)
  146. dHigh     = securityNoRep(syminfo.tickerid, "D", high [1])
  147. dLow      = securityNoRep(syminfo.tickerid, "D", low  [1])
  148. dClose    = securityNoRep(syminfo.tickerid, "D", close[1])
  149. ema = ta.ema(close, 144)
  150. emaBull = close > ema
  151. equal_tf(res) => str.tonumber(res) == f_chartTfInMinutes() and not timeframe.isseconds
  152. higher_tf(res) => str.tonumber(res) > f_chartTfInMinutes() or timeframe.isseconds
  153. too_small_tf(res) => (timeframe.isweekly and res=="1") or (timeframe.ismonthly and str.tonumber(res) < 10)
  154. securityNoRep1(sym, res, src) =>
  155.     bool bull_ = na
  156.     bull_ := equal_tf(res) ? src : bull_
  157.     bull_ := higher_tf(res) ? request.security(sym, res, src, barmerge.gaps_off, barmerge.lookahead_on) : bull_
  158.     bull_array = request.security_lower_tf(syminfo.tickerid, higher_tf(res) ? str.tostring(f_chartTfInMinutes()) + (timeframe.isseconds ? "S" : "") : too_small_tf(res) ? (timeframe.isweekly ? "3" : "10") : res, src)
  159.     if array.size(bull_array) > 1 and not equal_tf(res) and not higher_tf(res)
  160.         bull_ := array.pop(bull_array)
  161.     array.clear(bull_array)
  162.     bull_
  163. TF1Bull   = securityNoRep1(syminfo.tickerid, "1"   , emaBull)
  164. TF3Bull   = securityNoRep1(syminfo.tickerid, "3"   , emaBull)
  165. TF5Bull   = securityNoRep1(syminfo.tickerid, "5"   , emaBull)
  166. TF15Bull  = securityNoRep1(syminfo.tickerid, "15"  , emaBull)
  167. TF30Bull  = securityNoRep1(syminfo.tickerid, "30"  , emaBull)
  168. TF60Bull  = securityNoRep1(syminfo.tickerid, "60"  , emaBull)
  169. TF120Bull = securityNoRep1(syminfo.tickerid, "120" , emaBull)
  170. TF240Bull = securityNoRep1(syminfo.tickerid, "240" , emaBull)
  171. TF480Bull = securityNoRep1(syminfo.tickerid, "480" , emaBull)
  172. TFDBull   = securityNoRep1(syminfo.tickerid, "1440", emaBull)
  173. [wt1, wt2] = wavetrend(close, 5, 10)
  174. [wtDivBear1, wtDivBull1] = f_findDivs(wt2, 15, -40)
  175. [wtDivBear2, wtDivBull2] = f_findDivs(wt2, 45, -65)
  176. wtDivBull = wtDivBull1 or wtDivBull2
  177. wtDivBear = wtDivBear1 or wtDivBear2
  178.  
  179. // Colors
  180. white = #00c2fd, white30 = color.new(white, 100)
  181. blue = #fd00fd, blue30 = color.new(blue, 100)
  182. whiteish  = #ffffff, whiteish30  = color.new(whiteish , 100)
  183.  
  184. // Plot
  185. off = percWidth(300, offsetSignal)
  186. barcolor(up > dn ? white : blue)
  187. plotshape(showBuySell and bull ? low  - off : na, "Buy Label" , shape.labelup  , location.absolute, color(#028806), 0, "Buy" , color.white, size=size.tiny)
  188. plotshape(showBuySell and bear ? high + off : na, "Sell Label", shape.labeldown, location.absolute, color(#8b010d), 0, "Sell", color.white, size=size.tiny)
  189. plotshape(ta.crossover(wt1, wt2) and wt2 <= -53, "Don't Sell/Bottom" , shape.xcross, location.belowbar, color(#8a0410), size=size.tiny)
  190. plotshape(ta.crossunder(wt1, wt2) and wt2 >= 53, "Don't Buy/Top", shape.xcross, location.abovebar, color(#038507), size=size.tiny)
  191. plotshape(wtDivBull, "Weak Buy ", shape.circle  , location.belowbar, color(#038307), size=size.auto)
  192. plotshape(wtDivBear, "Weak Sell", shape.circle, location.abovebar, color(#8b030e), size=size.auto)
  193. plotshape(showReversal and rsiOs, "Reversal Buy" , shape.diamond, location.belowbar, color(#037007), size=size.tiny)
  194. plotshape(showReversal and rsiOb, "Reversal Sell", shape.diamond, location.abovebar, color(#7e050f), size=size.tiny)
  195.  
  196. srcStop = close
  197. atrBand = srcStop * (percentStop / 100)
  198. atrStop = trigger ? srcStop - atrBand : srcStop + atrBand
  199. lastTrade(src) => ta.valuewhen(bull or bear, src, 0)
  200. entry_y = lastTrade(srcStop)
  201. stop_y = lastTrade(atrStop)
  202. tp1_y = (entry_y - lastTrade(atrStop)) * 2 + entry_y
  203.  
  204. // Labels
  205. labelTpSl(y, txt, color) =>
  206.     label labelTpSl = percentStop and enableE != 0 ? label.new(bar_index + 1, y, txt, xloc.bar_index, yloc.price, color, label.style_label_left, color.white, size.normal) : na
  207.     label.delete(labelTpSl[1])
  208. labelTpSl(entry_y, "Entry: " + str.tostring(math.round_to_mintick(entry_y)), color = Entry)
  209. labelTpSl(stop_y , "StopLoss: " + str.tostring(math.round_to_mintick(stop_y)), color = Stop)
  210. labelTpSl(tp1_y, "Take Profit: " + str.tostring(math.round_to_mintick(tp1_y)), color = Tp1)
  211. lineTpSl(y, color) =>
  212.     line lineTpSl = percentStop and enableE != 0 ? line.new(bar_index - (trigger ? countBull : countBear) + 4, y, bar_index + 1, y, xloc.bar_index, extend.none, color, line.style_solid) : na
  213.     line.delete(lineTpSl[1])
  214. lineTpSl(entry_y, color = Entry)
  215. lineTpSl(stop_y, color = Stop)
  216. lineTpSl(tp1_y, color = Tp1)
  217.  
  218. // SUPPLY & DEMAND
  219. //Functions
  220.  
  221. //Line Style function
  222. get_line_style(style) =>
  223.     out = switch style
  224.         'Solid'  => line.style_solid
  225.         'Dashed' => line.style_dashed
  226.         'Dotted' => line.style_dotted
  227.  
  228. //Function to get order block coordinates
  229. get_coordinates(condition, top, btm, ob_val)=>
  230.     var ob_top  = array.new_float(0)
  231.     var ob_btm  = array.new_float(0)
  232.     var ob_avg  = array.new_float(0)
  233.     var ob_left = array.new_int(0)
  234.  
  235.     float ob = na
  236.  
  237.     //Append coordinates to arrays
  238.     if condition and enableSD
  239.         avg = math.avg(top, btm)
  240.        
  241.         array.unshift(ob_top, top)
  242.         array.unshift(ob_btm, btm)
  243.         array.unshift(ob_avg, avg)
  244.         array.unshift(ob_left, time[length])
  245.        
  246.         ob := ob_val
  247.    
  248.     [ob_top, ob_btm, ob_avg, ob_left, ob]
  249.  
  250. //Function to remove mitigated order blocks from coordinate arrays
  251. remove_mitigated(ob_top, ob_btm, ob_left, ob_avg, target, bull)=>
  252.     mitigated = false
  253.     target_array = bull ? ob_btm : ob_top
  254.  
  255.     for element in target_array
  256.         idx = array.indexof(target_array, element)
  257.  
  258.         if (bull ? target < element : target > element)
  259.             mitigated := true
  260.  
  261.             array.remove(ob_top, idx)
  262.             array.remove(ob_btm, idx)
  263.             array.remove(ob_avg, idx)
  264.             array.remove(ob_left, idx)
  265.    
  266.     mitigated
  267.  
  268. //Function to set order blocks
  269. set_order_blocks(ob_top, ob_btm, ob_left, ob_avg, ext_last, bg_css, border_css, lvl_css)=>
  270.     var ob_box = array.new_box(0)
  271.     var ob_lvl = array.new_line(0)
  272.  
  273.     //Fill arrays with boxes/lines
  274.     if barstate.isfirst
  275.         for i = 0 to ext_last-1
  276.             array.unshift(ob_box, box.new(na,na,na,na
  277.               , xloc = xloc.bar_time
  278.               , extend= extend.right
  279.               , bgcolor = bg_css
  280.               , border_color = color.new(border_css, 70)))
  281.  
  282.             array.unshift(ob_lvl, line.new(na,na,na,na
  283.               , xloc = xloc.bar_time
  284.               , extend = extend.right
  285.               , color = lvl_css
  286.               , style = get_line_style(line_style)
  287.               , width = line_width))
  288.  
  289.     //Set order blocks
  290.     if barstate.islast
  291.         if array.size(ob_top) > 0
  292.             for i = 0 to math.min(ext_last-1, array.size(ob_top)-1)
  293.                 get_box = array.get(ob_box, i)
  294.                 get_lvl = array.get(ob_lvl, i)
  295.  
  296.                 box.set_lefttop(get_box, array.get(ob_left, i), array.get(ob_top, i))
  297.                 box.set_rightbottom(get_box, array.get(ob_left, i), array.get(ob_btm, i))
  298.  
  299.                 line.set_xy1(get_lvl, array.get(ob_left, i), array.get(ob_avg, i))
  300.                 line.set_xy2(get_lvl, array.get(ob_left, i)+1, array.get(ob_avg, i))
  301.  
  302. //Global elements
  303. var os = 0
  304. var target_bull = 0.
  305. var target_bear = 0.
  306.  
  307. n = bar_index
  308. upper = ta.highest(length)
  309. lower = ta.lowest(length)
  310.  
  311. if mitigation == 'Close'
  312.     target_bull := ta.lowest(close, length)
  313.     target_bear := ta.highest(close, length)
  314. else
  315.     target_bull := lower
  316.     target_bear := upper
  317.  
  318. os := high[length] > upper ? 0 : low[length] < lower ? 1 : os[1]
  319.  
  320. phv = ta.pivothigh(volume, length, length)
  321.  
  322. //Get bullish/bearish order blocks coordinates
  323. [bull_top
  324.   , bull_btm
  325.   , bull_avg
  326.   , bull_left
  327.   , bull_ob] = get_coordinates(phv and os == 1, hl2[length], low[length], low[length])
  328.  
  329. [bear_top
  330.   , bear_btm
  331.   , bear_avg
  332.   , bear_left
  333.   , bear_ob] = get_coordinates(phv and os == 0, high[length], hl2[length], high[length])
  334.  
  335. //Remove mitigated order blocks
  336. mitigated_bull = remove_mitigated(bull_top
  337.   , bull_btm
  338.   , bull_left
  339.   , bull_avg
  340.   , target_bull
  341.   , true)
  342.  
  343. mitigated_bear = remove_mitigated(bear_top
  344.   , bear_btm
  345.   , bear_left
  346.   , bear_avg
  347.   , target_bear
  348.   , false)
  349.  
  350. //Set bullish order blocks
  351. set_order_blocks(bull_top
  352.   , bull_btm
  353.   , bull_left
  354.   , bull_avg
  355.   , bull_ext_last
  356.   , bg_bull_css
  357.   , bull_css
  358.   , bull_avg_css)
  359.  
  360. //Set bearish order blocks
  361. set_order_blocks(bear_top
  362.   , bear_btm
  363.   , bear_left
  364.   , bear_avg
  365.   , bear_ext_last
  366.   , bg_bear_css
  367.   , bear_css
  368.   , bear_avg_css)
  369.  
  370. // SUPPORT & RESISTANCE
  371.  
  372. percWidth1(len, perc) => (ta.highest(len) - ta.lowest(len)) * perc / 100
  373.  
  374. // Get components
  375. rb            = 10
  376. prd           = 284
  377. ChannelW      = 10
  378. label_loc     = 55
  379. style1        = lineStyle1 == "Solid" ? line.style_solid : lineStyle1 == "Dotted" ? line.style_dotted :  line.style_dashed
  380. ph            = ta.pivothigh(rb, rb)
  381. pl            = ta.pivotlow (rb, rb)
  382. sr_levels     = array.new_float(21, na)
  383. prdhighest    = ta.highest(prd)
  384. prdlowest     = ta.lowest(prd)
  385. cwidth        = percWidth(prd, ChannelW)
  386. zonePerc      = percWidth(300, zoneWidth)
  387. aas           = array.new_bool(41, true)
  388. u1            = 0.0, u1 := nz(u1[1])
  389. d1            = 0.0, d1 := nz(d1[1])
  390. highestph     = 0.0, highestph := highestph[1]
  391. lowestpl      = 0.0, lowestpl := lowestpl[1]
  392. var sr_levs   = array.new_float(21, na)
  393. label hlabel  = na, label.delete(hlabel[1])
  394. label llabel  = na, label.delete(llabel[1])
  395. var sr_lines  = array.new_line(21, na)
  396. var sr_linesH = array.new_line(21, na)
  397. var sr_linesL = array.new_line(21, na)
  398. var sr_linesF = array.new_linefill(21, na)
  399. var sr_labels = array.new_label(21, na)
  400. if ph or pl
  401.     for x = 0 to array.size(sr_levels) - 1
  402.         array.set(sr_levels, x, na)
  403.     highestph := prdlowest
  404.     lowestpl := prdhighest
  405.     countpp = 0
  406.     for x = 0 to prd
  407.         if na(close[x])
  408.             break
  409.         if not na(ph[x]) or not na(pl[x])
  410.             highestph := math.max(highestph, nz(ph[x], prdlowest), nz(pl[x], prdlowest))
  411.             lowestpl := math.min(lowestpl, nz(ph[x], prdhighest), nz(pl[x], prdhighest))
  412.             countpp += 1
  413.             if countpp > 40
  414.                 break
  415.             if array.get(aas, countpp)
  416.                 upl = (ph[x] ? high[x + rb] : low[x + rb]) + cwidth
  417.                 dnl = (ph[x] ? high[x + rb] : low[x + rb]) - cwidth
  418.                 u1 := countpp == 1 ? upl : u1
  419.                 d1 := countpp == 1 ? dnl : d1
  420.                 tmp = array.new_bool(41, true)
  421.                 cnt = 0
  422.                 tpoint = 0
  423.                 for xx = 0 to prd
  424.                     if na(close[xx])
  425.                         break
  426.                     if not na(ph[xx]) or not na(pl[xx])
  427.                         chg = false
  428.                         cnt += 1
  429.                         if cnt > 40
  430.                             break
  431.                         if array.get(aas, cnt)
  432.                             if not na(ph[xx])
  433.                                 if high[xx + rb] <= upl and high[xx + rb] >= dnl
  434.                                     tpoint += 1
  435.                                     chg := true
  436.                             if not na(pl[xx])
  437.                                 if low[xx + rb] <= upl and low[xx + rb] >= dnl
  438.                                     tpoint += 1
  439.                                     chg := true
  440.                         if chg and cnt < 41
  441.                             array.set(tmp, cnt, false)
  442.                 if tpoint >= strengthSR
  443.                     for g = 0 to 40 by 1
  444.                         if not array.get(tmp, g)
  445.                             array.set(aas, g, false)
  446.                     if ph[x] and countpp < 21
  447.                         array.set(sr_levels, countpp, high[x + rb])
  448.                     if pl[x] and countpp < 21
  449.                         array.set(sr_levels, countpp, low[x + rb])
  450.  
  451. // Plot
  452. var line highest_ = na, line.delete(highest_)
  453. var line lowest_  = na, line.delete(lowest_)
  454. var line highest_fill1 = na, line.delete(highest_fill1)
  455. var line highest_fill2 = na, line.delete(highest_fill2)
  456. var line lowest_fill1  = na, line.delete(lowest_fill1)
  457. var line lowest_fill2  = na, line.delete(lowest_fill2)
  458. hi_col = close >= highestph ? colorSup : colorRes
  459. lo_col = close >= lowestpl  ? colorSup : colorRes
  460. if enableSR
  461.     highest_ := line.new(bar_index - 311, highestph, bar_index, highestph, xloc.bar_index, expandSR ? extend.both : extend.right, hi_col, style1, lineWidth1)
  462.     lowest_  := line.new(bar_index - 311, lowestpl , bar_index, lowestpl , xloc.bar_index, expandSR ? extend.both : extend.right, lo_col, style1, lineWidth1)
  463.     if useHLZones
  464.         highest_fill1 := line.new(bar_index - 311, highestph + zonePerc, bar_index, highestph + zonePerc, xloc.bar_index, expandSR ? extend.both : extend.right, na)
  465.         highest_fill2 := line.new(bar_index - 311, highestph - zonePerc, bar_index, highestph - zonePerc, xloc.bar_index, expandSR ? extend.both : extend.right, na)
  466.         lowest_fill1  := line.new(bar_index - 311, lowestpl + zonePerc , bar_index, lowestpl + zonePerc , xloc.bar_index, expandSR ? extend.both : extend.right, na)
  467.         lowest_fill2  := line.new(bar_index - 311, lowestpl - zonePerc , bar_index, lowestpl - zonePerc , xloc.bar_index, expandSR ? extend.both : extend.right, na)
  468.         linefill.new(highest_fill1, highest_fill2, color.new(hi_col, 90))
  469.         linefill.new(lowest_fill1 , lowest_fill2 , color.new(lo_col, 90))
  470. if ph or pl
  471.     for x = 0 to array.size(sr_lines) - 1
  472.         array.set(sr_levs, x, array.get(sr_levels, x))
  473. for x = 0 to array.size(sr_lines) - 1
  474.     line.delete(array.get(sr_lines, x))
  475.     line.delete(array.get(sr_linesH, x))
  476.     line.delete(array.get(sr_linesL, x))
  477.     linefill.delete(array.get(sr_linesF, x))
  478.     if array.get(sr_levs, x) and enableSR
  479.         line_col = close >= array.get(sr_levs, x) ? colorSup : colorRes
  480.         array.set(sr_lines, x, line.new(bar_index - 355, array.get(sr_levs, x), bar_index, array.get(sr_levs, x), xloc.bar_index, expandSR ? extend.both : extend.right, line_col, style1, lineWidth1))
  481.         if useZones
  482.             array.set(sr_linesH, x, line.new(bar_index - 355, array.get(sr_levs, x) + zonePerc, bar_index, array.get(sr_levs, x) + zonePerc, xloc.bar_index, expandSR ? extend.both : extend.right, na))
  483.             array.set(sr_linesL, x, line.new(bar_index - 355, array.get(sr_levs, x) - zonePerc, bar_index, array.get(sr_levs, x) - zonePerc, xloc.bar_index, expandSR ? extend.both : extend.right, na))
  484.             array.set(sr_linesF, x, linefill.new(array.get(sr_linesH, x), array.get(sr_linesL, x), color.new(line_col, 90)))
  485. for x = 0 to array.size(sr_labels) - 1
  486.     label.delete(array.get(sr_labels, x))
  487.     if array.get(sr_levs, x) and enableSR
  488.         lab_loc = close >= array.get(sr_levs, x) ? label.style_label_up : label.style_label_down
  489.         lab_col = close >= array.get(sr_levs, x) ? colorSup             : colorRes
  490.  
  491. // Dashboard
  492. var dashboard_loc  = locationDashboard == "Top Right" ? position.top_right : locationDashboard == "Middle Right" ? position.middle_right : locationDashboard == "Bottom Right" ? position.bottom_right : locationDashboard == "Top Center" ? position.top_center : locationDashboard == "Middle Center" ? position.middle_center : locationDashboard == "Bottom Center" ? position.bottom_center : locationDashboard == "Top Left" ? position.top_left : locationDashboard == "Middle Left" ? position.middle_left : position.bottom_left
  493. var dashboard_size = sizeDashboard == "Large" ? size.large : sizeDashboard == "Normal" ? size.normal : sizeDashboard == "Small" ? size.small : size.tiny
  494. var dashboard      = showDashboard ? table.new(dashboard_loc, 2, 15, tableBgColor, #000000, 2, tableBgColor, 1) : na
  495. dashboard_cell(column, row, txt, signal=false) => table.cell(dashboard, column, row, txt, 0, 0, signal ? #000000 : tableTextColor, text_size=dashboard_size)
  496. dashboard_cell_bg(column, row, col) => table.cell_set_bgcolor(dashboard, column, row, col)
  497. if barstate.islast and showDashboard
  498.     dashboard_cell(0, 0 , "Crypto_Wolf_Traders_V4.1")
  499.     dashboard_cell(0, 1 , "Current Position")
  500.     dashboard_cell(0, 2 , "Current Trend")
  501.     dashboard_cell(0, 3 , "Volume")
  502.     dashboard_cell(0, 4 , "Timeframe")
  503.     dashboard_cell(0, 5 , "1 min:")
  504.     dashboard_cell(0, 6 , "3 min:")
  505.     dashboard_cell(0, 7 , "5 min:")
  506.     dashboard_cell(0, 8 , "15 min:")
  507.     dashboard_cell(0, 9 , "30 min:")
  508.     dashboard_cell(0, 10, "1 H:")
  509.     dashboard_cell(0, 11, "2 H:")
  510.     dashboard_cell(0, 12, "4 H:")
  511.     dashboard_cell(0, 13, "8 H:")
  512.     dashboard_cell(0, 14, "Daily:")
  513.     dashboard_cell(1, 0 , "")
  514.     dashboard_cell(1, 1 , trigger ? "Buy" : "Sell", true), dashboard_cell_bg(1, 1, trigger ? #058809 : #8f0712)
  515.     dashboard_cell(1, 2 , emaBull ? "Bullish" : "Bearish", true), dashboard_cell_bg(1, 2, emaBull ? #047c08 : #8d040f)
  516.     dashboard_cell(1, 3 , str.tostring(volume))
  517.     dashboard_cell(1, 4 , "Trends")
  518.     dashboard_cell(1, 5 , TF1Bull   ? "Bullish" : "Bearish", true), dashboard_cell_bg(1, 5 , TF1Bull   ? #008104 : #85040e)
  519.     dashboard_cell(1, 6 , TF3Bull   ? "Bullish" : "Bearish", true), dashboard_cell_bg(1, 6 , TF3Bull   ? #028106 : #8b0510)
  520.     dashboard_cell(1, 7 , TF5Bull   ? "Bullish" : "Bearish", true), dashboard_cell_bg(1, 7 , TF5Bull   ? #027c06 : #8d040f)
  521.     dashboard_cell(1, 8 , TF15Bull  ? "Bullish" : "Bearish", true), dashboard_cell_bg(1, 8 , TF15Bull  ? #018005 : #80040e)
  522.     dashboard_cell(1, 9 , TF30Bull  ? "Bullish" : "Bearish", true), dashboard_cell_bg(1, 9 , TF30Bull  ? #028806 : #85020d)
  523.     dashboard_cell(1, 10, TF60Bull  ? "Bullish" : "Bearish", true), dashboard_cell_bg(1, 10, TF60Bull  ? #028006 : #86030e)
  524.     dashboard_cell(1, 11, TF120Bull ? "Bullish" : "Bearish", true), dashboard_cell_bg(1, 11, TF120Bull ? #038107 : #81030e)
  525.     dashboard_cell(1, 12, TF240Bull ? "Bullish" : "Bearish", true), dashboard_cell_bg(1, 12, TF240Bull ? #028307 : #74020b)
  526.     dashboard_cell(1, 13, TF480Bull ? "Bullish" : "Bearish", true), dashboard_cell_bg(1, 13, TF480Bull ? #048008 : #81030d)
  527.     dashboard_cell(1, 14, TFDBull   ? "Bullish" : "Bearish", true), dashboard_cell_bg(1, 14, TFDBull   ? #047c08 : #85020d)
  528.  
  529. // Previos Day H/L/C
  530. lStyle = lineStyle == "Solid" ? line.style_solid : lineStyle == "Dotted" ? line.style_dotted : line.style_dashed
  531. dHighLine   = showPdHlc ? line.new(bar_index, dHigh,  bar_index + 1, dHigh , xloc.bar_index, extend.both, lineColor, lStyle, lineWidth) : na, line.delete(dHighLine[1])
  532. dLowLine    = showPdHlc ? line.new(bar_index, dLow ,  bar_index + 1, dLow  , xloc.bar_index, extend.both, lineColor, lStyle, lineWidth) : na, line.delete(dLowLine[1])
  533. dCloseLine  = showPdHlc ? line.new(bar_index, dClose, bar_index + 1, dClose, xloc.bar_index, extend.both, lineColor, lStyle, lineWidth) : na, line.delete(dCloseLine[1])
  534.  
  535. ////////////////////////////////////////////////////////////////////////////////
  536. //------------------CRYPTO-WOLF-TRADERS-NEURAL-NETRORK------------------------------------//
  537. ////////////////////////////////////////////////////////////////////////////////
  538. price = plot(close, title='Close Line', color=color.new(color.blue, 0), display=display.none)
  539. ////////////////////////////////////////////////////////////////////////////////
  540. //TREND INDICATORS▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼
  541. //Trend EMA
  542. tttradetrend = 'Only place BUY or SELL orders with the direction of the Trend EMA.'
  543. tradetrendoption = input.bool(false, title='Only Tade with Trend', group = "NEURAL NETWORK", tooltip=tttradetrend)
  544. len111 = input.int(defval=200, minval=0, maxval=2000, title='Trend EMA Length')
  545. src111 = close
  546. out111 = ta.ema(src111, len111)
  547. ma111 = plot(out111, title='EMA 200', linewidth=5, color=color.new(color.blue, 0), offset=0)
  548. mabuy = out111 > out111[1]
  549. masell = out111 < out111[1]
  550. //5 EMAs////////////////////////////////////////////////////////////////////////
  551. len1 = 9
  552. src1 = close
  553. out1 = ta.ema(src1, len1)
  554. ema1color = out1 > out1[1] ? #00bcd4 : #e91e63
  555. ema1 = plot(out1, title='EMA 9', linewidth=3, color=color.new(ema1color, 50), offset=0, display=display.none)
  556. fill(price, ema1, title='EMA 9 Fill', color=color.new(ema1color, 90), editable=true)
  557. len2 = 21
  558. src2 = close
  559. out2 = ta.ema(src2, len2)
  560. ema2color = out2 > out2[1] ? #00bcd4 : #e91e63
  561. ema2 = plot(out2, title='EMA 21', linewidth=3, color=color.new(ema2color, 50), offset=0, display=display.none)
  562. fill(price, ema2, title='EMA 21 Fill', color=color.new(ema2color, 90), editable=true)
  563. len3 = 55
  564. src3 = close
  565. out3 = ta.ema(src3, len3)
  566. ema3color = out3 > out3[1] ? #00bcd4 : #e91e63
  567. ema3 = plot(out3, title='EMA 55', linewidth=3, color=color.new(ema3color, 50), offset=0, display=display.none)
  568. fill(price, ema3, title='EMA 55 Fill', color=color.new(ema3color, 90), editable=true)
  569. len4 = 100
  570. src4 = close
  571. out4 = ta.ema(src4, len4)
  572. ema4color = out4 > out4[1] ? #00bcd4 : #e91e63
  573. ema4 = plot(out4, title='EMA 100', linewidth=3, color=color.new(ema4color, 50), offset=0, display=display.none)
  574. fill(price, ema4, title='EMA 100 Fill', color=color.new(ema4color, 90), editable=true)
  575. len5 = 200
  576. src5 = close
  577. out5 = ta.ema(src5, len5)
  578. ema5color = out5 > out5[1] ? #00bcd4 : #e91e63
  579. ema5 = plot(out5, title='EMA 200', linewidth=3, color=color.new(ema5color, 50), offset=0, display=display.none)
  580. fill(price, ema5, title='EMA 200 Fill', color=color.new(ema5color, 90), editable=true)
  581.  
  582. //Supertrend////////////////////////////////////////////////////////////////////
  583. atrPeriod = 10
  584. factor = 3
  585. [supertrend, direction] = ta.supertrend(factor, atrPeriod)
  586. bodyMiddle = plot((open + close) / 2, display=display.none, title='Body Middle Line')
  587. uptrend = direction < 0 and direction[1] > 0[1] ? supertrend : na
  588. downtrend = direction > 0 and direction[1] < 0[1] ? supertrend : na
  589. //fill(bodyMiddle, upTrend, color.new(color.green, 90), fillgaps=false)
  590. //fill(bodyMiddle, downTrend, color.new(color.red, 90), fillgaps=false)
  591. //bullishsupertrend = supertrend < close and supertrend[1] > close
  592. //plotshape(uptrend, style=shape.labelup, color=color.green, location=location.belowbar, size=size.large)
  593.  
  594. //HMA///////////////////////////////////////////////////////////////////////////
  595. len6 = 100
  596. src6 = close
  597. hma = ta.wma(2 * ta.wma(src6, len6 / 2) - ta.wma(src6, len6), math.floor(math.sqrt(len6)))
  598. hmacolor = close > hma ? #00bcd4 : #e91e63
  599. plot(hma, title='HMA Line', color=color.new(hmacolor, 25), linewidth=5)
  600.  
  601. //Parabolic SAR/////////////////////////////////////////////////////////////////
  602. start = 0.02
  603. increment = 0.01
  604. maximum = 0.2
  605. psar = ta.sar(start, increment, maximum)
  606. //plot(psar, "ParabolicSAR", style=plot.style_circles, color=#ffffff)
  607.  
  608.  
  609. //END▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲
  610. ////////////////////////////////////////////////////////////////////////////////
  611. //MOMENTUM INCIDATORS▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼
  612.  
  613. //RSI Divergence////////////////////////////////////////////////////////////////
  614. len11 = 14
  615. src11 = close
  616. lbR11 = 2
  617. lbL11 = 6
  618. rangeUpper11 = 60
  619. rangeLower11 = 5
  620. plotBull11 = true
  621. plotHiddenBull11 = false
  622. plotBear11 = true
  623. plotHiddenBear11 = false
  624. bearColor11 = color.red
  625. bullColor11 = color.green
  626. hiddenBullColor11 = color.new(color.green, 80)
  627. hiddenBearColor11 = color.new(color.red, 80)
  628. textColor11 = color.white
  629. noneColor11 = color.new(color.white, 100)
  630. osc11 = ta.rsi(src11, len11)
  631.  
  632. //plot(osc11, title="RSI", linewidth=2, color=#2962FF)
  633. //hline(50, title="Middle Line", color=#787B86, linestyle=hline.style_dotted)
  634. //obLevel11 = hline(70, title="Overbought", color=#787B86, linestyle=hline.style_dotted)
  635. //osLevel11 = hline(30, title="Oversold", color=#787B86, linestyle=hline.style_dotted)
  636. //fill(obLevel11, osLevel11, title="Background", color=color.rgb(33, 150, 243, 90))
  637.  
  638. plFound11 = na(ta.pivotlow(osc11, lbL11, lbR11)) ? false : true
  639. phFound11 = na(ta.pivothigh(osc11, lbL11, lbR11)) ? false : true
  640. _inRange11(cond) =>
  641.     bars11 = ta.barssince(cond == true)
  642.     rangeLower11 <= bars11 and bars11 <= rangeUpper11
  643.  
  644. //Regular Bullish Divergence
  645.  
  646. //Osc: Higher Low
  647. oscHL11 = osc11[lbR11] > ta.valuewhen(plFound11, osc11[lbR11], 1) and _inRange11(plFound11[1])
  648. //Price: Lower Low
  649. priceLL11 = low[lbR11] < ta.valuewhen(plFound11, low[lbR11], 1)
  650.  
  651. bullCond11 = plotBull11 and priceLL11 and oscHL11 and plFound11
  652. //plot(plFound11 ? osc11[lbR11] : na, offset=-lbR11, title="Regular Bullish", linewidth=2, color=(bullCond11 ? bullColor11 : noneColor11))
  653. //plotshape(bullCond11 ? osc11[lbR11] : na, offset=-lbR11, title="Regular Bullish Label", text=" Bull ", style=shape.labelup, location=location.absolute, color=bullColor11, textcolor=textColor11)
  654.  
  655. //Hidden Bullish Divergence
  656.  
  657. //Osc: Lower Low
  658. oscLL11 = osc11[lbR11] < ta.valuewhen(plFound11, osc11[lbR11], 1) and _inRange11(plFound11[1])
  659. //Price: Higher Low
  660. priceHL11 = low[lbR11] > ta.valuewhen(plFound11, low[lbR11], 1)
  661.  
  662. hiddenBullCond11 = plotHiddenBull11 and priceHL11 and oscLL11 and plFound11
  663. //plot(plFound11 ? osc11[lbR11] : na, offset=-lbR11, title="Hidden Bullish", linewidth=2, color=(hiddenBullCond11 ? hiddenBullColor11 : noneColor11))
  664. //plotshape(hiddenBullCond11 ? osc11[lbR11] : na, offset=-lbR11, title="Hidden Bullish Label", text=" H Bull ", style=shape.labelup, location=location.absolute, color=bullColor11, textcolor=textColor11)
  665.  
  666. //Regular Bearish Divergence
  667.  
  668. //Osc: Lower High
  669. oscLH11 = osc11[lbR11] < ta.valuewhen(phFound11, osc11[lbR11], 1) and _inRange11(phFound11[1])
  670. //Price: Higher High
  671. priceHH11 = high[lbR11] > ta.valuewhen(phFound11, high[lbR11], 1)
  672.  
  673. bearCond11 = plotBear11 and priceHH11 and oscLH11 and phFound11
  674. //plot(phFound11 ? osc11[lbR11] : na, offset=-lbR11, title="Regular Bearish", linewidth=2, color=(bearCond11 ? bearColor11 : noneColor11))
  675. //plotshape(bearCond11 ? osc11[lbR11] : na, offset=-lbR11, title="Regular Bearish Label", text=" Bear ", style=shape.labeldown, location=location.absolute, color=bearColor11, textcolor=textColor11)
  676.  
  677. //Hidden Bearish Divergence
  678.  
  679. //Osc: Higher High
  680. oscHH11 = osc11[lbR11] > ta.valuewhen(phFound11, osc11[lbR11], 1) and _inRange11(phFound11[1])
  681. // Price: Lower High
  682. priceLH11 = high[lbR11] < ta.valuewhen(phFound11, high[lbR11], 1)
  683.  
  684. hiddenBearCond11 = plotHiddenBear11 and priceLH11 and oscHH11 and phFound11
  685. //plot(phFound11 ? osc11[lbR11] : na, offset=-lbR11, title="Hidden Bearish", linewidth=2, color=(hiddenBearCond11 ? hiddenBearColor11 : noneColor11))
  686. //plotshape(hiddenBearCond11 ? osc11[lbR11] : na, offset=-lbR11, title="Hidden Bearish Label", text=" H Bear ", style=shape.labeldown, location=location.absolute, color=bearColor11, textcolor=textColor11)
  687.  
  688. //MACD Divergence///////////////////////////////////////////////////////////////
  689. fast_length12 = 12
  690. slow_length12 = 26
  691. src12 = close
  692. signal_length12 = 9
  693. sma_source12 = 'EMA'
  694. sma_signal12 = 'EMA'
  695. //Plot colors
  696. col_macd12 = #2962FF
  697. col_signal12 = #FF6D00
  698. col_grow_above12 = #26A69A
  699. col_fall_above12 = #B2DFDB
  700. col_grow_below12 = #FFCDD2
  701. col_fall_below12 = #FF5252
  702. //Calculating
  703. fast_ma12 = sma_source12 == 'SMA' ? ta.sma(src12, fast_length12) : ta.ema(src12, fast_length12)
  704. slow_ma12 = sma_source12 == 'SMA' ? ta.sma(src12, slow_length12) : ta.ema(src12, slow_length12)
  705. macd = fast_ma12 - slow_ma12
  706. signal = sma_signal12 == 'SMA' ? ta.sma(macd, signal_length12) : ta.ema(macd, signal_length12)
  707. hist = macd - signal
  708. //plot(hist, title="Histogram", style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? col_grow_above12 : col_fall_above12) : (hist[1] < hist ? col_grow_below12 : col_fall_below12)))
  709. //plot(macd, title="MACD", color=col_macd12)
  710. //plot(signal, title="Signal", color=col_signal12)
  711.  
  712. donttouchzero12 = true
  713.  
  714. lbR12 = 2
  715. lbL12 = 6
  716. rangeUpper12 = 60
  717. rangeLower12 = 5
  718. plotBull12 = true
  719. plotHiddenBull12 = false
  720. plotBear12 = true
  721. plotHiddenBear12 = false
  722. bearColor12 = color.red
  723. bullColor12 = color.green
  724. hiddenBullColor12 = color.new(color.green, 80)
  725. hiddenBearColor12 = color.new(color.red, 80)
  726. textColor12 = color.white
  727. noneColor12 = color.new(color.white, 100)
  728. osc12 = macd
  729.  
  730. plFound12 = na(ta.pivotlow(osc12, lbL12, lbR12)) ? false : true
  731. phFound12 = na(ta.pivothigh(osc12, lbL12, lbR12)) ? false : true
  732. _inRange12(cond) =>
  733.     bars12 = ta.barssince(cond == true)
  734.     rangeLower12 <= bars12 and bars12 <= rangeUpper12
  735.  
  736. //Regular Bullish Divergence
  737.  
  738. //Osc: Higher Low
  739. oscHL12 = osc12[lbR12] > ta.valuewhen(plFound12, osc12[lbR12], 1) and _inRange12(plFound12[1]) and osc12[lbR12] < 0
  740. // Price: Lower Low
  741. priceLL12 = low[lbR12] < ta.valuewhen(plFound12, low[lbR12], 1)
  742. priceHHZero12 = ta.highest(osc12, lbL12 + lbR12 + 5)
  743. //plot(priceHHZero,title="priceHHZero",color=color.green)
  744. blowzero12 = donttouchzero12 ? priceHHZero12 < 0 : true
  745.  
  746. bullCond12 = plotBull12 and priceLL12 and oscHL12 and plFound12 and blowzero12
  747. //plot(plFound12 ? osc12[lbR12] : na, offset=-lbR12, title="Regular Bullish", linewidth=2, color=(bullCond12 ? bullColor12 : noneColor12))
  748. //plotshape(bullCond12 ? osc12[lbR12] : na, offset=-lbR12, title="Regular Bullish Label", text=" Bull ", style=shape.labelup, location=location.absolute, color=bullColor12, textcolor=textColor12)
  749.  
  750. //Hidden Bullish Divergence
  751.  
  752. //Osc: Lower Low
  753. oscLL12 = osc12[lbR12] < ta.valuewhen(plFound12, osc12[lbR12], 1) and _inRange12(plFound12[1])
  754. //Price: Higher Low
  755. priceHL12 = low[lbR12] > ta.valuewhen(plFound12, low[lbR12], 1)
  756.  
  757. hiddenBullCond12 = plotHiddenBull12 and priceHL12 and oscLL12 and plFound12
  758. //plot(plFound12 ? osc12[lbR12] : na, offset=-lbR12, title="Hidden Bullish", linewidth=2, color=(hiddenBullCond12 ? hiddenBullColor12 : noneColor12))
  759. //plotshape(hiddenBullCond12 ? osc12[lbR12] : na, offset=-lbR12, title="Hidden Bullish Label", text=" H Bull ", style=shape.labelup, location=location.absolute, color=bullColor12, textcolor=textColor12)
  760.  
  761. //Regular Bearish Divergence
  762.  
  763. //Osc: Lower High
  764. oscLH12 = osc12[lbR12] < ta.valuewhen(phFound12, osc12[lbR12], 1) and _inRange12(phFound12[1]) and osc12[lbR12] > 0
  765. priceLLZero12 = ta.lowest(osc12, lbL12 + lbR12 + 5)
  766. //plot(priceLLZero,title="priceLLZero", color=color.red)
  767. bearzero12 = donttouchzero12 ? priceLLZero12 > 0 : true
  768. //Price: Higher High
  769. priceHH12 = high[lbR12] > ta.valuewhen(phFound12, high[lbR12], 1)
  770.  
  771. bearCond12 = plotBear12 and priceHH12 and oscLH12 and phFound12 and bearzero12
  772. //plot(phFound12 ? osc12[lbR12] : na, offset=-lbR12, title="Regular Bearish", linewidth=2, color=(bearCond12 ? bearColor12 : noneColor12))
  773. //plotshape(bearCond12 ? osc12[lbR12] : na, offset=-lbR12, title="Regular Bearish Label", text=" Bear ", style=shape.labeldown, location=location.absolute, color=bearColor12, textcolor=textColor12)
  774.  
  775. //Hidden Bearish Divergence
  776.  
  777. //Osc: Higher High
  778. oscHH12 = osc12[lbR12] > ta.valuewhen(phFound12, osc12[lbR12], 1) and _inRange12(phFound12[1])
  779. //Price: Lower High
  780. priceLH12 = high[lbR12] < ta.valuewhen(phFound12, high[lbR12], 1)
  781.  
  782. hiddenBearCond12 = plotHiddenBear12 and priceLH12 and oscHH12 and phFound12
  783. //plot(phFound12 ? osc12[lbR12] : na, offset=-lbR12, title="Hidden Bearish", linewidth=2, color=(hiddenBearCond12 ? hiddenBearColor12 : noneColor12))
  784. //plotshape(hiddenBearCond12 ? osc12[lbR12] : na, offset=-lbR12, title="Hidden Bearish Label", text=" H Bear ", style=shape.labeldown, location=location.absolute, color=bearColor12, textcolor=textColor12)
  785.  
  786.  
  787. //Wave Trend Divergence/////////////////////////////////////////////////////////
  788. n1 = 9
  789. n2 = 12
  790. ap = hlc3
  791. hline = 0
  792.  
  793. //Divergence
  794. lbR13 = 2
  795. lbL13 = 6
  796. rangeUpper13 = 60
  797. rangeLower13 = 5
  798. plotBull13 = true
  799. plotHiddenBull13 = false
  800. plotBear13 = true
  801. plotHiddenBear13 = false
  802.  
  803. bearColor13 = color.red
  804. bullColor13 = color.green
  805. hiddenBullColor13 = color.green
  806. hiddenBearColor13 = color.red
  807. textColor13 = color.white
  808. noneColor13 = color.new(color.white, 100)
  809.  
  810. _inRange13(cond) =>
  811.     bars13 = ta.barssince(cond == true)
  812.     rangeLower13 <= bars13 and bars13 <= rangeUpper13
  813.  
  814.  
  815. //Stochastic Divergence/////////////////////////////////////////////////////////
  816. periodK14 = 14
  817. smoothK14 = 3
  818. periodD14 = 3
  819. k14 = ta.sma(ta.stoch(close, high, low, periodK14), smoothK14)
  820. d14 = ta.sma(k14, periodD14)
  821.  
  822. //Divergence
  823. lbR14 = 2
  824. lbL14 = 6
  825. rangeUpper14 = 60
  826. rangeLower14 = 5
  827. plotBull14 = true
  828. plotHiddenBull14 = false
  829. plotBear14 = true
  830. plotHiddenBear14 = false
  831.  
  832. bearColor14 = color.red
  833. bullColor14 = color.green
  834. hiddenBullColor14 = color.green
  835. hiddenBearColor14 = color.red
  836. textColor14 = color.white
  837. noneColor14 = color.new(color.white, 100)
  838.  
  839. osc14 = k14
  840.  
  841. plFound14 = na(ta.pivotlow(osc14, lbL14, lbR14)) ? false : true
  842. phFound14 = na(ta.pivothigh(osc14, lbL14, lbR14)) ? false : true
  843.  
  844. _inRange14(cond) =>
  845.     bars14 = ta.barssince(cond == true)
  846.     rangeLower14 <= bars14 and bars14 <= rangeUpper14
  847.  
  848. //Regular Bullish
  849.  
  850. //Osc: Higher Low
  851. oscHL14 = osc14[lbR14] > ta.valuewhen(plFound14, osc14[lbR14], 1) and _inRange14(plFound14[1])
  852.  
  853. //Price: Lower Low
  854. priceLL14 = low[lbR14] < ta.valuewhen(plFound14, low[lbR14], 1)
  855.  
  856. bullCond14 = plotBull14 and priceLL14 and oscHL14 and plFound14
  857. //plot(plFound14 ? osc14[lbR14] : na, offset=-lbR14, title="Regular Bullish", linewidth=2, color=(bullCond14 ? bullColor14 : noneColor14))
  858. //plotshape(bullCond14 ? osc14[lbR14] : na, offset=-lbR14, title="Regular Bullish Label", text=" Bull ", style=shape.labelup, location=location.absolute, color=bullColor14, textcolor=textColor14)
  859.  
  860. //Hidden Bullish
  861.  
  862. //Osc: Lower Low
  863. oscLL14 = osc14[lbR14] < ta.valuewhen(plFound14, osc14[lbR14], 1) and _inRange14(plFound14[1])
  864.  
  865. //Price: Higher Low
  866. priceHL14 = low[lbR14] > ta.valuewhen(plFound14, low[lbR14], 1)
  867.  
  868. hiddenBullCond14 = plotHiddenBull14 and priceHL14 and oscLL14 and plFound14
  869. //plot(plFound14 ? osc14[lbR14] : na, offset=-lbR14, title="Hidden Bullish", linewidth=2, color=(hiddenBullCond14 ? hiddenBullColor14 : noneColor14))
  870. //plotshape(hiddenBullCond14 ? osc14[lbR14] : na, offset=-lbR14, title="Hidden Bullish Label", text=" H Bull ", style=shape.labelup, location=location.absolute, color=bullColor14, textcolor=textColor14)
  871.  
  872. //Regular Bearish
  873.  
  874. //Osc: Lower High
  875. oscLH14 = osc14[lbR14] < ta.valuewhen(phFound14, osc14[lbR14], 1) and _inRange14(phFound14[1])
  876.  
  877. //Price: Higher High
  878. priceHH14 = high[lbR14] > ta.valuewhen(phFound14, high[lbR14], 1)
  879.  
  880. bearCond14 = plotBear14 and priceHH14 and oscLH14 and phFound14
  881. //plot(phFound14 ? osc14[lbR14] : na, offset=-lbR14, title="Regular Bearish", linewidth=2, color=(bearCond14 ? bearColor14 : noneColor14))
  882. //plotshape(bearCond14 ? osc14[lbR14] : na, offset=-lbR14, title="Regular Bearish Label", text=" Bear ", style=shape.labeldown, location=location.absolute, color=bearColor14, textcolor=textColor14)
  883.  
  884. //Hidden Bearish
  885.  
  886. //Osc: Higher High
  887. oscHH14 = osc14[lbR14] > ta.valuewhen(phFound14, osc14[lbR14], 1) and _inRange14(phFound14[1])
  888.  
  889. //Price: Lower High
  890. priceLH14 = high[lbR14] < ta.valuewhen(phFound14, high[lbR14], 1)
  891.  
  892. hiddenBearCond14 = plotHiddenBear14 and priceLH14 and oscHH14 and phFound14
  893. //plot(phFound14 ? osc14[lbR14] : na, offset=-lbR14, title="Hidden Bearish", linewidth=2, color=(hiddenBearCond14 ? hiddenBearColor14 : noneColor14))
  894. //plotshape(hiddenBearCond14 ? osc14[lbR14] : na, offset=-lbR14, title="Hidden Bearish Label", text=" H Bear ", style=shape.labeldown, location=location.absolute, color=bearColor14, textcolor=textColor14)
  895.  
  896.  
  897. //END▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲
  898. ////////////////////////////////////////////////////////////////////////////////
  899. //VOLATILITY INDICATORS▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼
  900.  
  901. //Average True Range /////////////////////////////////////////////////
  902. length2 = 1
  903. mult2 = 1.85
  904. showLabels = true
  905. useClose = false
  906. highlightState = false
  907.  
  908. atr = mult2 * ta.atr(length2)
  909.  
  910. longStop = (useClose ? ta.highest(close, length2) : ta.highest(length2)) - atr
  911. longStopPrev = nz(longStop[1], longStop)
  912. longStop := close[1] > longStopPrev ? math.max(longStop, longStopPrev) : longStop
  913.  
  914. shortStop = (useClose ? ta.lowest(close, length2) : ta.lowest(length2)) + atr
  915. shortStopPrev = nz(shortStop[1], shortStop)
  916. shortStop := close[1] < shortStopPrev ? math.min(shortStop, shortStopPrev) : shortStop
  917.  
  918. var int dir = 1
  919. dir := close > shortStopPrev ? 1 : close < longStopPrev ? -1 : dir
  920.  
  921. var color longColor = color.green
  922. var color shortColor = color.red
  923.  
  924. buySignal = dir == 1 and dir[1] == -1
  925. //plotshape(buySignal and showLabels ? longStop : na, title="Gold Buy", text="Buy", location=location.belowbar, style=shape.labelup, size=size.tiny, color=longColor, textcolor=color.new(color.white, 0))
  926.  
  927. sellSignal = dir == -1 and dir[1] == 1
  928. //plotshape(sellSignal and showLabels ? shortStop : na, title="Gold Sell", text="Sell", location=location.abovebar, style=shape.labeldown, size=size.tiny, color=shortColor, textcolor=color.new(color.white, 0))
  929.  
  930. //Relative Volatility Index Divergence//////////////////////////////////////////
  931. length15 = 12
  932. src15 = close
  933. len15 = 14
  934. stddev15 = ta.stdev(src15, length15)
  935. upper15 = ta.ema(ta.change(src15) <= 0 ? 0 : stddev15, len15)
  936. lower15 = ta.ema(ta.change(src15) > 0 ? 0 : stddev15, len15)
  937. rvi = upper15 / (upper15 + lower15) * 100
  938.  
  939. //Divergence
  940. lbR15 = 2
  941. lbL15 = 6
  942. rangeUpper15 = 60
  943. rangeLower15 = 5
  944. plotBull15 = true
  945. plotHiddenBull15 = false
  946. plotBear15 = true
  947. plotHiddenBear15 = false
  948.  
  949. bearColor15 = color.red
  950. bullColor15 = color.green
  951. hiddenBullColor15 = color.green
  952. hiddenBearColor15 = color.red
  953. textColor15 = color.white
  954. noneColor15 = color.new(color.white, 100)
  955.  
  956. d15 = rvi
  957. osc15 = d15
  958.  
  959. plFound15 = na(ta.pivotlow(osc15, lbL15, lbR15)) ? false : true
  960. phFound15 = na(ta.pivothigh(osc15, lbL15, lbR15)) ? false : true
  961.  
  962. _inRange15(cond) =>
  963.     bars15 = ta.barssince(cond == true)
  964.     rangeLower15 <= bars15 and bars15 <= rangeUpper15
  965.  
  966. //Regular Bullish
  967.  
  968. //Osc: Higher Low
  969. oscHL15 = osc15[lbR15] > ta.valuewhen(plFound15, osc15[lbR15], 1) and _inRange15(plFound15[1])
  970.  
  971. //Price: Lower Low
  972. priceLL15 = low[lbR15] < ta.valuewhen(plFound15, low[lbR15], 1)
  973.  
  974. bullCond15 = plotBull15 and priceLL15 and oscHL15 and plFound15
  975. //plot(plFound15 ? osc15[lbR15] : na, offset=-lbR15, title="Regular Bullish", linewidth=2, color=(bullCond15 ? bullColor15 : noneColor15))
  976. //plotshape(bullCond15 ? osc15[lbR15] : na, offset=-lbR15, title="Regular Bullish Label", text=" Bull ", style=shape.labelup, location=location.absolute, color=bullColor15, textcolor=textColor15)
  977.  
  978. //Hidden Bullish
  979.  
  980. //Osc: Lower Low
  981. oscLL15 = osc15[lbR15] < ta.valuewhen(plFound15, osc15[lbR15], 1) and _inRange15(plFound15[1])
  982.  
  983. //Price: Higher Low
  984. priceHL15 = low[lbR15] > ta.valuewhen(plFound15, low[lbR15], 1)
  985.  
  986. hiddenBullCond15 = plotHiddenBull15 and priceHL15 and oscLL15 and plFound15
  987. //plot(plFound15 ? osc15[lbR15] : na, offset=-lbR15, title="Hidden Bullish", linewidth=2, color=(hiddenBullCond15 ? hiddenBullColor15 : noneColor15))
  988. //plotshape(hiddenBullCond15 ? osc15[lbR15] : na, offset=-lbR15, title="Hidden Bullish Label", text=" H Bull ", style=shape.labelup, location=location.absolute, color=bullColor15, textcolor=textColor15)
  989.  
  990. //Regular Bearish
  991.  
  992. //Osc: Lower High
  993. oscLH15 = osc15[lbR15] < ta.valuewhen(phFound15, osc15[lbR15], 1) and _inRange15(phFound15[1])
  994.  
  995. //Price: Higher High
  996. priceHH15 = high[lbR15] > ta.valuewhen(phFound15, high[lbR15], 1)
  997.  
  998. bearCond15 = plotBear15 and priceHH15 and oscLH15 and phFound15
  999. //plot(phFound15 ? osc15[lbR15] : na, offset=-lbR15, title="Regular Bearish", linewidth=2, color=(bearCond15 ? bearColor15 : noneColor15))
  1000. //plotshape(bearCond15 ? osc15[lbR15] : na, offset=-lbR15, title="Regular Bearish Label", text=" Bear ", style=shape.labeldown, location=location.absolute, color=bearColor15, textcolor=textColor15)
  1001.  
  1002. //Hidden Bearish
  1003.  
  1004. //Osc: Higher High
  1005. oscHH15 = osc15[lbR15] > ta.valuewhen(phFound15, osc15[lbR15], 1) and _inRange15(phFound15[1])
  1006.  
  1007. //Price: Lower High
  1008. priceLH15 = high[lbR15] < ta.valuewhen(phFound15, high[lbR15], 1)
  1009.  
  1010. hiddenBearCond15 = plotHiddenBear15 and priceLH15 and oscHH15 and phFound15
  1011. //plot(phFound15 ? osc15[lbR15] : na, offset=-lbR15, title="Hidden Bearish", linewidth=2, color=(hiddenBearCond15 ? hiddenBearColor15 : noneColor15))
  1012. //plotshape(hiddenBearCond15 ? osc15[lbR15] : na, offset=-lbR15, title="Hidden Bearish Label", text=" H Bear ", style=shape.labeldown, location=location.absolute, color=bearColor15, textcolor=textColor15)
  1013.  
  1014. //Support and Resistance////////////////////////////////////////////////////////
  1015. left16 = 200
  1016. right16 = 20
  1017. quick_right16 = 5
  1018. src16 = 'Close'
  1019.  
  1020. pivothigh_1 = ta.pivothigh(close, left16, right16)
  1021. pivothigh_2 = ta.pivothigh(high, left16, right16)
  1022. pivot_high16 = src16 == 'Close' ? pivothigh_1 : pivothigh_2
  1023. pivotlow_1 = ta.pivotlow(close, left16, right16)
  1024. pivotlow_2 = ta.pivotlow(low, left16, right16)
  1025. pivot_lows16 = src16 == 'Close' ? pivotlow_1 : pivotlow_2
  1026.  
  1027. pivothigh_3 = ta.pivothigh(close, left16, quick_right16)
  1028. pivothigh_4 = ta.pivothigh(high, left16, quick_right16)
  1029. quick_pivot_high16 = src16 == 'Close' ? pivothigh_3 : pivothigh_4
  1030. pivotlow_3 = ta.pivotlow(close, left16, quick_right16)
  1031. pivotlow_4 = ta.pivotlow(low, left16, quick_right16)
  1032. quick_pivot_lows16 = src16 == 'Close' ? pivotlow_3 : pivotlow_4
  1033.  
  1034. valuewhen_1 = ta.valuewhen(quick_pivot_high16, close[quick_right16], 0)
  1035. valuewhen_2 = ta.valuewhen(quick_pivot_high16, high[quick_right16], 0)
  1036. level1 = src16 == 'Close' ? valuewhen_1 : valuewhen_2
  1037. valuewhen_3 = ta.valuewhen(quick_pivot_lows16, close[quick_right16], 0)
  1038. valuewhen_4 = ta.valuewhen(quick_pivot_lows16, low[quick_right16], 0)
  1039. level2 = src16 == 'Close' ? valuewhen_3 : valuewhen_4
  1040. valuewhen_5 = ta.valuewhen(pivot_high16, close[right16], 0)
  1041. valuewhen_6 = ta.valuewhen(pivot_high16, high[right16], 0)
  1042. level3 = src16 == 'Close' ? valuewhen_5 : valuewhen_6
  1043. valuewhen_7 = ta.valuewhen(pivot_lows16, close[right16], 0)
  1044. valuewhen_8 = ta.valuewhen(pivot_lows16, low[right16], 0)
  1045. level4 = src16 == 'Close' ? valuewhen_7 : valuewhen_8
  1046. valuewhen_9 = ta.valuewhen(pivot_high16, close[right16], 1)
  1047. valuewhen_10 = ta.valuewhen(pivot_high16, high[right16], 1)
  1048. level5 = src16 == 'Close' ? valuewhen_9 : valuewhen_10
  1049. valuewhen_11 = ta.valuewhen(pivot_lows16, close[right16], 1)
  1050. valuewhen_12 = ta.valuewhen(pivot_lows16, low[right16], 1)
  1051. level6 = src16 == 'Close' ? valuewhen_11 : valuewhen_12
  1052. valuewhen_13 = ta.valuewhen(pivot_high16, close[right16], 2)
  1053. valuewhen_14 = ta.valuewhen(pivot_high16, high[right16], 2)
  1054. level7 = src16 == 'Close' ? valuewhen_13 : valuewhen_14
  1055. valuewhen_15 = ta.valuewhen(pivot_lows16, close[right16], 2)
  1056. valuewhen_16 = ta.valuewhen(pivot_lows16, low[right16], 2)
  1057. level8 = src16 == 'Close' ? valuewhen_15 : valuewhen_16
  1058.  
  1059. level1_col = close >= level1 ? color.green : color.red
  1060. level2_col = close >= level2 ? color.green : color.red
  1061. level3_col = close >= level3 ? color.green : color.red
  1062. level4_col = close >= level4 ? color.green : color.red
  1063. level5_col = close >= level5 ? color.green : color.red
  1064. level6_col = close >= level6 ? color.green : color.red
  1065. level7_col = close >= level7 ? color.green : color.red
  1066. level8_col = close >= level8 ? color.green : color.red
  1067.  
  1068. length17 = 9
  1069. src17 = close
  1070. hma17 = ta.wma(2 * ta.wma(src17, length17 / 2) - ta.wma(src17, length17), math.floor(math.sqrt(length17)))
  1071.  
  1072. buy1 = hma17 > level1 and hma17[1] < level1[1] and close > close[2]
  1073. buy2 = hma17 > level2 and hma17[1] < level2[1] and close > close[2]
  1074. buy3 = hma17 > level3 and hma17[1] < level3[1] and close > close[2]
  1075. buy4 = hma17 > level4 and hma17[1] < level4[1] and close > close[2]
  1076. buy5 = hma17 > level5 and hma17[1] < level5[1] and close > close[2]
  1077. buy6 = hma17 > level6 and hma17[1] < level6[1] and close > close[2]
  1078. buy7 = hma17 > level7 and hma17[1] < level7[1] and close > close[2]
  1079. buy8 = hma17 > level8 and hma17[1] < level8[1] and close > close[2]
  1080.  
  1081. sell1 = hma17 < level1 and hma17[1] > level1[1] and close < close[2]
  1082. sell2 = hma17 < level2 and hma17[1] > level2[1] and close < close[2]
  1083. sell3 = hma17 < level3 and hma17[1] > level3[1] and close < close[2]
  1084. sell4 = hma17 < level4 and hma17[1] > level4[1] and close < close[2]
  1085. sell5 = hma17 < level5 and hma17[1] > level5[1] and close < close[2]
  1086. sell6 = hma17 < level6 and hma17[1] > level6[1] and close < close[2]
  1087. sell7 = hma17 < level7 and hma17[1] > level7[1] and close < close[2]
  1088. sell8 = hma17 < level8 and hma17[1] > level8[1] and close < close[2]
  1089.  
  1090.  
  1091. //END▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲
  1092. ////////////////////////////////////////////////////////////////////////////////
  1093. //VOLUME INDICATORS▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼
  1094.  
  1095. //OBV Divergence////////////////////////////////////////////////////////////////
  1096. len18 = 20
  1097. src18 = close
  1098. lbR18 = 2
  1099. lbL18 = 6
  1100. rangeUpper18 = 60
  1101. rangeLower18 = 5
  1102. plotBull18 = true
  1103. plotHiddenBull18 = false
  1104. plotBear18 = true
  1105. plotHiddenBear18 = false
  1106.  
  1107.  
  1108. bearColor18 = color.red
  1109. bullColor18 = color.green
  1110. hiddenBullColor18 = color.green
  1111. hiddenBearColor18 = color.new(color.red, 80)
  1112. textColor18 = color.white
  1113. noneColor18 = color.new(color.white, 100)
  1114.  
  1115. csrc = ta.change(src18)
  1116. obv1(src18) =>
  1117.     ta.cum(ta.change(src18) > 0 ? volume : csrc < 0 ? -volume : 0 * volume)
  1118.  
  1119. _inRange(cond) =>
  1120.     bars = ta.barssince(cond == true)
  1121.     rangeLower18 <= bars and bars <= rangeUpper18
  1122.  
  1123. //Chaikin Money Flow////////////////////////////////////////////////////////////
  1124. length19 = 50
  1125. ad19 = close == high and close == low or high == low ? 0 : (2 * close - low - high) / (high - low) * volume
  1126. cmf = math.sum(ad19, length19) / math.sum(volume, length19)
  1127. //plot(cmf, color=#43A047, title="MF")
  1128. //hline(0, color=#787B86, title="Zero", linestyle=hline.style_dashed)
  1129.  
  1130. //VWAP//////////////////////////////////////////////////////////////////////////
  1131. computeVWAP(src20, isNewPeriod, stDevMultiplier) =>
  1132.     var float sumSrcVol = na
  1133.     var float sumVol = na
  1134.     var float sumSrcSrcVol = na
  1135.  
  1136.     sumSrcVol := isNewPeriod ? src20 * volume : src20 * volume + sumSrcVol[1]
  1137.     sumVol := isNewPeriod ? volume : volume + sumVol[1]
  1138.     // sumSrcSrcVol calculates the dividend of the equation that is later used to calculate the standard deviation
  1139.     sumSrcSrcVol := isNewPeriod ? volume * math.pow(src20, 2) : volume * math.pow(src20, 2) + sumSrcSrcVol[1]
  1140.  
  1141.     _vwap = sumSrcVol / sumVol
  1142.     variance = sumSrcSrcVol / sumVol - math.pow(_vwap, 2)
  1143.     variance := variance < 0 ? 0 : variance
  1144.     stDev = math.sqrt(variance)
  1145.  
  1146.     lowerBand20 = _vwap - stDev * stDevMultiplier
  1147.     upperBand20 = _vwap + stDev * stDevMultiplier
  1148.  
  1149.     [_vwap, lowerBand20, upperBand20]
  1150.  
  1151. hideonDWM = false
  1152. var anchor = 'Session'
  1153. src20 = hlc3
  1154. offset20 = 0
  1155.  
  1156. showBands = true
  1157. stdevMult = 1.0
  1158.  
  1159. timeChange(period) =>
  1160.     ta.change(time(period))
  1161.  
  1162. new_earnings = request.earnings(syminfo.tickerid, earnings.actual, barmerge.gaps_on, barmerge.lookahead_on)
  1163. new_dividends = request.dividends(syminfo.tickerid, dividends.gross, barmerge.gaps_on, barmerge.lookahead_on)
  1164. new_split = request.splits(syminfo.tickerid, splits.denominator, barmerge.gaps_on, barmerge.lookahead_on)
  1165.  
  1166. tcD = timeChange('D')
  1167. tcW = timeChange('W')
  1168. tcM = timeChange('M')
  1169. tc3M = timeChange('3M')
  1170. tc12M = timeChange('12M')
  1171.  
  1172. isNewPeriod = anchor == 'Earnings' ? new_earnings : anchor == 'Dividends' ? new_dividends : anchor == 'Splits' ? new_split : na(src20[1]) ? true : anchor == 'Session' ? tcD : anchor == 'Week' ? tcW : anchor == 'Month' ? tcM : anchor == 'Quarter' ? tc3M : anchor == 'Year' ? tc12M : anchor == 'Decade' ? tc12M and year % 10 == 0 : anchor == 'Century' ? tc12M and year % 100 == 0 : false
  1173.  
  1174. float vwapValue = na
  1175. float std = na
  1176. float upperBandValue = na
  1177. float lowerBandValue = na
  1178.  
  1179. if not(hideonDWM and timeframe.isdwm)
  1180.     [_vwap, bottom, top] = computeVWAP(src20, isNewPeriod, stdevMult)
  1181.     vwapValue := _vwap
  1182.     upperBandValue := showBands ? top : na
  1183.     lowerBandValue := showBands ? bottom : na
  1184.     lowerBandValue
  1185.  
  1186. //Candle Patterns///////////////////////////////////////////////////////////////
  1187.  
  1188. //Bullish Engulfing
  1189. C_DownTrend = true
  1190. C_UpTrend = true
  1191. var trendRule1 = 'SMA50'
  1192. var trendRule2 = 'SMA50, SMA200'
  1193. var trendRule = trendRule1
  1194.  
  1195. if trendRule == trendRule1
  1196.     priceAvg = ta.sma(close, 50)
  1197.     C_DownTrend := close < priceAvg
  1198.     C_UpTrend := close > priceAvg
  1199.     C_UpTrend
  1200.  
  1201. if trendRule == trendRule2
  1202.     sma200 = ta.sma(close, 200)
  1203.     sma50 = ta.sma(close, 50)
  1204.     C_DownTrend := close < sma50 and sma50 < sma200
  1205.     C_UpTrend := close > sma50 and sma50 > sma200
  1206.     C_UpTrend
  1207. C_Len = 14  // ema depth for bodyAvg
  1208. C_ShadowPercent = 5.0  // size of shadows
  1209. C_ShadowEqualsPercent = 100.0
  1210. C_DojiBodyPercent = 5.0
  1211. C_Factor = 2.0  // shows the number of times the shadow dominates the candlestick body
  1212.  
  1213. C_BodyHi = math.max(close, open)
  1214. C_BodyLo = math.min(close, open)
  1215. C_Body = C_BodyHi - C_BodyLo
  1216. C_BodyAvg = ta.ema(C_Body, C_Len)
  1217. C_SmallBody = C_Body < C_BodyAvg
  1218. C_LongBody = C_Body > C_BodyAvg
  1219. C_UpShadow = high - C_BodyHi
  1220. C_DnShadow = C_BodyLo - low
  1221. C_HasUpShadow = C_UpShadow > C_ShadowPercent / 100 * C_Body
  1222. C_HasDnShadow = C_DnShadow > C_ShadowPercent / 100 * C_Body
  1223. C_WhiteBody = open < close
  1224. C_BlackBody = open > close
  1225. C_Range = high - low
  1226. C_IsInsideBar = C_BodyHi[1] > C_BodyHi and C_BodyLo[1] < C_BodyLo
  1227. C_BodyMiddle = C_Body / 2 + C_BodyLo
  1228. C_ShadowEquals = C_UpShadow == C_DnShadow or math.abs(C_UpShadow - C_DnShadow) / C_DnShadow * 100 < C_ShadowEqualsPercent and math.abs(C_DnShadow - C_UpShadow) / C_UpShadow * 100 < C_ShadowEqualsPercent
  1229. C_IsDojiBody = C_Range > 0 and C_Body <= C_Range * C_DojiBodyPercent / 100
  1230. C_Doji = C_IsDojiBody and C_ShadowEquals
  1231.  
  1232. patternLabelPosLow = low - ta.atr(30) * 0.6
  1233. patternLabelPosHigh = high + ta.atr(30) * 0.6
  1234.  
  1235. label_color_bullish = color.blue
  1236. C_EngulfingBullishNumberOfCandles = 2
  1237. C_EngulfingBullish = C_DownTrend and C_WhiteBody and C_LongBody and C_BlackBody[1] and C_SmallBody[1] and close >= open[1] and open <= close[1] and (close > open[1] or open < close[1])
  1238. if C_EngulfingBullish
  1239.     var ttBullishEngulfing = 'Engulfing\nAt the end of a given downward trend, there will most likely be a reversal pattern. To distinguish the first day, this candlestick pattern uses a small body, followed by a day where the candle body fully overtakes the body from the day before, and closes in the trend’s opposite direction. Although similar to the outside reversal chart pattern, it is not essential for this pattern to completely overtake the range (high to low), rather only the open and the close.'
  1240.     ttBullishEngulfing
  1241.     //label.new(bar_index, patternLabelPosLow, text="BE", style=label.style_label_up, color = label_color_bullish, textcolor=color.white, tooltip = ttBullishEngulfing)
  1242. //bgcolor(highest(C_EngulfingBullish?1:0, C_EngulfingBullishNumberOfCandles)!=0 ? color.blue : na, offset=-(C_EngulfingBullishNumberOfCandles-1))
  1243.  
  1244. //Bearish Engulfing
  1245. label_color_bearish = color.red
  1246. C_EngulfingBearishNumberOfCandles = 2
  1247. C_EngulfingBearish = C_UpTrend and C_BlackBody and C_LongBody and C_WhiteBody[1] and C_SmallBody[1] and close <= open[1] and open >= close[1] and (close < open[1] or open > close[1])
  1248. if C_EngulfingBearish
  1249.     var ttBearishEngulfing = 'Engulfing\nAt the end of a given uptrend, a reversal pattern will most likely appear. During the first day, this candlestick pattern uses a small body. It is then followed by a day where the candle body fully overtakes the body from the day before it and closes in the trend’s opposite direction. Although similar to the outside reversal chart pattern, it is not essential for this pattern to fully overtake the range (high to low), rather only the open and the close.'
  1250.     ttBearishEngulfing
  1251.     //label.new(bar_index, patternLabelPosHigh, text="BE", style=label.style_label_down, color = label_color_bearish, textcolor=color.white, tooltip = ttBearishEngulfing)
  1252. //bgcolor(highest(C_EngulfingBearish?1:0, C_EngulfingBearishNumberOfCandles)!=0 ? color.red : na, offset=-(C_EngulfingBearishNumberOfCandles-1))
  1253.  
  1254. //END▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲
  1255. ////////////////////////////////////////////////////////////////////////////////
  1256. //SIGNAL SCORES▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼
  1257.  
  1258. //Alternate Signals Option
  1259. alternatesignals = input(title='Alternate Signals', defval=true)
  1260.  
  1261. //Position Options
  1262. longpositions = input(title='Long Positions', defval=true)
  1263. shortpositions = input(title='Short Positions', defval=true)
  1264.  
  1265. //Stop Loss Warning Option
  1266. stoplosspercent = input.float(title='Stop Loss Warning (%)', defval=-2.5, minval=-50, maxval=0, step=.1) / 100
  1267.  
  1268. //Score Requirements
  1269. stronglongscore = input.int(defval=10, minval=0, maxval=1000, title='Required Strong LONG Score')
  1270. strongshortscore = input.int(defval=10, minval=0, maxval=1000, title='Required Strong SHORT Score')
  1271. weaklongscore = input.int(defval=8, minval=0, maxval=1000, title='Required Weak LONG Score')
  1272. weakshortscore = input.int(defval=8, minval=0, maxval=1000, title='Required Weak SHORT Score')
  1273.  
  1274. ////////////////////////////////////////////////////////////////////////////////
  1275. //STOP LOSS WARNINGS▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼
  1276.  
  1277. //Stop Loss Criteria
  1278. longstoploss = strategy.position_avg_price * (1 + stoplosspercent)
  1279. shortstoploss = strategy.position_avg_price * (1 - stoplosspercent)
  1280. printstoplong = longstoploss > close and longstoploss[1] < close[1] and strategy.position_size > 0
  1281. printstopshort = shortstoploss < close and shortstoploss[1] > close[1] and strategy.position_size < 0
  1282.  
  1283. ////////////////////////////////////////////////////////////////////////////
  1284. //END▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲
  1285. ////////////////////////////////////////////////////////////////////////////////
  1286. // Alerts
  1287. // to automate put this in trendinview message:     {{strategy.order.alert_message}}
  1288. i_alert_txt_entry_long = input.text_area(defval = "", title = "Long Entry Message", group = "Alerts")
  1289. i_alert_txt_exit_long = input.text_area(defval = "", title = "Long Exit Message", group = "Alerts")
  1290. i_alert_txt_entry_short = input.text_area(defval = "", title = "Short Entry Message", group = "Alerts")
  1291. i_alert_txt_exit_short = input.text_area(defval = "", title = "Short Exit Message", group = "Alerts")
  1292. i_alert_txt_TP_long = input.text_area(defval = "", title = "Long TP Message", group = "Alerts")
  1293. i_alert_txt_TP_short = input.text_area(defval = "", title = "Short TP Message", group = "Alerts")
  1294. i_alert_txt_SL_long = input.text_area(defval = "", title = "Long SL Message", group = "Alerts")
  1295. i_alert_txt_SL_short = input.text_area(defval = "", title = "Short SL Message", group = "Alerts")
  1296.  
  1297.  
  1298. // Entries and Exits with TP/SL
  1299. if bull
  1300.     //strategy.close("Short" , alert_message = i_alert_txt_exit_short)
  1301.     strategy.entry("Long" , strategy.long , alert_message = i_alert_txt_entry_long)
  1302.     strategy.exit("Take Profit", from_entry = "Long", limit = tp1_y , qty_percent = 100)//, alert_message = i_alert_txt_TP_long)
  1303.     strategy.exit("Stop Loss", from_entry = "Long", loss = stop_y)//, alert_message = i_alert_txt_SL_long)
  1304.  
  1305. if bear
  1306.     //strategy.close("Long" , alert_message = i_alert_txt_exit_long)
  1307.     strategy.entry("Short" , strategy.short, alert_message = i_alert_txt_entry_short)
  1308.     strategy.exit("Take Profit", from_entry = "Short", limit = tp1_y , qty_percent = 100)//, alert_message = i_alert_txt_TP_short)
  1309.     strategy.exit("Stop Loss", from_entry = "Short", loss = stop_y)//, alert_message = i_alert_txt_SL_short)
  1310. ////////////////////////////////////////////////////////////////////////////////
Comments
Add Comment
Please, Sign In to add comment