Advertisement
Guest User

Untitled

a guest
Jun 1st, 2024
279
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.42 KB | None | 1 0
  1. /// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © BrookstarNZ-"CRYPTO SLAYA"
  3.  
  4. /// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  5. // © Crypto_Wolf_Traders
  6.  
  7.  
  8. //@version=5
  9. strategy("Slaya-Wolf-SuperScalper-Veins-V8", overlay=true, max_labels_count=500, default_qty_type = strategy.percent_of_equity, default_qty_value = 25, initial_capital = 500)
  10. ///////////////////////////////////////////////////////////////////////////////
  11. //-----------------------CRYPTO SLAYA-CRYPTO-WOLF-TRADERS---------------------//
  12. ///////////////////////////////////////////////////////////////////////////////
  13. // SIGNAL MEANINGS//
  14. //"Buy Label" = Strong Buy//
  15. //"Sell Label" = Strong Sell//
  16. //"Don't Long" = Green Cross//
  17. //"Don't Short" = Red Cross//
  18. //"Weak Buy " = Green Circle//
  19. //"Weak Sell" = Red Circle//
  20. //"Reversal Buy" = Green Diamond//
  21. //"Reversal Sell" = Red Diamond//
  22.  
  23. // Get user settings
  24. res = input.timeframe(title='TIMEFRAME', defval='1h', group ="NON REPAINT HA")
  25. showBuySell = input(true, "BUY/SELL SIGNALS ON/OFF", group="BUY & SELL SIGNALS")
  26. sensitivity = input.float(2.7, "SENSITIVITY (1-6)", 0.1, 10, group="BUY & SELL SIGNALS")
  27. percentStop = input.float(1.0, "STOP LOSS %", 0, group="BUY & SELL SIGNALS")
  28. percentTake = input.float(0.2, "TAKE PROFIT %", 0, group="BUY & SELL SIGNALS")
  29. percentTake2 = input.float(0.4, "TAKE PROFIT2 %", 0, group="BUY & SELL SIGNALS")
  30. percentTake3 = input.float(0.6, "TAKE PROFIT3 %", 0, group="BUY & SELL SIGNALS")
  31. percentTake4 = input.float(0.8, "TAKE PROFIT4 %", 0, group="BUY & SELL SIGNALS")
  32. percentTake5 = input.float(1, "TAKE PROFIT5 %", 0, group="BUY & SELL SIGNALS")
  33. //Strong Buy/Sell
  34. showStrongBuySell = input(true, "STRONG BUY/SELL SIGNALS ON/OFF", group="STRONG BUY & SELL SIGNALS")
  35. sensitivity2 = input.float(13, "SENSITIVITY", 0.1, 20, group="STRONG BUY & SELL SIGNALS")
  36. percentStrongStop = input.float(1.0, "STOP LOSS %", 0)
  37. percentStrongTake = input.float(0.2, "TAKE PROFIT %", 0)
  38. percentStrongTake2 = input.float(0.4, "TAKE PROFIT2 %", 0)
  39. percentStrongTake3 = input.float(0.6, "TAKE PROFIT3 %", 0)
  40. percentStrongTake4 = input.float(0.8, "TAKE PROFIT4 %", 0)
  41. percentStrongTake5 = input.float(1, "TAKE PROFIT5 %", 0)
  42.  
  43. offsetSignal = input.float(1, "SIGNAL OFFSET", 0, group="BUY & SELL SIGNALS")
  44. showReversal = input(true, "REVERSAL SIGNALS ON/OFF", group="BUY & SELL SIGNALS")
  45. // Entry & Exit
  46. enableE = input(false, "EXIT & ENTRY ON/OFF", group="EXIT & ENTRY")
  47. //Stop = input.color(color.new(#83868f, 5), "STOP LOSS", group="EXIT & ENTRY")
  48. Entry = input.color(color.new(#8d020e, 5), "ENTRY", group="EXIT & ENTRY")
  49. Tp1 = input.color(color.new(#038007, 5), "TAKE PROFIT", group="EXIT & ENTRY")
  50. // Supply & Demand
  51. enableSD = input(true, "SUPPLY & DEMAND ON/OFF", group="SUPPLY & DEMAND")
  52. mitigation = input.string('Wick', 'MITIGATION', options = ['Wick', 'Close'], group ="SUPPLY & DEMAND")
  53. length = input.int(20, 'VOLUME PIVOT', minval = 1, group ="SUPPLY & DEMAND")
  54. bull_ext_last = input.int(1, 'DEMAND', minval = 1, inline = 'bull', group ="SUPPLY & DEMAND")
  55. bull_avg_css = input.color(color.new(#00dbff, 1), '', inline = 'bull', group ="SUPPLY & DEMAND")
  56. bull_css = input.color(color.new(#00000000, 100), '', inline = 'bull', group ="SUPPLY & DEMAND")
  57. bg_bull_css = input.color(color.new(#00ff0a, 90), '', inline = 'bull', group ="SUPPLY & DEMAND")
  58. bear_ext_last = input.int(1, 'SUPPLY', minval = 1 , inline = 'bear', group ="SUPPLY & DEMAND")
  59. bear_avg_css = input.color(color.new(#E91E63, 1), '', inline = 'bear', group ="SUPPLY & DEMAND")
  60. bear_css = input.color(color.new(#00000000, 100), '', inline = 'bear', group ="SUPPLY & DEMAND")
  61. bg_bear_css = input.color(color.new(#ff0015, 90), '', inline = 'bear', group ="SUPPLY & DEMAND")
  62. line_style = input.string("Solid", "LINE STYLE", ["Solid", "Dotted", "Dashed"], group ="SUPPLY & DEMAND")
  63. line_width = input.int(2, 'LINE WIDTH', minval = 1, group ="SUPPLY & DEMAND")
  64. // Support & Resistance
  65. enableSR = input(true, "SUPPORT & RESISTANCE ON/Off", group="SUPPORT & RESISTANCE")
  66. colorSup = input(#00dbff, "SUPPORT", group="SUPPORT & RESISTANCE")
  67. colorRes = input(#E91E63, "RESISTANCE", group="SUPPORT & RESISTANCE")
  68. strengthSR = input.int(6, "S/R STRENGTH", 1, group="SUPPORT & RESISTANCE")
  69. lineStyle1 = input.string("Solid", "LINE STYLE", ["Solid", "Dotted", "Dashed"], group="SUPPORT & RESISTANCE")
  70. lineWidth1 = input.int(2, "LINE WIDTH", 1, group="SUPPORT & RESISTANCE")
  71. expandSR = input(true, "EXTEND LINES", group = "SUPPORT & RESISTANCE")
  72. useZones = input(true, "ZONE ON/OFF", group="SUPPORT & RESISTANCE")
  73. useHLZones = input(true, "HIGH LOW ZONES ON/OFF", group="SUPPORT & RESISTANCE")
  74. 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")
  75. // Trend Table
  76. showDashboard = input(true, "TeiwazTrading ON/OFF", group="TeiwazTrading DASHBOARD")
  77. locationDashboard = input.string("Top Right", "Table Location", ["Top Right", "Middle Right", "Bottom Right", "Top Center", "Middle Center", "Bottom Center", "Top Left", "Middle Left", "Bottom Left"], group="TREND DASHBOARD")
  78. tableTextColor = input(color.rgb(236, 233, 233), "TEXT", group="TeiwazTrading DASHBOARD")
  79. tableBgColor = input(color.black, "BACKGROUND", group="TeiwazTrading DASHBOARD")
  80. sizeDashboard = input.string("Small", "TABLE SIZE", ["Large", "Normal", "Small", "Tiny"], group="TeiwazTrading DASHBOARD")
  81. showPdHlc = input(false, "PREVIOUS DAY H/L/C", group="PREVIOUS DAY HIGH LOW CLOSE")
  82. lineColor = input.color(#028a07, "LINE COLORS", group="PREVIOUS DAY HIGH LOW CLOSE")
  83. lineStyle = input.string("Solid", "LINE STYLE", ["Solid", "Dotted", "Dashed"], group ="PREVIOUS DAY HIGH LOW CLOSE")
  84. lineWidth = input.int(1, "LINE WIDTH", group="PREVIOUS DAY HIGH LOW CLOSE")
  85.  
  86. // Create non-repainting security function
  87. rp_security(_symbol, _res, _src) =>
  88. request.security(_symbol, _res, _src[barstate.isrealtime ? 1 : 0])
  89.  
  90. htfHigh = rp_security(syminfo.tickerid, res, high)
  91. htfLow = rp_security(syminfo.tickerid, res, low)
  92.  
  93. // Main Indicator
  94. // Functions
  95. smoothrng(x, t, m) =>
  96. wper = t * 2 - 1
  97. avrng = ta.ema(math.abs(x - x[1]), t)
  98. smoothrng = ta.ema(avrng, wper) * m
  99. rngfilt(x, r) =>
  100. rngfilt = x
  101. 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
  102. percWidth(len, perc) => (ta.highest(len) - ta.lowest(len)) * perc / 100
  103. securityNoRep(sym, res, src) => request.security(sym, res, src, barmerge.gaps_off, barmerge.lookahead_on)
  104. swingPoints(prd) =>
  105. pivHi = ta.pivothigh(prd, prd)
  106. pivLo = ta.pivotlow (prd, prd)
  107. last_pivHi = ta.valuewhen(pivHi, pivHi, 1)
  108. last_pivLo = ta.valuewhen(pivLo, pivLo, 1)
  109. hh = pivHi and pivHi > last_pivHi ? pivHi : na
  110. lh = pivHi and pivHi < last_pivHi ? pivHi : na
  111. hl = pivLo and pivLo > last_pivLo ? pivLo : na
  112. ll = pivLo and pivLo < last_pivLo ? pivLo : na
  113. [hh, lh, hl, ll]
  114. f_chartTfInMinutes() =>
  115. float _resInMinutes = timeframe.multiplier * (
  116. timeframe.isseconds ? 1 :
  117. timeframe.isminutes ? 1. :
  118. timeframe.isdaily ? 60. * 24 :
  119. timeframe.isweekly ? 60. * 24 * 7 :
  120. timeframe.ismonthly ? 60. * 24 * 30.4375 : na)
  121. f_kc(src, len, sensitivity) =>
  122. basis = ta.sma(src, len)
  123. span = ta.atr(len)
  124. [basis + span * sensitivity, basis - span * sensitivity]
  125. wavetrend(src, chlLen, avgLen) =>
  126. esa = ta.ema(src, chlLen)
  127. d = ta.ema(math.abs(src - esa), chlLen)
  128. ci = (src - esa) / (0.015 * d)
  129. wt1 = ta.ema(ci, avgLen)
  130. wt2 = ta.sma(wt1, 3)
  131. [wt1, wt2]
  132. f_top_fractal(src) => src[4] < src[2] and src[3] < src[2] and src[2] > src[1] and src[2] > src[0]
  133. f_bot_fractal(src) => src[4] > src[2] and src[3] > src[2] and src[2] < src[1] and src[2] < src[0]
  134. f_fractalize (src) => f_top_fractal(src) ? 1 : f_bot_fractal(src) ? -1 : 0
  135. f_findDivs(src, topLimit, botLimit) =>
  136. fractalTop = f_fractalize(src) > 0 and src[2] >= topLimit ? src[2] : na
  137. fractalBot = f_fractalize(src) < 0 and src[2] <= botLimit ? src[2] : na
  138. highPrev = ta.valuewhen(fractalTop, src[2], 0)[2]
  139. highPrice = ta.valuewhen(fractalTop, high[2], 0)[2]
  140. lowPrev = ta.valuewhen(fractalBot, src[2], 0)[2]
  141. lowPrice = ta.valuewhen(fractalBot, low[2], 0)[2]
  142. bearSignal = fractalTop and high[1] > highPrice and src[1] < highPrev
  143. bullSignal = fractalBot and low[1] < lowPrice and src[1] > lowPrev
  144. [bearSignal, bullSignal]
  145.  
  146. // Get components
  147. source = input(close, title = "Smoothring Source", group = "Smoothing")
  148. smrng1_input= input.int(200, "Smring1", 1, 200 , 1 , group = "Smoothing")
  149. smrng1_sens = input.float(defval = 13.0,title = "sens",minval = 0.1, maxval = 50 , step = 0.01 , group = "Smoothing")
  150. smrng2_input= input.int(32, "Smring2", 1, 500 , 1 , group = "Smoothing")
  151. smrng1 = smoothrng(source, smrng1_input, smrng1_sens)
  152. smrng2 = smoothrng(source, smrng2_input, sensitivity)
  153. smrng = (smrng1 + smrng2) / 2
  154. filt = rngfilt(source, smrng)
  155. up = 0.0, up := filt > filt[1] ? nz(up[1]) + 1 : filt < filt[1] ? 0 : nz(up[1])
  156. dn = 0.0, dn := filt < filt[1] ? nz(dn[1]) + 1 : filt > filt[1] ? 0 : nz(dn[1])
  157. bullCond = bool(na), bullCond := source > filt and source > source[1] and up > 0 or source > filt and source < source[1] and up > 0
  158. bearCond = bool(na), bearCond := source < filt and source < source[1] and dn > 0 or source < filt and source > source[1] and dn > 0
  159. lastCond = 0, lastCond := bullCond ? 1 : bearCond ? -1 : lastCond[1]
  160. bull = bullCond and lastCond[1] == -1
  161. bear = bearCond and lastCond[1] == 1
  162. smrng3 = smoothrng(source, smrng2_input, sensitivity2)
  163. smrngstrong = (smrng1 + smrng3) / 2
  164. filt2 = rngfilt(source, smrngstrong)
  165. up2 = 0.0, up2 := filt2 > filt2[1] ? nz(up2[1]) + 1 : filt2 < filt2[1] ? 0 : nz(up2[1])
  166. dn2 = 0.0, dn2 := filt2 < filt2[1] ? nz(dn2[1]) + 1 : filt2 > filt2[1] ? 0 : nz(dn2[1])
  167. strongbullCond = bool(na), strongbullCond := source > filt2 and source > source[1] and up2 > 0 or source > filt2 and source < source[1] and up2 > 0
  168. strongbearCond = bool(na), strongbearCond := source < filt2 and source < source[1] and dn2 > 0 or source < filt2 and source > source[1] and dn2 > 0
  169. lastCond2 = 0, lastCond2 := strongbullCond ? 1 : strongbearCond ? -1 : lastCond2[1]
  170. strongbull = strongbullCond and lastCond2[1] == -1
  171. strongbear = strongbearCond and lastCond2[1] == 1
  172. countBull = ta.barssince(bull)
  173. countBear = ta.barssince(bear)
  174. countStrongBull = ta.barssince(strongbull)
  175. countStrongBear = ta.barssince(strongbear)
  176. trigger = nz(countBull, bar_index) < nz(countBear, bar_index) ? 1 : 0
  177. rsi = ta.rsi(close, 28)
  178. rsiOb = rsi > 68 and rsi > ta.ema(rsi, 10)
  179. rsiOs = rsi < 28 and rsi < ta.ema(rsi, 10)
  180. dHigh = securityNoRep(syminfo.tickerid, "D", high [1])
  181. dLow = securityNoRep(syminfo.tickerid, "D", low [1])
  182. dClose = securityNoRep(syminfo.tickerid, "D", close[1])
  183. ema = ta.ema(close, 144)
  184. emaBull = close > ema
  185. equal_tf(res) => str.tonumber(res) == f_chartTfInMinutes() and not timeframe.isseconds
  186. higher_tf(res) => str.tonumber(res) > f_chartTfInMinutes() or timeframe.isseconds
  187. too_small_tf(res) => (timeframe.isweekly and res=="1") or (timeframe.ismonthly and str.tonumber(res) < 10)
  188. securityNoRep1(sym, res, src) =>
  189. bool bull_ = na
  190. bull_ := equal_tf(res) ? src : bull_
  191. bull_ := higher_tf(res) ? request.security(sym, res, src, barmerge.gaps_off, barmerge.lookahead_on) : bull_
  192. 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)
  193. if array.size(bull_array) > 1 and not equal_tf(res) and not higher_tf(res)
  194. bull_ := array.pop(bull_array)
  195. array.clear(bull_array)
  196. bull_
  197. TF1Bull = securityNoRep1(syminfo.tickerid, "1" , emaBull)
  198. TF3Bull = securityNoRep1(syminfo.tickerid, "3" , emaBull)
  199. TF5Bull = securityNoRep1(syminfo.tickerid, "5" , emaBull)
  200. TF15Bull = securityNoRep1(syminfo.tickerid, "15" , emaBull)
  201. TF30Bull = securityNoRep1(syminfo.tickerid, "30" , emaBull)
  202. TF60Bull = securityNoRep1(syminfo.tickerid, "60" , emaBull)
  203. TF120Bull = securityNoRep1(syminfo.tickerid, "120" , emaBull)
  204. TF240Bull = securityNoRep1(syminfo.tickerid, "240" , emaBull)
  205. TF480Bull = securityNoRep1(syminfo.tickerid, "480" , emaBull)
  206. TFDBull = securityNoRep1(syminfo.tickerid, "1440", emaBull)
  207. [wt1, wt2] = wavetrend(close, 5, 10)
  208. [wtDivBear1, wtDivBull1] = f_findDivs(wt2, 15, -40)
  209. [wtDivBear2, wtDivBull2] = f_findDivs(wt2, 45, -65)
  210. wtDivBull = wtDivBull1 or wtDivBull2
  211. wtDivBear = wtDivBear1 or wtDivBear2
  212.  
  213.  
  214. // Colors
  215. white = #00e4fd, white30 = color.new(white, 100)
  216. blue = #fd00a4, blue30 = color.new(blue, 100)
  217. whiteish = #ffffff, whiteish30 = color.new(whiteish , 100)
  218.  
  219. // Plot
  220. off = percWidth(300, offsetSignal)
  221. barcolor(up > dn ? white : blue)
  222. plotshape(showBuySell and bull ? low - off : na, "Buy Label" , shape.labelup , location.absolute, color(#028a14), 0, "Buy" , color.white, size=size.tiny)
  223. plotshape(showBuySell and bear ? high + off : na, "Sell Label", shape.labeldown, location.absolute, color(#8b010d), 0, "Sell", color.white, size=size.tiny)
  224. plotshape(showStrongBuySell and strongbull ? low - off : na, "Strong Buy Label" , shape.labelup , location.absolute, color(#028a14), 0, "Strong-Buy" , color.white, size=size.tiny)
  225. plotshape(showStrongBuySell and strongbear ? high + off : na, "Strong Sell Label", shape.labeldown, location.absolute, color(#8b010d), 0, "Strong-Sell", color.white, size=size.tiny)
  226. plotshape(ta.crossover(wt1, wt2) and wt2 <= -53, "Don't Sell/Bottom" , shape.xcross, location.belowbar, color(#fd0015), size=size.tiny)
  227. plotshape(ta.crossunder(wt1, wt2) and wt2 >= 53, "Don't Buy/Top", shape.xcross, location.abovebar, color(#00ff22), size=size.tiny)
  228. plotshape(wtDivBull, "Weak Buy ", shape.circle , location.belowbar, color(#00ff22), size=size.auto)
  229. plotshape(wtDivBear, "Weak Sell", shape.circle, location.abovebar, color(#fd0015), size=size.auto)
  230. plotshape(showReversal and rsiOs, "Reversal Buy" , shape.diamond, location.belowbar, color(#00ff22), size=size.tiny)
  231. plotshape(showReversal and rsiOb, "Reversal Sell", shape.diamond, location.abovebar, color(#fd0015), size=size.tiny)
  232.  
  233. srcStop = close
  234. atrBand = srcStop * (percentStop / 700)
  235. atrBand2 = srcStop * (percentTake / 100)
  236. atrBand3 = srcStop * (percentTake2 / 100)
  237. atrBand4 = srcStop * (percentTake3 / 100)
  238. atrBand5 = srcStop * (percentTake4 / 100)
  239. atrBand6 = srcStop * (percentTake5 / 100)
  240. atrStop = trigger ? srcStop - atrBand : srcStop + atrBand
  241. atrTake = trigger ? srcStop - atrBand2 : srcStop + atrBand2
  242. atrTake2 = trigger ? srcStop - atrBand3 : srcStop + atrBand3
  243. atrTake3 = trigger ? srcStop - atrBand4 : srcStop + atrBand4
  244. atrTake4 = trigger ? srcStop - atrBand5 : srcStop + atrBand5
  245. atrTake5 = trigger ? srcStop - atrBand6 : srcStop + atrBand6
  246. lastTrade(src) => ta.valuewhen(bull or bear, src, 0)
  247. entry_y = lastTrade(srcStop)
  248. stop_y = lastTrade(atrStop)
  249. tp1_y = (entry_y - lastTrade(atrTake)) + entry_y
  250. tp2_y = (entry_y - lastTrade(atrTake2)) + entry_y
  251. tp3_y = (entry_y - lastTrade(atrTake3)) + entry_y
  252. tp4_y = (entry_y - lastTrade(atrTake4)) + entry_y
  253. tp5_y = (entry_y - lastTrade(atrTake5)) + entry_y
  254.  
  255. // Labels
  256. labelTpSl(y, txt, color) =>
  257. 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
  258. label.delete(labelTpSl[1])
  259. //labelTpSl(entry_y, "Entry: " + str.tostring(math.round_to_mintick(entry_y)), color = Entry)
  260. //labelTpSl(stop_y , "StopLoss: " + str.tostring(math.round_to_mintick(stop_y)), color = Stop)
  261. labelTpSl(tp1_y, "Take Profit 1: " + str.tostring(math.round_to_mintick(tp1_y)), color = Tp1)
  262. labelTpSl(tp2_y, "Take Profit 2: " + str.tostring(math.round_to_mintick(tp2_y)), color = Tp1)
  263. labelTpSl(tp3_y, "Take Profit 3: " + str.tostring(math.round_to_mintick(tp3_y)), color = Tp1)
  264. labelTpSl(tp4_y, "Take Profit 4: " + str.tostring(math.round_to_mintick(tp4_y)), color = Tp1)
  265. labelTpSl(tp5_y, "Take Profit 5: " + str.tostring(math.round_to_mintick(tp5_y)), color = Tp1)
  266. lineTpSl(y, color) =>
  267. 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
  268. line.delete(lineTpSl[1])
  269. //lineTpSl(entry_y, color = Entry)
  270. //lineTpSl(stop_y, color = Stop)
  271. lineTpSl(tp1_y, color = Tp1)
  272. lineTpSl(tp2_y, color = Tp1)
  273. lineTpSl(tp3_y, color = Tp1)
  274. lineTpSl(tp4_y, color = Tp1)
  275. lineTpSl(tp5_y, color = Tp1)
  276.  
  277. // SUPPLY & DEMAND
  278. //Functions
  279.  
  280. //Line Style function
  281. get_line_style(style) =>
  282. out = switch style
  283. 'Solid' => line.style_solid
  284. 'Dashed' => line.style_dashed
  285. 'Dotted' => line.style_dotted
  286.  
  287. //Function to get order block coordinates
  288. get_coordinates(condition, top, btm, ob_val)=>
  289. var ob_top = array.new_float(0)
  290. var ob_btm = array.new_float(0)
  291. var ob_avg = array.new_float(0)
  292. var ob_left = array.new_int(0)
  293.  
  294. float ob = na
  295.  
  296. //Append coordinates to arrays
  297. if condition and enableSD
  298. avg = math.avg(top, btm)
  299.  
  300. array.unshift(ob_top, top)
  301. array.unshift(ob_btm, btm)
  302. array.unshift(ob_avg, avg)
  303. array.unshift(ob_left, time[length])
  304.  
  305. ob := ob_val
  306.  
  307. [ob_top, ob_btm, ob_avg, ob_left, ob]
  308.  
  309. //Function to remove mitigated order blocks from coordinate arrays
  310. remove_mitigated(ob_top, ob_btm, ob_left, ob_avg, target, bull)=>
  311. mitigated = false
  312. target_array = bull ? ob_btm : ob_top
  313.  
  314. for element in target_array
  315. idx = array.indexof(target_array, element)
  316.  
  317. if (bull ? target < element : target > element)
  318. mitigated := true
  319.  
  320. array.remove(ob_top, idx)
  321. array.remove(ob_btm, idx)
  322. array.remove(ob_avg, idx)
  323. array.remove(ob_left, idx)
  324.  
  325. mitigated
  326.  
  327. //Function to set order blocks
  328. set_order_blocks(ob_top, ob_btm, ob_left, ob_avg, ext_last, bg_css, border_css, lvl_css)=>
  329. var ob_box = array.new_box(0)
  330. var ob_lvl = array.new_line(0)
  331.  
  332. //Fill arrays with boxes/lines
  333. if barstate.isfirst
  334. for i = 0 to ext_last-1
  335. array.unshift(ob_box, box.new(na,na,na,na
  336. , xloc = xloc.bar_time
  337. , extend= extend.right
  338. , bgcolor = bg_css
  339. , border_color = color.new(border_css, 70)))
  340.  
  341. array.unshift(ob_lvl, line.new(na,na,na,na
  342. , xloc = xloc.bar_time
  343. , extend = extend.right
  344. , color = lvl_css
  345. , style = get_line_style(line_style)
  346. , width = line_width))
  347.  
  348. //Set order blocks
  349. if barstate.islast
  350. if array.size(ob_top) > 0
  351. for i = 0 to math.min(ext_last-1, array.size(ob_top)-1)
  352. get_box = array.get(ob_box, i)
  353. get_lvl = array.get(ob_lvl, i)
  354.  
  355. box.set_lefttop(get_box, array.get(ob_left, i), array.get(ob_top, i))
  356. box.set_rightbottom(get_box, array.get(ob_left, i), array.get(ob_btm, i))
  357.  
  358. line.set_xy1(get_lvl, array.get(ob_left, i), array.get(ob_avg, i))
  359. line.set_xy2(get_lvl, array.get(ob_left, i)+1, array.get(ob_avg, i))
  360.  
  361. //Global elements
  362. var os = 0
  363. var target_bull = 0.
  364. var target_bear = 0.
  365.  
  366. n = bar_index
  367. upper = ta.highest(length)
  368. lower = ta.lowest(length)
  369.  
  370. if mitigation == 'Close'
  371. target_bull := ta.lowest(close, length)
  372. target_bear := ta.highest(close, length)
  373. else
  374. target_bull := lower
  375. target_bear := upper
  376.  
  377. os := high[length] > upper ? 0 : low[length] < lower ? 1 : os[1]
  378.  
  379. phv = ta.pivothigh(volume, length, length)
  380.  
  381. // Crypto_Wolf_Traders
  382. var tLog = table.new(position = position.bottom_center, rows = 1, columns = 2, border_width=-6)
  383. table.cell(tLog, row = 0, column = 0, text = " Slaya & Wolf ", text_size=size.normal, text_color = #00def6)
  384. table.cell(tLog, row = 0, column = 1, text = "SuperScalper-Veins ", text_size=size.normal, text_color = #f60087)
  385.  
  386. //Get bullish/bearish order blocks coordinates
  387. [bull_top
  388. , bull_btm
  389. , bull_avg
  390. , bull_left
  391. , bull_ob] = get_coordinates(phv and os == 1, hl2[length], low[length], low[length])
  392.  
  393. [bear_top
  394. , bear_btm
  395. , bear_avg
  396. , bear_left
  397. , bear_ob] = get_coordinates(phv and os == 0, high[length], hl2[length], high[length])
  398.  
  399. //Remove mitigated order blocks
  400. mitigated_bull = remove_mitigated(bull_top
  401. , bull_btm
  402. , bull_left
  403. , bull_avg
  404. , target_bull
  405. , true)
  406.  
  407. mitigated_bear = remove_mitigated(bear_top
  408. , bear_btm
  409. , bear_left
  410. , bear_avg
  411. , target_bear
  412. , false)
  413.  
  414. //Set bullish order blocks
  415. set_order_blocks(bull_top
  416. , bull_btm
  417. , bull_left
  418. , bull_avg
  419. , bull_ext_last
  420. , bg_bull_css
  421. , bull_css
  422. , bull_avg_css)
  423.  
  424. //Set bearish order blocks
  425. set_order_blocks(bear_top
  426. , bear_btm
  427. , bear_left
  428. , bear_avg
  429. , bear_ext_last
  430. , bg_bear_css
  431. , bear_css
  432. , bear_avg_css)
  433.  
  434. // SUPPORT & RESISTANCE
  435.  
  436. percWidth1(len, perc) => (ta.highest(len) - ta.lowest(len)) * perc / 100
  437.  
  438. // Get components
  439. rb = 10
  440. prd = 284
  441. ChannelW = 10
  442. label_loc = 55
  443. style1 = lineStyle1 == "Solid" ? line.style_solid : lineStyle1 == "Dotted" ? line.style_dotted : line.style_dashed
  444. ph = ta.pivothigh(rb, rb)
  445. pl = ta.pivotlow (rb, rb)
  446. sr_levels = array.new_float(21, na)
  447. prdhighest = ta.highest(prd)
  448. prdlowest = ta.lowest(prd)
  449. cwidth = percWidth(prd, ChannelW)
  450. zonePerc = percWidth(300, zoneWidth)
  451. aas = array.new_bool(41, true)
  452. u1 = 0.0, u1 := nz(u1[1])
  453. d1 = 0.0, d1 := nz(d1[1])
  454. highestph = 0.0, highestph := highestph[1]
  455. lowestpl = 0.0, lowestpl := lowestpl[1]
  456. var sr_levs = array.new_float(21, na)
  457. label hlabel = na, label.delete(hlabel[1])
  458. label llabel = na, label.delete(llabel[1])
  459. var sr_lines = array.new_line(21, na)
  460. var sr_linesH = array.new_line(21, na)
  461. var sr_linesL = array.new_line(21, na)
  462. var sr_linesF = array.new_linefill(21, na)
  463. var sr_labels = array.new_label(21, na)
  464. if ph or pl
  465. for x = 0 to array.size(sr_levels) - 1
  466. array.set(sr_levels, x, na)
  467. highestph := prdlowest
  468. lowestpl := prdhighest
  469. countpp = 0
  470. for x = 0 to prd
  471. if na(close[x])
  472. break
  473. if not na(ph[x]) or not na(pl[x])
  474. highestph := math.max(highestph, nz(ph[x], prdlowest), nz(pl[x], prdlowest))
  475. lowestpl := math.min(lowestpl, nz(ph[x], prdhighest), nz(pl[x], prdhighest))
  476. countpp += 1
  477. if countpp > 40
  478. break
  479. if array.get(aas, countpp)
  480. upl = (ph[x] ? high[x + rb] : low[x + rb]) + cwidth
  481. dnl = (ph[x] ? high[x + rb] : low[x + rb]) - cwidth
  482. u1 := countpp == 1 ? upl : u1
  483. d1 := countpp == 1 ? dnl : d1
  484. tmp = array.new_bool(41, true)
  485. cnt = 0
  486. tpoint = 0
  487. for xx = 0 to prd
  488. if na(close[xx])
  489. break
  490. if not na(ph[xx]) or not na(pl[xx])
  491. chg = false
  492. cnt += 1
  493. if cnt > 40
  494. break
  495. if array.get(aas, cnt)
  496. if not na(ph[xx])
  497. if high[xx + rb] <= upl and high[xx + rb] >= dnl
  498. tpoint += 1
  499. chg := true
  500. if not na(pl[xx])
  501. if low[xx + rb] <= upl and low[xx + rb] >= dnl
  502. tpoint += 1
  503. chg := true
  504. if chg and cnt < 41
  505. array.set(tmp, cnt, false)
  506. if tpoint >= strengthSR
  507. for g = 0 to 40 by 1
  508. if not array.get(tmp, g)
  509. array.set(aas, g, false)
  510. if ph[x] and countpp < 21
  511. array.set(sr_levels, countpp, high[x + rb])
  512. if pl[x] and countpp < 21
  513. array.set(sr_levels, countpp, low[x + rb])
  514.  
  515. // Plot
  516. var line highest_ = na, line.delete(highest_)
  517. var line lowest_ = na, line.delete(lowest_)
  518. var line highest_fill1 = na, line.delete(highest_fill1)
  519. var line highest_fill2 = na, line.delete(highest_fill2)
  520. var line lowest_fill1 = na, line.delete(lowest_fill1)
  521. var line lowest_fill2 = na, line.delete(lowest_fill2)
  522. hi_col = close >= highestph ? colorSup : colorRes
  523. lo_col = close >= lowestpl ? colorSup : colorRes
  524. if enableSR
  525. highest_ := line.new(bar_index - 311, highestph, bar_index, highestph, xloc.bar_index, expandSR ? extend.both : extend.right, hi_col, style1, lineWidth1)
  526. lowest_ := line.new(bar_index - 311, lowestpl , bar_index, lowestpl , xloc.bar_index, expandSR ? extend.both : extend.right, lo_col, style1, lineWidth1)
  527. if useHLZones
  528. highest_fill1 := line.new(bar_index - 311, highestph + zonePerc, bar_index, highestph + zonePerc, xloc.bar_index, expandSR ? extend.both : extend.right, na)
  529. highest_fill2 := line.new(bar_index - 311, highestph - zonePerc, bar_index, highestph - zonePerc, xloc.bar_index, expandSR ? extend.both : extend.right, na)
  530. lowest_fill1 := line.new(bar_index - 311, lowestpl + zonePerc , bar_index, lowestpl + zonePerc , xloc.bar_index, expandSR ? extend.both : extend.right, na)
  531. lowest_fill2 := line.new(bar_index - 311, lowestpl - zonePerc , bar_index, lowestpl - zonePerc , xloc.bar_index, expandSR ? extend.both : extend.right, na)
  532. linefill.new(highest_fill1, highest_fill2, color.new(hi_col, 90))
  533. linefill.new(lowest_fill1 , lowest_fill2 , color.new(lo_col, 90))
  534. if ph or pl
  535. for x = 0 to array.size(sr_lines) - 1
  536. array.set(sr_levs, x, array.get(sr_levels, x))
  537. for x = 0 to array.size(sr_lines) - 1
  538. line.delete(array.get(sr_lines, x))
  539. line.delete(array.get(sr_linesH, x))
  540. line.delete(array.get(sr_linesL, x))
  541. linefill.delete(array.get(sr_linesF, x))
  542. if array.get(sr_levs, x) and enableSR
  543. line_col = close >= array.get(sr_levs, x) ? colorSup : colorRes
  544. 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))
  545. if useZones
  546. 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))
  547. 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))
  548. array.set(sr_linesF, x, linefill.new(array.get(sr_linesH, x), array.get(sr_linesL, x), color.new(line_col, 90)))
  549. for x = 0 to array.size(sr_labels) - 1
  550. label.delete(array.get(sr_labels, x))
  551. if array.get(sr_levs, x) and enableSR
  552. lab_loc = close >= array.get(sr_levs, x) ? label.style_label_up : label.style_label_down
  553. lab_col = close >= array.get(sr_levs, x) ? colorSup : colorRes
  554.  
  555.  
  556.  
  557. ////////////////////////////////////////////////////////////////////////////////
  558. // Alerts
  559. // to automate put this in trendinview message: {{strategy.order.alert_message}}
  560. i_alert_txt_entry_long = input.text_area(defval = "", title = "Long Entry Message", group = "Alerts")
  561. i_alert_txt_exit_long = input.text_area(defval = "", title = "Long Exit Message", group = "Alerts")
  562. i_alert_txt_entry_short = input.text_area(defval = "", title = "Short Entry Message", group = "Alerts")
  563. i_alert_txt_exit_short = input.text_area(defval = "", title = "Short Exit Message", group = "Alerts")
  564. //i_alert_txt_TP_long = input.text_area(defval = "", title = "Long TP Message", group = "Alerts")
  565. //i_alert_txt_TP_short = input.text_area(defval = "", title = "Short TP Message", group = "Alerts")
  566. //i_alert_txt_SL_long = input.text_area(defval = "", title = "Long SL Message", group = "Alerts")
  567. //i_alert_txt_SL_short = input.text_area(defval = "", title = "Short SL Message", group = "Alerts")
  568.  
  569.  
  570. // Entries and Exits with TP/SL
  571. if bull
  572. strategy.close("Short" ,alert_message = i_alert_txt_exit_short, comment = "Close Short")
  573. strategy.entry("Long" , strategy.long , alert_message = i_alert_txt_entry_long)
  574. strategy.exit("Take Profit 1", from_entry = "Long", limit = tp1_y , qty_percent = 30), alert_message = i_alert_txt_TP_long)
  575. strategy.exit("Take Profit 2", from_entry = "Long", limit = tp2_y , qty_percent = 30), alert_message = i_alert_txt_TP_long)
  576. strategy.exit("Take Profit 3", from_entry = "Long", limit = tp3_y , qty_percent = 20), alert_message = i_alert_txt_TP_long)
  577. strategy.exit("Take Profit 4", from_entry = "Long", limit = tp4_y , qty_percent = 20), alert_message = i_alert_txt_TP_long)
  578. //strategy.exit("Stop Loss", from_entry = "Long", loss = stop_y, comment_loss = "Long Stop Loss")//, alert_message = i_alert_txt_SL_long)
  579.  
  580. if bear
  581. strategy.close("Long" , alert_message = i_alert_txt_exit_long , comment = "Close Long")
  582. strategy.entry("Short" , strategy.short, alert_message = i_alert_txt_entry_short)
  583. strategy.exit("Take Profit 1", from_entry = "Short", limit = tp1_y , qty_percent = 30), alert_message = i_alert_txt_TP_short)
  584. strategy.exit("Take Profit 2", from_entry = "Short", limit = tp2_y , qty_percent = 30), alert_message = i_alert_txt_TP_short)
  585. strategy.exit("Take Profit 3", from_entry = "Short", limit = tp3_y , qty_percent = 20), alert_message = i_alert_txt_TP_short)
  586. strategy.exit("Take Profit 4", from_entry = "Short", limit = tp4_y , qty_percent = 20), alert_message = i_alert_txt_TP_short)
  587. //strategy.exit("Stop Loss", from_entry = "Short", loss = stop_y, comment_loss = "Short Stop Loss")//, alert_message = i_alert_txt_SL_short)
  588.  
  589.  
  590.  
  591.  
  592. /// End Of The Code///
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement