xmd79

[BB] LAZARUSBURAK

Nov 22nd, 2021
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 39.08 KB | None | 0 0
  1.  
  2. //LAZARUSBURAK
  3. //@version=5
  4. indicator("[BB] LAZARUSBURAK", shorttitle="[BB] BB", overlay=true, max_lines_count=500, max_labels_count=500, max_bars_back=500)
  5.  
  6. hw = input(8., 'Bw')
  7. srcw = input(close, 'Source')
  8. //----
  9. nw = bar_index
  10. var lnw = array.new_line(0)
  11. if barstate.isfirst
  12. for iw = 0 to 499 by 1
  13. array.push(lnw, line.new(na, na, na, na))
  14. //----
  15. float y2w = na
  16. float y1w = na
  17. float y1_dw = na
  18. //----
  19. line lw = na
  20. label lbw = na
  21. if barstate.islast
  22. for iw = 0 to math.min(499, nw - 1) by 1
  23. sumw = 0.
  24. sumww = 0.
  25. for jw = 0 to math.min(499, nw - 1) by 1
  26. ww = math.exp(-(math.pow(iw - jw, 2) / (hw * hw * 2)))
  27. sumw := sumw + srcw[jw] * ww
  28. sumww := sumww + ww
  29. sumww
  30. y2w := sumw / sumww
  31. dw = y2w - y1w
  32.  
  33.  
  34.  
  35. if dw > 0 and y1_dw < 0
  36. label.new(nw - iw + 1, srcw[iw], '๐Ÿš€', color=#00000000, style=label.style_label_up, size=size.huge, textcolor=#39ff14, textalign=text.align_center)
  37. if dw < 0 and y1_dw > 0
  38. label.new(nw - iw + 1, srcw[iw], '๐Ÿ’€', color=#00000000, style=label.style_label_down, size=size.huge, textcolor=#ff1100, textalign=text.align_center)
  39.  
  40. y1w := y2w
  41. y1_dw := dw
  42. y1_dw
  43.  
  44.  
  45.  
  46. length = input.int(20, minval=1)
  47. src = input(close, title='Source')
  48. mult = input.float(2.0, minval=0.001, maxval=50, title='StdDev')
  49. bcolorbars = input(true, title='Color bars')
  50.  
  51. basis = ta.sma(src, length)
  52. dev = mult * ta.stdev(src, length)
  53. upper = basis + dev
  54. lower = basis - dev
  55.  
  56. // Color Bars with the tendency
  57.  
  58. bColor = close > basis
  59. b2Color = close < basis
  60.  
  61. plotshape(bcolorbars ? bColor : na, location=location.top, color=#00FF00, size=size.tiny, transp=25)
  62. plotshape(bcolorbars ? b2Color : na, location=location.top, color=#d82020, size=size.tiny, transp=25)
  63.  
  64.  
  65. filterBW = input(false, title='filter Bill Williams Fractals')
  66. showll = input(true, title='Show levels')
  67. showff = input(false, title='Show fractals (repaint!)')
  68. showdd = input(true, title='Show dots (repaint!)')
  69.  
  70. //Variables
  71. loss = 0.0
  72. maxloss = 0.0
  73. equity = 0.0
  74.  
  75.  
  76. //Fractals
  77. isRegularFractal(mode) =>
  78. ret = mode == 1 ? high[4] < high[3] and high[3] < high[2] and high[2] > high[1] and high[1] > high[0] : mode == -1 ? low[4] > low[3] and low[3] > low[2] and low[2] < low[1] and low[1] < low[0] : false
  79. ret
  80. isBWFractal(mode) =>
  81. ret = mode == 1 ? high[4] < high[2] and high[3] <= high[2] and high[2] >= high[1] and high[2] > high[0] : mode == -1 ? low[4] > low[2] and low[3] >= low[2] and low[2] <= low[1] and low[2] < low[0] : false
  82. ret
  83. filteredtopf = filterBW ? isRegularFractal(1) : isBWFractal(1)
  84. filteredbotf = filterBW ? isRegularFractal(-1) : isBWFractal(-1)
  85.  
  86. //Triangles
  87. plotshape(filteredtopf and showff, title='Filtered Top Fractals', style=shape.triangledown, location=location.abovebar, color=color.new(color.red, 0), offset=-2)
  88. plotshape(filteredbotf and showff, title='Filtered Bottom Fractals', style=shape.triangleup, location=location.belowbar, color=color.new(color.lime, 0), offset=-2)
  89.  
  90. //Levels
  91. hh = 0.0
  92. ll = 0.0
  93. hh := filteredtopf ? high[2] : hh[1]
  94. ll := filteredbotf ? low[2] : ll[1]
  95.  
  96. //Trend
  97. trend = 0
  98. trend := high >= hh[1] ? 1 : low <= ll[1] ? -1 : trend[1]
  99.  
  100. //Lines
  101. hcol = showll and hh == hh[1] and close < hh ? color.lime : na
  102. lcol = showll and ll == ll[1] and close > ll ? color.red : na
  103. plot(hh, color=hcol)
  104. plot(ll, color=lcol)
  105.  
  106. //Dots
  107. var line hline = na
  108. if hh != hh[1] and showdd
  109. hline := line.new(bar_index - 0, hh[0], bar_index - 2, hh[0], xloc=xloc.bar_index, extend=extend.none, style=line.style_dotted, color=color.lime, width=1)
  110. hline
  111. var line lline = na
  112. if ll != ll[1] and showdd
  113. lline := line.new(bar_index - 0, ll[0] - syminfo.mintick, bar_index - 2, ll[0] - syminfo.mintick, xloc=xloc.bar_index, extend=extend.none, style=line.style_dotted, color=color.red, width=1)
  114. lline
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122. color yellow50 = color.new(color.yellow, 50)
  123. ShowImbalance = input(defval=true, title='Show Imbalance')
  124. TopImbalance = low[2] <= open[1] and high[0] >= close[1]
  125. TopImbalancesize = low[2] - high[0]
  126. if ShowImbalance and TopImbalance and TopImbalancesize > 0
  127. BOX1 = box.new(left=bar_index[1], top=low[2], right=bar_index[0], bottom=high[0])
  128. box.set_bgcolor(BOX1, color=yellow50)
  129. box.set_border_color(BOX1, color=yellow50)
  130. // box.set_extend (BOX1,extend.right)
  131.  
  132. BottomInbalance = high[2] >= open[1] and low[0] <= close[1]
  133. BottomInbalancesize = low[0] - high[2]
  134. if ShowImbalance and BottomInbalance and BottomInbalancesize > 0
  135. BOX2 = box.new(left=bar_index[1], top=low[0], right=bar_index[0], bottom=high[2])
  136. box.set_bgcolor(BOX2, color=yellow50)
  137. box.set_border_color(BOX2, color=yellow50)
  138.  
  139.  
  140. show_vp = input(true, title='--------------- Show Volume profile ------------')
  141. //MOD'S
  142. bool input_delta = input(title='Delta', defval=true)
  143. bool input_poc = false
  144.  
  145. //FRAME: Y
  146. int input_depth = input.int(title='Depth [10; 1k]', defval=200, minval=10, maxval=1000)
  147. bool input_range = false
  148. float input_persent = 5
  149. bool input_log10 = false
  150.  
  151. //FRAME: X
  152. int input_amp = input.int(title='Amp [10; 100]', defval=50, minval=10, maxval=100)
  153. int input_size = input.int(title='Dot size', defval=1, minval=1, maxval=3)
  154.  
  155. //PALETTE
  156. color input_c_info = input(title='Color: Info', defval=color.new(#FFFFFF, 0)) //EM color White
  157. color input_c_frame = input(title='Color: Frame', defval=color.new(#617793, 0)) //EM color Palladium
  158. color input_c_total = input(title='Color: ฮฃ', defval=color.new(#b8c9ff, 0)) //EM color Palladium
  159. color input_c_plus = input(title='Color: ฮ” +', defval=color.new(#d82020, 0)) //EM color Green
  160. color input_c_minus = input(title='Color: ฮ” โ€“', defval=color.new(#00FF00, 0)) //EM color red
  161.  
  162. far = input(50, 'far')
  163.  
  164.  
  165.  
  166. //////////////////
  167. // //
  168. // DATA //
  169. // //
  170. //////////////////
  171.  
  172.  
  173. //// FRAME
  174.  
  175. //ath & atl
  176. float FH = na
  177. float FL = na
  178. float rn = na
  179.  
  180. //true depth
  181. int depth = input_depth
  182.  
  183. //first bar time
  184. var int time_first = time
  185.  
  186.  
  187. //// ROWS DATA
  188.  
  189. var R = array.new_float(50, 0) //Row (price)
  190. var TV = array.new_float(50, 0) //Total: Value
  191. var TA = array.new_int(50, 0) //Total: Amp
  192. var TP = array.new_bool(50, false) //Total: Peak
  193. float TM = 1 //Total: Max Value
  194. var DV = array.new_float(50, 0) //Delta: Value
  195. var DA = array.new_int(50, 0) //Delta: Amp
  196. var DP = array.new_bool(50, false) //Delta: Peak
  197.  
  198.  
  199. //// POC
  200.  
  201. float POC = na
  202. float POC_DP = na
  203. float POC_DN = na
  204.  
  205.  
  206. //// INTERFACE
  207.  
  208. //text
  209. string txt_top = input_range ? '+ ' + str.tostring(input_persent, '0.0') + ' %' : ' ' + (input_amp < 20 ? 'H โ‡… L' : 'HIGH โ‡… LOW')
  210. string txt_btm = 'โฎ ' + str.tostring(input_depth)
  211.  
  212. //size
  213. var dot_size = input_size == 1 ? size.tiny : input_size == 2 ? size.small : size.normal
  214.  
  215. //invisible
  216. var color c_opacity = color.new(color.white, 100)
  217.  
  218.  
  219.  
  220.  
  221. ////////////////////////
  222. // //
  223. // EXCEPTIONS //
  224. // //
  225. ////////////////////////
  226.  
  227. bool exception_no_volume = nz(volume) == 0
  228. bool exception_excess_depth = na(close[input_depth])
  229. bool exception_bug_minute = timeframe.period == '1'
  230.  
  231.  
  232. //// EXCEPTION HANDLING
  233.  
  234. //no volume
  235. if exception_no_volume
  236. txt_top := input_amp < 20 ? '๐Ÿšซ' : '๐Ÿšซ NO VOLUME'
  237. txt_top
  238.  
  239. //depth correction
  240. if exception_excess_depth and barstate.islast
  241. for i = 2 to input_depth by 1
  242. if na(close[i])
  243. depth := i
  244. break
  245. txt_btm := 'โฎ ' + str.tostring(depth)
  246. txt_btm
  247.  
  248.  
  249.  
  250.  
  251. //////////////////////////
  252. // //
  253. // CALCULATIONS //
  254. // //
  255. //////////////////////////
  256.  
  257.  
  258. //// FRAME
  259.  
  260. //ath & atl
  261. if input_range
  262. rn := hl2 * input_persent / 100
  263. FH := hl2 + rn
  264. FL := hl2 - rn
  265. FL
  266. else
  267. FH := ta.highest(high, depth)
  268. FL := ta.lowest(low, depth)
  269. FL
  270.  
  271. //time_first bar time
  272. if barstate.isfirst
  273. time_first := time
  274. time_first
  275.  
  276.  
  277. //// FUNCTIONS
  278.  
  279. //row axis
  280. float axis_step = (input_log10 ? math.log10(FH / FL) : FH - FL) / 50 //step (logarithmic or linear)
  281. Axis(i) => // i steps
  282. input_log10 ? math.pow(10, math.log10(FL) + i * axis_step) : FL + i * axis_step
  283.  
  284. //drawing histogram
  285. Histogram(i) =>
  286. string T = input_delta and array.get(DP, i) or not input_delta and array.get(TP, i) ? 'โ—„ ' : ' '
  287. if array.get(TV, i) > 0
  288. int D_ = array.get(DA, i)
  289. for j = array.get(TA, i) to 0 by 1
  290. T += (input_delta ? D_ > j ? 'โ€ข' : 'ยท ' : 'โ€ข')
  291. T
  292. else
  293. T := ' โ€ง'
  294. T
  295. T
  296.  
  297. //row color
  298. Color(m) =>
  299. input_delta and array.get(DA, m) != 0 ? array.get(DV, m) > 0 ? input_c_plus : input_c_minus : input_c_total
  300.  
  301.  
  302. //// MAIN
  303.  
  304. if barstate.islast and not exception_no_volume and show_vp
  305.  
  306. //rows conformity to prices
  307. for i = 0 to 49 by 1
  308. array.set(R, i, Axis(i + 0.5)) //offset row axis โ€” row-hight / 2
  309.  
  310. //full depth
  311. for i = 0 to depth - 1 by 1
  312.  
  313. int C = 0 //denominator
  314. TS = array.new_float(50, 0) //divisible volumes
  315. DS = array.new_float(50, 0) //divisible deltas
  316.  
  317. //set TS & DS and denominator
  318. for j = 0 to 49 by 1
  319. float R_ = array.get(R, j)
  320. if high[i] > R_ and R_ > low[i]
  321. C += 1
  322. array.set(TS, j, nz(volume[i]))
  323. if input_delta
  324. array.set(DS, j, nz(volume[i]) * (close[i] > R_ ? 1 : -1))
  325.  
  326. if C != 0
  327.  
  328. //if High or Low out of range
  329. float K = 1 //cutoff factor [0; 1]
  330. if input_range and (high[i] > Axis(50) or low[i] < Axis(0))
  331. K := C / ((high[i] - low[i]) / (input_log10 ? math.pow(10, axis_step) : axis_step))
  332. K
  333.  
  334. //rows value
  335. for j = 0 to 49 by 1
  336. array.set(TV, j, array.get(TV, j) + array.get(TS, j) * K / C)
  337. if input_delta
  338. array.set(DV, j, array.get(DV, j) + array.get(DS, j) * K / C)
  339.  
  340. array.clear(TS)
  341. array.clear(DS)
  342.  
  343. TM := array.max(TV)
  344.  
  345. for i = 0 to 49 by 1
  346.  
  347. //amplitude
  348. array.set(TA, i, math.floor(input_amp * array.get(TV, i) / TM))
  349.  
  350. if not input_delta
  351. //peak 4 < X > 4
  352. float T_ = array.get(TV, i)
  353. bool p4 = i - 4 < 0 ? true : T_ > array.get(TV, i - 4)
  354. bool p3 = i - 3 < 0 ? true : T_ > array.get(TV, i - 3)
  355. bool p2 = i - 2 < 0 ? true : T_ > array.get(TV, i - 2)
  356. bool p1 = i - 1 < 0 ? true : T_ > array.get(TV, i - 1)
  357. bool n1 = i + 1 > 49 ? true : T_ > array.get(TV, i + 1)
  358. bool n2 = i + 2 > 49 ? true : T_ > array.get(TV, i + 2)
  359. bool n3 = i + 3 > 49 ? true : T_ > array.get(TV, i + 3)
  360. bool n4 = i + 4 > 49 ? true : T_ > array.get(TV, i + 4)
  361. array.set(TP, i, p4 and p3 and p2 and p1 and n1 and n2 and n3 and n4)
  362. else
  363.  
  364. //amplitude
  365. array.set(DA, i, math.floor(array.get(TA, i) * math.abs(array.get(DV, i)) / array.get(TV, i)))
  366.  
  367. //peak 4 < X > 4
  368. float D_ = math.abs(array.get(DV, i))
  369. bool p4 = i - 4 < 0 ? true : D_ > math.abs(array.get(DV, i - 4))
  370. bool p3 = i - 3 < 0 ? true : D_ > math.abs(array.get(DV, i - 3))
  371. bool p2 = i - 2 < 0 ? true : D_ > math.abs(array.get(DV, i - 2))
  372. bool p1 = i - 1 < 0 ? true : D_ > math.abs(array.get(DV, i - 1))
  373. bool n1 = i + 1 > 49 ? true : D_ > math.abs(array.get(DV, i + 1))
  374. bool n2 = i + 2 > 49 ? true : D_ > math.abs(array.get(DV, i + 2))
  375. bool n3 = i + 3 > 49 ? true : D_ > math.abs(array.get(DV, i + 3))
  376. bool n4 = i + 4 > 49 ? true : D_ > math.abs(array.get(DV, i + 4))
  377. array.set(DP, i, p4 and p3 and p2 and p1 and n1 and n2 and n3 and n4)
  378.  
  379. //POC
  380. if input_poc
  381.  
  382. float sum = 0
  383. float mass = 0
  384. for i = 0 to 49 by 1
  385. float V_ = array.get(TV, i)
  386. sum += V_
  387. mass += V_ * array.get(R, i)
  388. mass
  389.  
  390. POC := nz(mass / sum, na)
  391.  
  392. if input_delta and not exception_bug_minute
  393. float seller_sum = 0
  394. float seller_mass = 0
  395. float buyer_sum = 0
  396. float buyer_mass = 0
  397.  
  398. for i = 0 to 49 by 1
  399. float R_ = array.get(R, i)
  400. float D_ = array.get(DV, i)
  401. seller_sum += (D_ < 0 ? D_ : 0)
  402. seller_mass += (D_ < 0 ? D_ * R_ : 0)
  403. buyer_sum += (D_ > 0 ? D_ : 0)
  404. buyer_mass += (D_ > 0 ? D_ * R_ : 0)
  405. buyer_mass
  406.  
  407. POC_DN := nz(seller_mass / seller_sum, na)
  408. POC_DP := nz(buyer_mass / buyer_sum, na)
  409. POC_DP
  410.  
  411.  
  412.  
  413.  
  414. //////////////////////
  415. // //
  416. // BUILDING //
  417. // //
  418. //////////////////////
  419.  
  420.  
  421. //// POC
  422.  
  423. var line line_POC_DN = line.new(bar_index, na, bar_index, na, style=line.style_dashed, color=input_c_minus)
  424. var line line_POC_DP = line.new(bar_index, na, bar_index, na, style=line.style_dashed, color=input_c_plus)
  425. var line line_POC = line.new(bar_index, na, bar_index, na, style=line.style_dashed, color=input_c_info)
  426.  
  427.  
  428. //// INTERFACE
  429.  
  430. var label label_top = label.new(bar_index, FH, text=txt_top, style=label.style_label_lower_left, textcolor=input_c_info, color=c_opacity, size=size.normal)
  431. var label label_btm = label.new(bar_index, FL, text=txt_btm, style=label.style_label_upper_left, textcolor=input_c_info, color=c_opacity, size=size.normal)
  432.  
  433.  
  434. // FRAME
  435.  
  436. var line line_FH = line.new(bar_index, FH, bar_index, FH, color=input_c_frame, style=line.style_dashed)
  437. var line line_FL = line.new(bar_index, FL, bar_index, FL, color=input_c_frame, style=line.style_dashed)
  438. var line line_FS = line.new(bar_index, FL, bar_index, FL, color=input_c_frame, style=line.style_dashed)
  439.  
  440.  
  441. //// HISTOGRAM
  442.  
  443. int r1 = time_close
  444. float r2 = close
  445. string r3 = ''
  446. color r4 = input_c_total
  447. var r5 = xloc.bar_time
  448. var r6 = yloc.price
  449. color r7 = c_opacity
  450. var r8 = label.style_label_right
  451. var r9 = dot_size
  452.  
  453. var label R01 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  454. var label R02 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  455. var label R03 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  456. var label R04 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  457. var label R05 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  458. var label R06 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  459. var label R07 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  460. var label R08 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  461. var label R09 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  462. var label R10 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  463. var label R11 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  464. var label R12 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  465. var label R13 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  466. var label R14 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  467. var label R15 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  468. var label R16 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  469. var label R17 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  470. var label R18 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  471. var label R19 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  472. var label R20 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  473. var label R21 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  474. var label R22 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  475. var label R23 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  476. var label R24 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  477. var label R25 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  478. var label R26 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  479. var label R27 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  480. var label R28 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  481. var label R29 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  482. var label R30 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  483. var label R31 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  484. var label R32 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  485. var label R33 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  486. var label R34 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  487. var label R35 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  488. var label R36 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  489. var label R37 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  490. var label R38 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  491. var label R39 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  492. var label R40 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  493. var label R41 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  494. var label R42 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  495. var label R43 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  496. var label R44 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  497. var label R45 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  498. var label R46 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  499. var label R47 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  500. var label R48 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  501. var label R49 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  502. var label R50 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
  503.  
  504.  
  505. //// SHIFT & REFRECH
  506.  
  507. if barstate.islast and show_vp
  508.  
  509. //Frame: limits
  510. tl = far * (time - time[1])
  511.  
  512. int time_start = math.max(time[depth - 1], time_first)
  513. int time_finish = time_close + tl
  514.  
  515.  
  516. //// INTERFACE
  517.  
  518. label.set_xloc(label_top, time_finish, xloc.bar_time)
  519. label.set_y(label_top, FH)
  520.  
  521. label.set_xloc(label_btm, time_finish, xloc.bar_time)
  522. label.set_y(label_btm, FL)
  523. label.set_text(label_btm, txt_btm)
  524.  
  525.  
  526. //// POC
  527.  
  528. line.set_xloc(line_POC, time_start, time_finish, xloc.bar_time)
  529. line.set_y1(line_POC, POC)
  530. line.set_y2(line_POC, POC)
  531.  
  532. line.set_xloc(line_POC_DN, time_start, time_finish, xloc.bar_time)
  533. line.set_y1(line_POC_DN, POC_DN)
  534. line.set_y2(line_POC_DN, POC_DN)
  535.  
  536. line.set_xloc(line_POC_DP, time_start, time_finish, xloc.bar_time)
  537. line.set_y1(line_POC_DP, POC_DP)
  538. line.set_y2(line_POC_DP, POC_DP)
  539.  
  540.  
  541. //// FRAME
  542.  
  543. line.set_xloc(line_FH, time_start, time_finish, xloc.bar_time)
  544. line.set_y1(line_FH, FH)
  545. line.set_y2(line_FH, FH)
  546.  
  547. line.set_xloc(line_FL, time_start, time_finish, xloc.bar_time)
  548. line.set_y1(line_FL, FL)
  549. line.set_y2(line_FL, FL)
  550.  
  551. line.set_xloc(line_FS, time_start, time_start, xloc.bar_time)
  552. line.set_y1(line_FS, FH)
  553. line.set_y2(line_FS, FL)
  554.  
  555.  
  556. //// HISTOGRAM
  557.  
  558. label.set_x(R01, time_finish)
  559. label.set_y(R01, array.get(R, 0))
  560. label.set_text(R01, Histogram(0))
  561. label.set_textcolor(R01, Color(0))
  562. label.set_x(R02, time_finish)
  563. label.set_y(R02, array.get(R, 1))
  564. label.set_text(R02, Histogram(1))
  565. label.set_textcolor(R02, Color(1))
  566. label.set_x(R03, time_finish)
  567. label.set_y(R03, array.get(R, 2))
  568. label.set_text(R03, Histogram(2))
  569. label.set_textcolor(R03, Color(2))
  570. label.set_x(R04, time_finish)
  571. label.set_y(R04, array.get(R, 3))
  572. label.set_text(R04, Histogram(3))
  573. label.set_textcolor(R04, Color(3))
  574. label.set_x(R05, time_finish)
  575. label.set_y(R05, array.get(R, 4))
  576. label.set_text(R05, Histogram(4))
  577. label.set_textcolor(R05, Color(4))
  578. label.set_x(R06, time_finish)
  579. label.set_y(R06, array.get(R, 5))
  580. label.set_text(R06, Histogram(5))
  581. label.set_textcolor(R06, Color(5))
  582. label.set_x(R07, time_finish)
  583. label.set_y(R07, array.get(R, 6))
  584. label.set_text(R07, Histogram(6))
  585. label.set_textcolor(R07, Color(6))
  586. label.set_x(R08, time_finish)
  587. label.set_y(R08, array.get(R, 7))
  588. label.set_text(R08, Histogram(7))
  589. label.set_textcolor(R08, Color(7))
  590. label.set_x(R09, time_finish)
  591. label.set_y(R09, array.get(R, 8))
  592. label.set_text(R09, Histogram(8))
  593. label.set_textcolor(R09, Color(8))
  594. label.set_x(R10, time_finish)
  595. label.set_y(R10, array.get(R, 9))
  596. label.set_text(R10, Histogram(9))
  597. label.set_textcolor(R10, Color(9))
  598. label.set_x(R11, time_finish)
  599. label.set_y(R11, array.get(R, 10))
  600. label.set_text(R11, Histogram(10))
  601. label.set_textcolor(R11, Color(10))
  602. label.set_x(R12, time_finish)
  603. label.set_y(R12, array.get(R, 11))
  604. label.set_text(R12, Histogram(11))
  605. label.set_textcolor(R12, Color(11))
  606. label.set_x(R13, time_finish)
  607. label.set_y(R13, array.get(R, 12))
  608. label.set_text(R13, Histogram(12))
  609. label.set_textcolor(R13, Color(12))
  610. label.set_x(R14, time_finish)
  611. label.set_y(R14, array.get(R, 13))
  612. label.set_text(R14, Histogram(13))
  613. label.set_textcolor(R14, Color(13))
  614. label.set_x(R15, time_finish)
  615. label.set_y(R15, array.get(R, 14))
  616. label.set_text(R15, Histogram(14))
  617. label.set_textcolor(R15, Color(14))
  618. label.set_x(R16, time_finish)
  619. label.set_y(R16, array.get(R, 15))
  620. label.set_text(R16, Histogram(15))
  621. label.set_textcolor(R16, Color(15))
  622. label.set_x(R17, time_finish)
  623. label.set_y(R17, array.get(R, 16))
  624. label.set_text(R17, Histogram(16))
  625. label.set_textcolor(R17, Color(16))
  626. label.set_x(R18, time_finish)
  627. label.set_y(R18, array.get(R, 17))
  628. label.set_text(R18, Histogram(17))
  629. label.set_textcolor(R18, Color(17))
  630. label.set_x(R19, time_finish)
  631. label.set_y(R19, array.get(R, 18))
  632. label.set_text(R19, Histogram(18))
  633. label.set_textcolor(R19, Color(18))
  634. label.set_x(R20, time_finish)
  635. label.set_y(R20, array.get(R, 19))
  636. label.set_text(R20, Histogram(19))
  637. label.set_textcolor(R20, Color(19))
  638. label.set_x(R21, time_finish)
  639. label.set_y(R21, array.get(R, 20))
  640. label.set_text(R21, Histogram(20))
  641. label.set_textcolor(R21, Color(20))
  642. label.set_x(R22, time_finish)
  643. label.set_y(R22, array.get(R, 21))
  644. label.set_text(R22, Histogram(21))
  645. label.set_textcolor(R22, Color(21))
  646. label.set_x(R23, time_finish)
  647. label.set_y(R23, array.get(R, 22))
  648. label.set_text(R23, Histogram(22))
  649. label.set_textcolor(R23, Color(22))
  650. label.set_x(R24, time_finish)
  651. label.set_y(R24, array.get(R, 23))
  652. label.set_text(R24, Histogram(23))
  653. label.set_textcolor(R24, Color(23))
  654. label.set_x(R25, time_finish)
  655. label.set_y(R25, array.get(R, 24))
  656. label.set_text(R25, Histogram(24))
  657. label.set_textcolor(R25, Color(24))
  658. label.set_x(R26, time_finish)
  659. label.set_y(R26, array.get(R, 25))
  660. label.set_text(R26, Histogram(25))
  661. label.set_textcolor(R26, Color(25))
  662. label.set_x(R27, time_finish)
  663. label.set_y(R27, array.get(R, 26))
  664. label.set_text(R27, Histogram(26))
  665. label.set_textcolor(R27, Color(26))
  666. label.set_x(R28, time_finish)
  667. label.set_y(R28, array.get(R, 27))
  668. label.set_text(R28, Histogram(27))
  669. label.set_textcolor(R28, Color(27))
  670. label.set_x(R29, time_finish)
  671. label.set_y(R29, array.get(R, 28))
  672. label.set_text(R29, Histogram(28))
  673. label.set_textcolor(R29, Color(28))
  674. label.set_x(R30, time_finish)
  675. label.set_y(R30, array.get(R, 29))
  676. label.set_text(R30, Histogram(29))
  677. label.set_textcolor(R30, Color(29))
  678. label.set_x(R31, time_finish)
  679. label.set_y(R31, array.get(R, 30))
  680. label.set_text(R31, Histogram(30))
  681. label.set_textcolor(R31, Color(30))
  682. label.set_x(R32, time_finish)
  683. label.set_y(R32, array.get(R, 31))
  684. label.set_text(R32, Histogram(31))
  685. label.set_textcolor(R32, Color(31))
  686. label.set_x(R33, time_finish)
  687. label.set_y(R33, array.get(R, 32))
  688. label.set_text(R33, Histogram(32))
  689. label.set_textcolor(R33, Color(32))
  690. label.set_x(R34, time_finish)
  691. label.set_y(R34, array.get(R, 33))
  692. label.set_text(R34, Histogram(33))
  693. label.set_textcolor(R34, Color(33))
  694. label.set_x(R35, time_finish)
  695. label.set_y(R35, array.get(R, 34))
  696. label.set_text(R35, Histogram(34))
  697. label.set_textcolor(R35, Color(34))
  698. label.set_x(R36, time_finish)
  699. label.set_y(R36, array.get(R, 35))
  700. label.set_text(R36, Histogram(35))
  701. label.set_textcolor(R36, Color(35))
  702. label.set_x(R37, time_finish)
  703. label.set_y(R37, array.get(R, 36))
  704. label.set_text(R37, Histogram(36))
  705. label.set_textcolor(R37, Color(36))
  706. label.set_x(R38, time_finish)
  707. label.set_y(R38, array.get(R, 37))
  708. label.set_text(R38, Histogram(37))
  709. label.set_textcolor(R38, Color(37))
  710. label.set_x(R39, time_finish)
  711. label.set_y(R39, array.get(R, 38))
  712. label.set_text(R39, Histogram(38))
  713. label.set_textcolor(R39, Color(38))
  714. label.set_x(R40, time_finish)
  715. label.set_y(R40, array.get(R, 39))
  716. label.set_text(R40, Histogram(39))
  717. label.set_textcolor(R40, Color(39))
  718. label.set_x(R41, time_finish)
  719. label.set_y(R41, array.get(R, 40))
  720. label.set_text(R41, Histogram(40))
  721. label.set_textcolor(R41, Color(40))
  722. label.set_x(R42, time_finish)
  723. label.set_y(R42, array.get(R, 41))
  724. label.set_text(R42, Histogram(41))
  725. label.set_textcolor(R42, Color(41))
  726. label.set_x(R43, time_finish)
  727. label.set_y(R43, array.get(R, 42))
  728. label.set_text(R43, Histogram(42))
  729. label.set_textcolor(R43, Color(42))
  730. label.set_x(R44, time_finish)
  731. label.set_y(R44, array.get(R, 43))
  732. label.set_text(R44, Histogram(43))
  733. label.set_textcolor(R44, Color(43))
  734. label.set_x(R45, time_finish)
  735. label.set_y(R45, array.get(R, 44))
  736. label.set_text(R45, Histogram(44))
  737. label.set_textcolor(R45, Color(44))
  738. label.set_x(R46, time_finish)
  739. label.set_y(R46, array.get(R, 45))
  740. label.set_text(R46, Histogram(45))
  741. label.set_textcolor(R46, Color(45))
  742. label.set_x(R47, time_finish)
  743. label.set_y(R47, array.get(R, 46))
  744. label.set_text(R47, Histogram(46))
  745. label.set_textcolor(R47, Color(46))
  746. label.set_x(R48, time_finish)
  747. label.set_y(R48, array.get(R, 47))
  748. label.set_text(R48, Histogram(47))
  749. label.set_textcolor(R48, Color(47))
  750. label.set_x(R49, time_finish)
  751. label.set_y(R49, array.get(R, 48))
  752. label.set_text(R49, Histogram(48))
  753. label.set_textcolor(R49, Color(48))
  754. label.set_x(R50, time_finish)
  755. label.set_y(R50, array.get(R, 49))
  756. label.set_text(R50, Histogram(49))
  757. label.set_textcolor(R50, Color(49))
  758.  
  759.  
  760.  
  761.  
  762.  
  763.  
  764.  
  765.  
  766.  
  767.  
  768.  
  769.  
  770.  
  771.  
  772.  
  773. // INPUTS
  774. i_time = input.session ('0000-0001:1234567', "New York", tooltip="Different exchanges will have difference time zones so change accordingly.")
  775. i_vline = input.bool (false, "VLine", inline="in3")
  776. i_vcol = input.color (#00b9d0, "", inline="in3")
  777. i_txtcol = input.color (#0098ff, "โ€ƒโ€ƒText color", inline="in3")
  778. i_vstyle = input.string ("Solid", "Style", options=["Solid", "Dotted", "Dashed"])
  779.  
  780. i_hline = input.bool (true, "HLine", inline="in1")
  781. i_linecol = input.color (#0064ff, "", inline="in1")
  782. i_linestyle = input.string ("Dotted", "โ€ƒ", options=["Solid", "Dotted", "Dashed"], inline="in1")
  783. i_ex = input.string ("None", "Extend", options=["None", "+1 Day", "Right", "Both"] )
  784.  
  785.  
  786. // MISC
  787. nymid = time ("1", i_time)
  788. linestyle = i_linestyle == "Solid" ? line.style_solid : i_linestyle == "Dotted" ? line.style_dotted : line.style_dashed
  789. vstyle = i_vstyle == "Solid" ? line.style_solid : i_vstyle == "Dotted" ? line.style_dotted : line.style_dashed
  790. ex = i_ex == "None" ? extend.none : i_ex == "+1 Day" ? extend.none : i_ex == "Right" ? extend.right : extend.both
  791. htime = i_ex == "+1 Day" ? 172800000 : 86400000
  792.  
  793. // CALC
  794. var openprice = 0.0
  795. if nymid
  796. if not nymid[1]
  797. openprice := open
  798. else
  799. openprice := math.max(open, openprice)
  800.  
  801. // OBJECTS
  802. var label lb = na
  803. if openprice != openprice[1] and i_hline
  804. var line lne = na
  805. line.set_x2(lne, nymid)
  806. line.set_extend(lne, extend.none)
  807. lne := line.new(nymid, openprice, nymid + htime, openprice, xloc.bar_time, ex, i_linecol, linestyle, 2)
  808. lb := label.new(nymid + htime, openprice, "NY Midnight Open | " + str.tostring(math.round_to_mintick(openprice)), xloc.bar_time, yloc.price, na, label.style_none, i_txtcol)
  809. label.delete(lb[1])
  810.  
  811. if i_vline
  812. line.new(nymid, high, nymid, low, xloc.bar_time, extend.both, i_vcol, vstyle, 1)
  813. // END
  814.  
  815.  
  816. includeSymbol1 = input.bool(true, 'Include Symbol 1?', group='Symbols')
  817. useCurrentChartAsSymbol1 = input.bool(true, 'Use current chart\'s symbol as Symbol 1', group='Symbols')
  818. symbol1 = input.string('', 'Symbol 1', group='Symbols')
  819. includeSymbol2 = input.bool(false, 'Include Symbol 2?', group='Symbols')
  820. symbol2 = input.string('', 'Symbol 2', group='Symbols')
  821. includeSymbol3 = input.bool(false, 'Include Symbol 3?', group='Symbols')
  822. symbol3 = input.string('', 'Symbol 3', group='Symbols')
  823. includeSymbol4 = input.bool(false, 'Include Symbol 4?', group='Symbols')
  824. symbol4 = input.string('', 'Symbol 4', group='Symbols')
  825.  
  826. // Kill Switch for if no instruments were selected
  827. killSwitch = not includeSymbol1 and not includeSymbol2 and not includeSymbol3 and not includeSymbol4
  828.  
  829. includeRsi = input.bool(true, 'Include RSI', group='RSI')
  830. rsiLength = input.int(7, 'RSI Length', group='RSI')
  831. rsiBullThreshold = input.int(50, 'RSI Bull Threshold', group='RSI')
  832. rsiBearThreshold = input.int(50, 'RSI Bear Threshold', group='RSI')
  833. includeStoch = input.bool(true, 'Include Stochastic', group='Stochastic')
  834.  
  835. periodK = input.int(14, title='%K Length', minval=1, group='Stochastic')
  836. smoothK = input.int(1, title='%K Smoothing', minval=1, group='Stochastic')
  837. periodD = input.int(3, title='%D Smoothing', minval=1, group='Stochastic')
  838. useStochD = input.bool(false, 'Use Stochastic D instead of K', group='Stochastic')
  839. stochBullThreshold = input.int(50, 'Stochastic Bull Threshold', group='Stochastic')
  840. stochBearThreshold = input.int(50, 'Stochastic Bear Threshold', group='Stochastic')
  841.  
  842. includeMacdHist = input.bool(true, 'Include MACD Histogram', group='MACD')
  843. macdFastLength = input.int(12, 'MACD Fast Length', group='MACD')
  844. macdSlowLength = input.int(26, 'MACD Slow Length', group='MACD')
  845. macdSignalLength = input.int(9, 'MACD Signal Length', group='MACD')
  846.  
  847. // Kill Switch for if no indicators are selected
  848. confluenceKillSwitch = not includeMacdHist and not includeRsi and not includeStoch
  849.  
  850. stochastic(periodK, smoothK, periodD) =>
  851. kss = ta.sma(ta.stoch(close, high, low, periodK), smoothK)
  852. d = ta.sma(kss, periodD)
  853. output = useStochD ? d : kss
  854. output
  855.  
  856. confluence() =>
  857. [_, _, histLine] = ta.macd(close, macdFastLength, macdSlowLength, macdSignalLength)
  858. rsiLine = ta.rsi(close, rsiLength)
  859. stochLine = stochastic(periodK, smoothK, periodD)
  860. histBull = includeMacdHist ? histLine > 0 : true
  861. histBear = includeMacdHist ? histLine <= 0 : true
  862. rsiBull = includeRsi ? rsiLine > rsiBullThreshold : true
  863. rsiBear = includeRsi ? rsiLine < rsiBearThreshold : true
  864. stochBull = includeStoch ? stochLine > stochBullThreshold : true
  865. stochBear = includeStoch ? stochLine < stochBearThreshold : true
  866. signal = histBull and rsiBull and stochBull and not confluenceKillSwitch ? 1 : histBear and rsiBear and stochBear and not confluenceKillSwitch ? -1 : 0
  867. signal
  868.  
  869. confluenceSymbol1 = useCurrentChartAsSymbol1 ? confluence() : request.security(symbol1, '', confluence())
  870. confluenceSymbol2 = request.security(symbol2, '', confluence())
  871. confluenceSymbol3 = request.security(symbol3, '', confluence())
  872. confluenceSymbol4 = request.security(symbol4, '', confluence())
  873.  
  874. symbol1BullFilter = includeSymbol1 ? confluenceSymbol1 == 1 : true
  875. symbol1BearFilter = includeSymbol1 ? confluenceSymbol1 == -1 : true
  876.  
  877. symbol2BullFilter = includeSymbol2 ? confluenceSymbol2 == 1 : true
  878. symbol2BearFilter = includeSymbol2 ? confluenceSymbol2 == -1 : true
  879.  
  880. symbol3BullFilter = includeSymbol3 ? confluenceSymbol3 == 1 : true
  881. symbol3BearFilter = includeSymbol3 ? confluenceSymbol3 == -1 : true
  882.  
  883. symbol4BullFilter = includeSymbol4 ? confluenceSymbol4 == 1 : true
  884. symbol4BearFilter = includeSymbol4 ? confluenceSymbol4 == -1 : true
  885.  
  886. bullish = symbol1BullFilter and symbol2BullFilter and symbol3BullFilter and symbol4BullFilter and not killSwitch
  887. bearish = symbol1BearFilter and symbol2BearFilter and symbol3BearFilter and symbol4BearFilter and not killSwitch
  888.  
  889.  
  890.  
  891. plotshape(symbol1BearFilter ? bearish : na, title='bearish', color=#d82020, location=location.bottom, size=size.tiny, transp=25)
  892. plotshape(symbol1BullFilter ? bullish : na, title='bullish', color=#00FF00, location=location.bottom, size=size.tiny, transp=25)
  893.  
  894.  
  895.  
  896.  
  897. firstLookback = input.int(title='Max lookback for bullish lowest low pivot point', defval=10, minval=1, maxval=100)
  898. lowerLowLookback = input.int(title='Max lookback bullish for divergence', defval=30, minval=5, maxval=100)
  899. bearFirstLookback = input.int(title='Max lookback for bearish highest high pivot point', defval=10, minval=1, maxval=100)
  900. bearLowerLowLookback = input.int(title='Max lookback bearish for divergence', defval=30, minval=5, maxval=100)
  901. leftBars = 2
  902. rightBars = 2
  903.  
  904. //
  905. // BULLISH
  906. //
  907. pm = ta.pivotlow(low, leftBars, rightBars)
  908. [m, ms, mh] = ta.macd(close, 12, 26, 9)
  909.  
  910. buy = 0
  911. p1m = 0
  912. p2m = 0
  913. q = 0
  914.  
  915. for i = 1 to firstLookback by 1
  916. if q
  917. break
  918. if p1m == 0
  919. if pm[i] != 0
  920. confimationCandle = low[0] > high[i + rightBars]
  921. previousIsConfirmationCandle = low[1] > high[i + rightBars]
  922. if confimationCandle and not previousIsConfirmationCandle
  923. p1m := i + rightBars // We found the current low
  924. continue
  925. if p1m != 0
  926. for j = 1 + i to lowerLowLookback + i by 1
  927. if q
  928. break
  929. if p2m == 0
  930. if pm[j] != 0
  931. p2m := j + rightBars // We found the previous low
  932. continue
  933. if p2m != 0
  934. lowerLows = low[p1m] < low[p2m]
  935. if not lowerLows
  936. q := 1
  937. break
  938. if lowerLows
  939. macdDivergence = m[p1m] > m[p2m]
  940.  
  941. lowCrossesSlope = 0
  942. if macdDivergence
  943. x1 = p2m
  944. x2 = p1m
  945. y1 = low[p2m]
  946. y2 = low[p1m]
  947. // The lower lows line should not be broken by price
  948. for x = p1m to p2m by 1
  949. y = (y2 - y1) / (x2 - x1) * (x - x1) + y1
  950. if low[x] < y
  951. lowCrossesSlope := 1
  952. break
  953.  
  954. if lowCrossesSlope == 0 and macdDivergence
  955. line.new(x1=bar_index[p2m], y1=low[p2m], x2=bar_index[p1m], y2=low[p1m], width=6, color=color.green)
  956. buy := 1
  957. q := -1
  958. break
  959. else
  960. p2m := 0 // Try the next previous low
  961. continue
  962. //
  963. // BEARISH
  964. //
  965. hm = ta.pivothigh(high, leftBars, rightBars)
  966. sell = 0
  967. h1 = 0
  968. h2 = 0
  969. qBear = 0
  970.  
  971. for i = 1 to firstLookback by 1
  972. if qBear
  973. break
  974. if h1 == 0
  975. if hm[i] != 0
  976. confimationCandle = high[0] < low[i + rightBars]
  977. previousIsConfirmationCandle = high[1] < low[i + rightBars]
  978. if confimationCandle and not previousIsConfirmationCandle
  979. h1 := i + rightBars // We found the current high
  980. continue
  981. if h1 != 0
  982. for j = 1 + i to lowerLowLookback + i by 1
  983. if qBear
  984. break
  985. if h2 == 0
  986. if hm[j] != 0
  987. h2 := j + rightBars // We found the previous high
  988. continue
  989. if h2 != 0
  990. higherHighs = high[h1] > high[h2]
  991. if not higherHighs
  992. qBear := 1
  993. break
  994. if higherHighs
  995. macdDivergence = m[h1 - rightBars] < m[h2 - rightBars]
  996.  
  997. highCrossesSlope = 0
  998. if macdDivergence
  999. x1 = h2
  1000. x2 = h1
  1001. y1 = high[h2]
  1002. y2 = high[h1]
  1003. // The higher highs line should not be broken by price
  1004. for x = h1 to h2 by 1
  1005. y = (y2 - y1) / (x2 - x1) * (x - x1) + y1
  1006. if high[x] > y
  1007. highCrossesSlope := 1
  1008. break
  1009.  
  1010. if highCrossesSlope == 0 and macdDivergence
  1011. line.new(x1=bar_index[h2], y1=high[h2], x2=bar_index[h1], y2=high[h1], width=6, color=color.red)
  1012. sell := 1
  1013. qBear := -1
  1014. break
  1015. else
  1016. h2 := 0 // Try the next previous low
  1017. continue
  1018.  
Advertisement
Add Comment
Please, Sign In to add comment