Advertisement
xmd79

cdd1

Apr 22nd, 2021
1,182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 62.43 KB | None | 0 0
  1. //@version=4
  2. study("Gann medians", overlay = true, max_bars_back=300)
  3.  
  4.  
  5. method1 = input("Median", options=["EMA", "Median", "SMA"])
  6. length1 = input(12)
  7. mult1 = input(1, minval=0, maxval=1)
  8.  
  9. method2 = input("Median", options=["EMA", "Median", "SMA"])
  10. length2 = input(27)
  11. mult2 = input(1, minval=0, maxval=1)
  12.  
  13. method3 = input("Median", options=["EMA", "Median", "SMA"])
  14. length3 = input(56)
  15. mult3 = input(1, minval=0, maxval=1)
  16. //----
  17. Avg(x, length, method) =>
  18. sma_1 = sma(x, length)
  19. ema_1 = ema(x, length)
  20. percentile_linear_interpolation_1 = percentile_linear_interpolation(x, length, 50)
  21. method == "SMA" ? sma_1 :
  22. method == "EMA" ? ema_1 : percentile_linear_interpolation_1
  23. //----
  24. a1 = highest(length1) - max(close, open)
  25. b1 = min(close, open) - lowest(length1)
  26. c1 = max(close, open) + a1 * mult1
  27. d1 = min(close, open) - b1 * mult1
  28.  
  29. a2 = highest(length2) - max(close, open)
  30. b2 = min(close, open) - lowest(length2)
  31. c2 = max(close, open) + a2 * mult2
  32. d2 = min(close, open) - b2 * mult2
  33.  
  34. a3 = highest(length3) - max(close, open)
  35. b3 = min(close, open) - lowest(length3)
  36. c3 = max(close, open) + a3 * mult3
  37. d3 = min(close, open) - b3 * mult3
  38. //----
  39. e1 = Avg(c1, length1, method1)
  40. f1 = Avg(d1, length1, method1)
  41. g1 = 0
  42. cross_1 = cross(close, f1)
  43. g1 := cross(close, e1) ? 1 : cross_1 ? 0 : nz(g1[1])
  44.  
  45. e2 = Avg(c2, length2, method2)
  46. f2 = Avg(d2, length2, method2)
  47. g2 = 0
  48. cross_2 = cross(close, f2)
  49. g2 := cross(close, e2) ? 1 : cross_2 ? 0 : nz(g2[1])
  50.  
  51. e3 = Avg(c3, length3, method3)
  52. f3 = Avg(d3, length3, method3)
  53. g3 = 0
  54. cross_3 = cross(close, f3)
  55. g3 := cross(close, e3) ? 1 : cross_3 ? 0 : nz(g3[1])
  56. //---
  57. hilo1 = g1 * f1 + (1 - g1) * e1
  58. css1 = g1 == 1 ? color.green : color.red
  59. plot(hilo1, color=css1, style=plot.style_line, show_last=1, linewidth=1, transp=0, trackprice=true)
  60.  
  61. hilo2 = g2 * f2 + (1 - g2) * e2
  62. css2 = g2 == 1 ? color.green : color.red
  63. plot(hilo2, color=css2, style=plot.style_line, show_last=1, linewidth=1, transp=0, trackprice=true)
  64.  
  65. hilo3 = g3 * f3 + (1 - g3) * e3
  66. css3 = g3 == 1 ? color.green : color.red
  67. plot(hilo3, color=css3, style=plot.style_line, show_last=1, linewidth=1, transp=0, trackprice=true)
  68.  
  69.  
  70. //end of this part
  71.  
  72.  
  73. //@version=4
  74.  
  75. //study(title="HiLo Activator", overlay=true)
  76. length = input(3, minval=1)
  77. displace = input(0, minval=0)
  78. highsma = sma(high, length)
  79. lowsma = sma(low, length)
  80. swing = iff(close > highsma[displace], 1, iff(close < lowsma[displace], -1, 0))
  81. mah = highest(high, length)
  82. mal = lowest(low, length)
  83. var stop = 0.0
  84. stop := iff(swing==1, mal, iff(swing==-1, mah, stop[1]))
  85.  
  86. linecolor = iff(stop < low, color.green, color.red)
  87. plot(stop)
  88.  
  89. //end of this part
  90.  
  91. //study(title="TrapTrading (Study)", overlay=true)
  92. // input
  93. counterTrend = input(defval=false, title="Trade Mode (ON: Counter Trend OFF: Trend Following)", type=input.bool)
  94. len1 = input(defval=20, title="Period (1-200)", type=input.integer, minval=1, maxval=200)
  95. multiple = input(defval=0.7, title="Multiple", type=input.float)
  96.  
  97. m1 = close - close[len1]
  98. lowest_1 = lowest(abs(m1), len1)
  99. highest_1 = highest(abs(m1), len1)
  100. controlPoint = counterTrend ? lowest_1 == abs(m1) : highest_1 == abs(m1)
  101. baseLine = valuewhen(controlPoint, avg(close, close[len1]), 0)
  102.  
  103. // trap line
  104. atr = valuewhen(controlPoint, highest(max(max(atr(len1), atr(len1 * 2)), atr(len1 * 3)), len1), 0)
  105. line1Up = baseLine + atr * multiple
  106. line2Up = baseLine + atr * 2 * multiple
  107. line3Up = baseLine + atr * 3 * multiple
  108. line4Up = baseLine + atr * 4 * multiple
  109. line5Up = baseLine + atr * 5 * multiple
  110. line6Up = baseLine + atr * 6 * multiple
  111. line7Up = baseLine + atr * 7 * multiple
  112. line8Up = baseLine + atr * 8 * multiple
  113. line9Up = baseLine + atr * 9 * multiple
  114. line10Up = baseLine + atr * 10 * multiple
  115. line1Down = baseLine - atr * multiple
  116. line2Down = baseLine - atr * 2 * multiple
  117. line3Down = baseLine - atr * 3 * multiple
  118. line4Down = baseLine - atr * 4 * multiple
  119. line5Down = baseLine - atr * 5 * multiple
  120. line6Down = baseLine - atr * 6 * multiple
  121. line7Down = baseLine - atr * 7 * multiple
  122. line8Down = baseLine - atr * 8 * multiple
  123. line9Down = baseLine - atr * 9 * multiple
  124. line10Down = baseLine - atr * 10 * multiple
  125.  
  126. // draw
  127. //barcolor(controlPoint ? color.yellow : close >= baseLine ? color.teal : color.red, title="Candle Color")
  128.  
  129.  
  130. // find which bar is 5 days away from the current time
  131. milliseconds_in_5days = 1000 * 60 * 60 * 24 * 1 // millisecs * secs * min * hours * days
  132. leftborder = (timenow - time) < milliseconds_in_5days // true or na when false
  133. rightborder = barstate.islast
  134.  
  135.  
  136. plot(baseLine, title="Base Line", color=color.purple, linewidth=1, style=plot.style_stepline, transp=0, trackprice=true)
  137. //plot(leftborder?line1Up:na, title="1Up Line", color=color.red, linewidth=1, style=plot.style_stepline, transp=0)
  138. //plot(leftborder?line2Up:na, title="2Up Line", color=color.red, linewidth=1, style=plot.style_stepline, transp=0)
  139. //plot(leftborder?line3Up:na, title="3Up Line", color=color.red, linewidth=1, style=plot.style_stepline, transp=0)
  140. //plot(leftborder?line4Up:na, title="4Up Line", color=color.red, linewidth=1, style=plot.style_stepline, transp=0)
  141. //plot(leftborder?line5Up:na, title="5Up Line", color=color.red, linewidth=1, style=plot.style_stepline, transp=0)
  142. //plot(leftborder?line6Up:na, title="6Up Line", color=color.red, linewidth=1, style=plot.style_stepline, transp=0)
  143. //plot(leftborder?line7Up:na, title="7Up Line", color=color.red, linewidth=1, style=plot.style_stepline, transp=0)
  144. //plot(leftborder?line8Up:na, title="8Up Line", color=color.red, linewidth=1, style=plot.style_stepline, transp=0)
  145. //plot(leftborder?line9Up:na, title="9Up Line", color=color.red, linewidth=1, style=plot.style_stepline, transp=0)
  146. //plot(leftborder?line10Up:na, title="10Up Line", color=color.red, linewidth=1, style=plot.style_stepline, transp=0)
  147. //plot(leftborder?line1Down:na, title="1Down Line", color=color.green, linewidth=1, style=plot.style_stepline, transp=0)
  148. //plot(leftborder?line2Down:na, title="2Down Line", color=color.green, linewidth=1, style=plot.style_stepline, transp=0)
  149. //plot(leftborder?line3Down:na, title="3Down Line", color=color.green, linewidth=1, style=plot.style_stepline, transp=0)
  150. //plot(leftborder?line4Down:na, title="4Down Line", color=color.green, linewidth=1, style=plot.style_stepline, transp=0)
  151. //plot(leftborder?line5Down:na, title="5Down Line", color=color.green, linewidth=1, style=plot.style_stepline, transp=0)
  152. //plot(leftborder?line6Down:na, title="6Down Line", color=color.green, linewidth=1, style=plot.style_stepline, transp=0)
  153. //plot(leftborder?line7Down:na, title="7Down Line", color=color.green, linewidth=1, style=plot.style_stepline, transp=0)
  154. //plot(leftborder?line8Down:na, title="8Down Line", color=color.green, linewidth=1, style=plot.style_stepline, transp=0)
  155. //plot(leftborder?line9Down:na, title="9Down Line", color=color.green, linewidth=1, style=plot.style_stepline, transp=0)
  156. //plot(leftborder?line10Down:na, title="10Down Line", color=color.green, linewidth=1, style=plot.style_stepline, transp=0)
  157. //end of this part
  158.  
  159.  
  160.  
  161. upperMult = input(title="Upper Deviation", defval=2)
  162. lowerMult = input(title="Lower Deviation", defval=-2)
  163.  
  164. useUpperDev = input(title="Use Upper Deviation", defval=true)
  165. useLowerDev = input(title="Use Lower Deviation", defval=true)
  166. showPearson = input(title="Show Pearson's R", defval=true)
  167. extendLines = input(title="Extend Lines", defval=false)
  168.  
  169. len = input(title="Count", defval=100)
  170. src = input(title="Source", defval=close)
  171.  
  172. extend = extendLines ? extend.right : extend.none
  173.  
  174. calcSlope(src, len) =>
  175. if not barstate.islast or len <= 1
  176. [float(na), float(na), float(na)]
  177. else
  178. sumX = 0.0
  179. sumY = 0.0
  180. sumXSqr = 0.0
  181. sumXY = 0.0
  182. for i = 0 to len - 1
  183. val = src[i]
  184. per = i + 1.0
  185. sumX := sumX + per
  186. sumY := sumY + val
  187. sumXSqr := sumXSqr + per * per
  188. sumXY := sumXY + val * per
  189. slope = (len * sumXY - sumX * sumY) / (len * sumXSqr - sumX * sumX)
  190. average = sumY / len
  191. intercept = average - slope * sumX / len + slope
  192. [slope, average, intercept]
  193.  
  194. [s, aLR, i] = calcSlope(src, len)
  195.  
  196. startPrice = i + s * (len - 1)
  197. endPrice = i
  198. var line baseLineLR = na
  199.  
  200. if na(baseLineLR) and not na(startPrice)
  201. baseLineLR := line.new(bar_index - len + 1, startPrice, bar_index, endPrice, width=4, extend=extend, color=color.red)
  202. else
  203. line.set_xy1(baseLineLR, bar_index - len + 1, startPrice)
  204. line.set_xy2(baseLineLR, bar_index, endPrice)
  205. na
  206.  
  207. calcDev(src, len, slope, average, intercept) =>
  208. upDev = 0.0
  209. dnDev = 0.0
  210. stdDevAcc = 0.0
  211. dsxx = 0.0
  212. dsyy = 0.0
  213. dsxy = 0.0
  214.  
  215. periods = len - 1
  216.  
  217. daY = intercept + (slope * periods) / 2
  218. val = intercept
  219.  
  220. for i = 0 to periods
  221. price = high[i] - val
  222. if (price > upDev)
  223. upDev := price
  224.  
  225. price := val - low[i]
  226. if (price > dnDev)
  227. dnDev := price
  228.  
  229. price := src[i]
  230. dxt = price - average
  231. dyt = val - daY
  232.  
  233. price := price - val
  234. stdDevAcc := stdDevAcc + price * price
  235. dsxx := dsxx + dxt * dxt
  236. dsyy := dsyy + dyt * dyt
  237. dsxy := dsxy + dxt * dyt
  238. val := val + slope
  239.  
  240. stdDev = sqrt(stdDevAcc / (periods == 0 ? 1 : periods))
  241. pearsonR = dsxx == 0 or dsyy == 0 ? 0 : dsxy / sqrt(dsxx * dsyy)
  242. [stdDev, pearsonR, upDev, dnDev]
  243.  
  244. [stdDev, pearsonR, upDev, dnDev] = calcDev(src, len, s, aLR, i)
  245.  
  246. upperStartPrice = startPrice + (useUpperDev ? upperMult * stdDev : upDev)
  247. upperEndPrice = endPrice + (useUpperDev ? upperMult * stdDev : upDev)
  248. var line upper = na
  249.  
  250. lowerStartPrice = startPrice + (useLowerDev ? lowerMult * stdDev : -dnDev)
  251. lowerEndPrice = endPrice + (useLowerDev ? lowerMult * stdDev : -dnDev)
  252. var line lower = na
  253.  
  254. if na(upper) and not na(upperStartPrice)
  255. upper := line.new(bar_index - len + 1, upperStartPrice, bar_index, upperEndPrice, width=4, extend=extend, color=#0000ff)
  256. else
  257. line.set_xy1(upper, bar_index - len + 1, upperStartPrice)
  258. line.set_xy2(upper, bar_index, upperEndPrice)
  259. na
  260.  
  261. if na(lower) and not na(lowerStartPrice)
  262. lower := line.new(bar_index - len + 1, lowerStartPrice, bar_index, lowerEndPrice, width=4, extend=extend, color=#0000ff)
  263. else
  264. line.set_xy1(lower, bar_index - len + 1, lowerStartPrice)
  265. line.set_xy2(lower, bar_index, lowerEndPrice)
  266. na
  267.  
  268. // Pearson's R
  269. var label r = na
  270. transparent = color.new(color.white, 100)
  271. label.delete(r[1])
  272. if showPearson and not na(pearsonR)
  273. r := label.new(bar_index - len + 1, lowerStartPrice, tostring(pearsonR, "#.################"), color=transparent, textcolor=#0000ff, size=size.normal, style=label.style_labelup)
  274. //end of this part
  275.  
  276.  
  277. testStartYear = input(2019, "Backtest Start Year")
  278. testStartMonth = input(10, "Backtest Start Month")
  279. testStartDay = input(20, "Backtest Start Day")
  280. testStartHour = input(0, "Backtest Start Hour")
  281. testStartMin = input(0, "Backtest Start Minute")
  282. testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,testStartHour,testStartMin)
  283. testStopYear = input(2099, "Backtest Stop Year")
  284. testStopMonth = input(1, "Backtest Stop Month")
  285. testStopDay = input(30, "Backtest Stop Day")
  286. testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)
  287. testPeriod() =>
  288. time >= testPeriodStart and time <= testPeriodStop ? true : false
  289.  
  290.  
  291. lenH = input(title='Length High', type=input.integer, defval=20, minval=1)
  292. lenL = input(title='Length Low', type=input.integer, defval=20, minval=1)
  293.  
  294. fun(src, len, isHigh, _style, _yloc, _color) =>
  295. p = nz(src[len])
  296. isFound = true
  297. for i = 0 to len * 2
  298. if isHigh and src[i] > p
  299. isFound := false
  300. if not isHigh and src[i] < p
  301. isFound := false
  302. if isFound and testPeriod()
  303. label.new(bar_index[len], p, tostring(p), style=_style, yloc=_yloc, color=_color)
  304. line.new(bar_index[len], p, bar_index, p, extend=extend.right, color=_color)
  305.  
  306.  
  307.  
  308. fun(high, lenH, true, label.style_labeldown, yloc.abovebar, color.red)
  309. fun(low, lenL, false, label.style_labelup, yloc.belowbar, color.green)
  310.  
  311. //end of this part
  312.  
  313.  
  314.  
  315. price = input(type=input.source, defval=ohlc4)
  316.  
  317. // Strategy vars setup here
  318. Depth = input(56, title="Depth") // Depth
  319. Deviation = input(5, title="Deviation") // Deviation
  320.  
  321. // main logic
  322. // ZigZag
  323. lastlow = 0.0, lasthigh = 0.0
  324. lastlow := nz(lastlow[1])
  325. lasthigh := nz(lasthigh[1])
  326.  
  327. data(x) =>
  328. d = security(syminfo.tickerid, timeframe.period, x, gaps = barmerge.gaps_off, lookahead = barmerge.lookahead_on)
  329. d
  330. getLow(x, y, z, a) =>
  331. lastlow = y
  332. v = data(x)
  333. m = v==lastlow or data(z) - v > a*syminfo.mintick
  334. if v!=lastlow
  335. lastlow := v
  336. if m
  337. v := 0.0
  338. [v,lastlow]
  339. getHigh(x, y, z, a) =>
  340. lasthigh = y
  341. v = data(x)
  342. m = v==lasthigh or v - data(z) > a*syminfo.mintick
  343. if v!=lasthigh
  344. lasthigh := v
  345. if m
  346. v := 0.0
  347. [v,lasthigh]
  348.  
  349. [v,e] = getLow(lowest(Depth), lastlow, low, Deviation)
  350. lastlow := e
  351. zBB = v != 0.0
  352. [v1,ee1] = getHigh(highest(Depth), lasthigh, high, Deviation)
  353. lasthigh := ee1
  354. zSS = v1 != 0.0
  355.  
  356. zigzagDirection = -1
  357. zigzagHigh = 0
  358. zigzagLow = 0
  359. zigzagDirection := zBB ? 0 : zSS ? 1 : nz(zigzagDirection[1], -1)
  360. virtualLow = zigzagLow[1] + 1
  361. if not zBB or (zBB and zigzagDirection == zigzagDirection[1] and low > low[virtualLow])
  362. zigzagLow := nz(zigzagLow[1]) + 1
  363.  
  364. virtualHigh = zigzagHigh[1] + 1
  365. if not zSS or (zSS and zigzagDirection == zigzagDirection[1] and high < high[virtualHigh])
  366. zigzagHigh := nz(zigzagHigh[1]) + 1
  367. a=bar_index-zigzagLow
  368. b=bar_index-zigzagHigh
  369. var color c = na, c := fixnan(a < b[1] ? color.lime : a > b[1] ? color.red : na)
  370. //barcolor(color=color.lime)
  371. line zigzag = line.new(bar_index-zigzagLow, low[zigzagLow], bar_index-zigzagHigh, high[zigzagHigh], color=c, style=line.style_solid, width=4)
  372. if (zigzagDirection == zigzagDirection[1])
  373. line.delete(zigzag[1])
  374.  
  375. l = label.new(bar_index-zigzagHigh, na)
  376. label.set_text(l, "Sell")
  377. label.set_color(l, color.red)
  378. label.set_yloc(l, yloc.abovebar)
  379. label.set_style(l, label.style_labeldown)
  380. if (zigzagDirection == zigzagDirection[1])
  381. label.delete(l[1])
  382.  
  383.  
  384.  
  385. l_b = label.new(bar_index-zigzagLow, na)
  386. label.set_text(l_b, "Buy")
  387. label.set_color(l_b, color.green)
  388. label.set_yloc(l_b, yloc.belowbar)
  389. label.set_style(l_b, label.style_labelup)
  390. if (zigzagDirection == zigzagDirection[1])
  391. label.delete(l_b[1])
  392.  
  393.  
  394. zzPrevHigh = zigzagHigh[1]
  395. zzPrevLow = zigzagLow[1]
  396. if not na(zzPrevHigh[1])
  397. zzPrevHigh := zzPrevHigh[1] + 1
  398.  
  399. if not na(zzPrevLow[1])
  400. zzPrevLow := zzPrevLow[1] + 1
  401.  
  402. if zigzagDirection != zigzagDirection[1]
  403. if zigzagDirection == 1
  404. zzPrevHigh := zigzagHigh[1] + 1
  405. if zigzagDirection == 0
  406. zzPrevLow := zigzagLow[1] + 1
  407.  
  408. //end of this part
  409.  
  410. // RSI Settings for user
  411. rsiSource = input(title="RSI Source", type=input.source, defval=close)
  412. rsiLength = input(title="RSI Length", type=input.integer, defval=7)
  413. rsiOverbought = input(title="RSI Overbought", type=input.integer, defval=70, minval=50, maxval=100)
  414. rsiOvesold = input(title="RSI Oversold", type=input.integer, defval=30, minval=1, maxval=50)
  415.  
  416. // RSI value based on inbuilt RSI
  417. rsiValue = rsi(rsiSource, rsiLength)
  418.  
  419. // Get the current state
  420. isOverbought = rsiValue >= rsiOverbought
  421. isOversold = rsiValue <= rsiOvesold
  422.  
  423. // State of the last extreme 0 for initialization, 1 = overbought, 2 = oversold
  424. var laststate = 0
  425.  
  426. // Highest and Lowest prices since the last state change
  427. var hh = low
  428. var ll = high
  429.  
  430. // Labels
  431. var label labelll = na
  432. var label labelhh = na
  433.  
  434. // Swing lines
  435. var line line_up = na
  436. var line line_down = na
  437.  
  438.  
  439. // We go from overbought straight to oversold NEW DRAWINGS CREATED HERE
  440. if(laststate == 1 and isOversold)
  441. ll := low
  442. labelll := label.new(bar_index, low, style=label.style_label_up, color=color.green, size=size.tiny)
  443. labelhh_low = label.get_x(labelhh)
  444. labelhh_pos = label.get_y(labelhh)
  445. line_down := line.new(bar_index, high, labelhh_low, labelhh_pos, width=2)
  446.  
  447. // We go from oversold straight to overbought NEW DRAWINGS CREATED HERE
  448. if(laststate == 2 and isOverbought)
  449. hh := high
  450. labelhh := label.new(bar_index, high, style=label.style_label_down, color=color.red, size=size.tiny)
  451. labelll_low = label.get_x(labelll)
  452. labelll_pos = label.get_y(labelll)
  453. line_up := line.new(bar_index, high, labelll_low, labelll_pos, width=2)
  454.  
  455.  
  456. // If we are overbought
  457. if(isOverbought)
  458. if(high >= hh)
  459. hh := high
  460. label.set_x(labelhh, bar_index)
  461. label.set_y(labelhh, high)
  462. line.set_x1(line_up, bar_index)
  463. line.set_y1(line_up, high)
  464. laststate := 1
  465.  
  466. // If we are oversold
  467. if(isOversold)
  468. if(low <= ll)
  469. ll := low
  470. label.set_x(labelll, bar_index)
  471. label.set_y(labelll, low)
  472. line.set_x1(line_down, bar_index)
  473. line.set_y1(line_down, low)
  474. laststate := 2
  475.  
  476.  
  477. // If last state was overbought and we are overbought
  478. if(laststate == 1 and isOverbought)
  479. if(hh <= high)
  480. hh := high
  481. label.set_x(labelhh, bar_index)
  482. label.set_y(labelhh, high)
  483. line.set_x1(line_up, bar_index)
  484. line.set_y1(line_up, high)
  485.  
  486. //If we are oversold and the last state was oversold, move the drawings to the lowest price
  487. if(laststate == 2 and isOversold)
  488. if(low <= ll)
  489. ll := low
  490. label.set_x(labelll, bar_index)
  491. label.set_y(labelll, low)
  492. line.set_x1(line_down, bar_index)
  493. line.set_y1(line_down, low)
  494.  
  495.  
  496. // If last state was overbought
  497. if(laststate == 1)
  498. if(hh <= high)
  499. hh := high
  500. label.set_x(labelhh, bar_index)
  501. label.set_y(labelhh, high)
  502. line.set_x1(line_up, bar_index)
  503. line.set_y1(line_up, high)
  504.  
  505. // If last stare was oversold
  506. if(laststate == 2)
  507. if(ll >= low)
  508. ll := low
  509. label.set_x(labelll, bar_index)
  510. label.set_y(labelll, low)
  511. line.set_x1(line_down, bar_index)
  512. line.set_y1(line_down, low)
  513.  
  514. //end of this part
  515.  
  516.  
  517.  
  518.  
  519. //@version=4
  520. //study("momentum zigzag", overlay = true)
  521. lengthZZZ = input(10, title = "High/Low length")
  522. hZZZ = highest(high, lengthZZZ * 2 + 1)
  523. lZZZ = lowest(low, lengthZZZ * 2 + 1)
  524. f_isMin(len) =>
  525. lZZZ == low[len]
  526. f_isMax(len) =>
  527. hZZZ == high[len]
  528.  
  529. var dirUp = false
  530. var lastLow = high * 100
  531. var lastHigh = 0.0
  532. var timeLow = bar_index
  533. var timeHigh = bar_index
  534. var line li = na
  535. f_drawLine() =>
  536. _li_color = dirUp ? color.gray : color.gray
  537. line.new(
  538. timeHigh - lengthZZZ, lastHigh,
  539. timeLow - lengthZZZ, lastLow,
  540. xloc.bar_index, color=_li_color, width=1
  541. )
  542.  
  543. if dirUp
  544. if (f_isMin(lengthZZZ) and low[lengthZZZ] < lastLow)
  545. lastLow := low[lengthZZZ]
  546. timeLow := bar_index
  547. line.delete(li)
  548. li := f_drawLine()
  549.  
  550. if (f_isMax(lengthZZZ) and high[lengthZZZ] > lastLow)
  551. lastHigh := high[lengthZZZ]
  552. timeHigh := bar_index
  553. dirUp := false
  554. li := f_drawLine()
  555.  
  556. if not dirUp
  557. if (f_isMax(lengthZZZ) and high[lengthZZZ] > lastHigh)
  558. lastHigh := high[lengthZZZ]
  559. timeHigh := bar_index
  560. line.delete(li)
  561. li := f_drawLine()
  562. if f_isMin(lengthZZZ) and low[lengthZZZ] < lastHigh
  563. lastLow := low[lengthZZZ]
  564. timeLow := bar_index
  565. dirUp := true
  566. li := f_drawLine()
  567. if (f_isMax(lengthZZZ) and high[lengthZZZ] > lastLow)
  568. lastHigh := high[lengthZZZ]
  569. timeHigh := bar_index
  570. dirUp := false
  571. li := f_drawLine()
  572.  
  573. //end of this part
  574.  
  575.  
  576. use_alt_series = input(defval=false, title='Use alternative source?')
  577. alt_src = input(defval=close, title='Alternative source:')
  578. hSR = use_alt_series ? alt_src : high
  579. lSR = use_alt_series ? alt_src : low
  580.  
  581. window = input(defval=14, title='lookback window :', type=input.integer)
  582. percent_of_range_for_trade_zone = input(defval=15.0, title='Percent of the range to use for trade zone', type=input.float) * 0.01
  583.  
  584. short_term_top = valuewhen(hSR >= highest(hSR, window), hSR, 0)
  585. short_term_bot = valuewhen(lSR <= lowest(lSR, window), lSR, 0)
  586.  
  587. short_term_resist = change(short_term_top) != 0 ? na : short_term_top
  588. short_term_suport = change(short_term_bot) != 0 ? na : short_term_bot
  589.  
  590. short_term_resist_plot = plot(series=short_term_resist, title='STR', color=color.fuchsia, linewidth=2, style=plot.style_linebr, transp=0)
  591. short_term_suport_plot = plot(series=short_term_suport, title='STS', color=color.aqua, linewidth=2, style=plot.style_linebr, transp=0)
  592.  
  593. fill(short_term_suport_plot,short_term_resist_plot, color=color.aqua, transp=95, title=" Trade Zone ")
  594.  
  595. // Calculate entry zone:
  596. float short_term_resist_trade_limit = na
  597. float short_term_suport_trade_limit = na
  598.  
  599. range = fixnan(short_term_resist) - fixnan(short_term_suport)
  600.  
  601. if not na(short_term_resist)
  602. if not na(short_term_resist_trade_limit[1])
  603. short_term_resist_trade_limit := short_term_resist_trade_limit[1]
  604. else
  605. short_term_resist_trade_limit := short_term_resist - range * percent_of_range_for_trade_zone
  606.  
  607. if not na(short_term_suport)
  608. if not na(short_term_suport_trade_limit[1])
  609. short_term_suport_trade_limit := short_term_suport_trade_limit[1]
  610. else
  611. short_term_suport_trade_limit := short_term_suport + range * percent_of_range_for_trade_zone
  612.  
  613. short_term_resist_trade_limit_plot = plot(series=short_term_resist_trade_limit, title='', color=color.red, linewidth=1, style=plot.style_linebr, transp=0)
  614. short_term_suport_trade_limit_plot = plot(series=short_term_suport_trade_limit, title='', color=color.yellow, linewidth=1, style=plot.style_linebr, transp=0)
  615.  
  616. //end of this part
  617.  
  618. lookback = input(defval=20, title="# of Candles to Look Back", type=input.integer)
  619. srcAA = "Close"
  620.  
  621. pivot_high = iff(srcAA == "Close", pivothigh(high, lookback, lookback), pivothigh(high, lookback, lookback))
  622. pivot_low = iff(srcAA == "Close", pivotlow(low, lookback, lookback), pivotlow(low, lookback, lookback))
  623.  
  624. plot_high = iff(srcAA == "Close", valuewhen(pivot_high, high[lookback], 0), valuewhen(pivot_high, high[lookback], 0))
  625. plot_low = iff(srcAA == "Close", valuewhen(pivot_low, low[lookback], 0), valuewhen(pivot_low, low[lookback], 0))
  626.  
  627. resistance = plot(plot_high, style=plot.style_line, title="Resistance Line", color=color.orange, show_last=1, linewidth=2, trackprice=true)
  628. support = plot(plot_low, style=plot.style_line, title="Support Line", color=color.orange, show_last=1, linewidth=2, trackprice=true)
  629.  
  630.  
  631.  
  632. //end of this part
  633.  
  634.  
  635.  
  636. // - INPUTS
  637. ShowPivots = input(true, title="Show Pivot Points")
  638. ShowHHLL = input(true, title="Show HH,LL,LH,HL markers on Pivots Points")
  639. left = input(5, minval=1, title="Pivot Length Left Hand Side")
  640. right = input(5, minval=1, title="Pivot Length Right Hand Side")
  641. //
  642.  
  643. var barCounter = 0
  644. barCounter := barCounter + 1
  645. f_draw_infopanel(_x, _y, _line, _text)=>
  646. _rep_text = ""
  647. if barstate.islast
  648. for _l = 0 to _line
  649. _rep_text := _rep_text + "\n"
  650. _rep_text := _rep_text + _text
  651. var label _la = na
  652. //a = label.get_text(_la)
  653. label.delete(_la)
  654. _la := label.new(
  655. x=_x, y=_y,
  656. text=_rep_text, xloc=xloc.bar_time, yloc=yloc.price,
  657. color=color.black, style=label.style_labelup, textcolor=color.silver, size=size.small)
  658.  
  659. // Determine pivots
  660. pvtLenL = left
  661. pvtLenR = right
  662.  
  663. // Get High and Low Pivot Points
  664. pvthi_ = pivothigh(high, pvtLenL, pvtLenR)
  665. pvtlo_ = pivotlow(low, pvtLenL, pvtLenR)
  666.  
  667. // Force Pivot completion before plotting.
  668. pvthi = pvthi_
  669. pvtlo = pvtlo_
  670.  
  671. // ||-----------------------------------------------------------------------------------------------------||
  672. // ||--- Higher Highs, Lower Highs, Higher Lows, Lower Lows -------------------------------------------||
  673. valuewhen_1 = valuewhen(pvthi, high[pvtLenR], 1)
  674. valuewhen_2 = valuewhen(pvthi, high[pvtLenR], 0)
  675. higherhigh = na(pvthi) ? na : valuewhen_1 < valuewhen_2 ? pvthi : na
  676. valuewhen_3 = valuewhen(pvthi, high[pvtLenR], 1)
  677. valuewhen_4 = valuewhen(pvthi, high[pvtLenR], 0)
  678. lowerhigh = na(pvthi) ? na : valuewhen_3 > valuewhen_4 ? pvthi : na
  679. valuewhen_5 = valuewhen(pvtlo, low[pvtLenR], 1)
  680. valuewhen_6 = valuewhen(pvtlo, low[pvtLenR ], 0)
  681. higherlow = na(pvtlo) ? na : valuewhen_5 < valuewhen_6 ? pvtlo : na
  682. valuewhen_7 = valuewhen(pvtlo, low[pvtLenR], 1)
  683. valuewhen_8 = valuewhen(pvtlo, low[pvtLenR ], 0)
  684. lowerlow = na(pvtlo) ? na : valuewhen_7 > valuewhen_8 ? pvtlo : na
  685.  
  686.  
  687. // If selected Display the HH/LL above/below candle.
  688. plotshape(ShowHHLL ? higherhigh : na, title='HH', location=location.abovebar, color=color.green, text="HH", offset=-pvtLenR)
  689. plotshape(ShowHHLL ? higherlow : na, title='HL', location=location.belowbar, color=color.green, text="HL", offset=-pvtLenR)
  690. plotshape(ShowHHLL ? lowerhigh : na, title='LH', location=location.abovebar, color=color.red, text="LH", offset=-pvtLenR)
  691. plotshape(ShowHHLL ? lowerlow : na, title='LL', location=location.belowbar, color=color.red, text="LL", offset=-pvtLenR)
  692.  
  693.  
  694. useColors = input(title="Fill with colors?",defval=true)
  695. isess = session.regular
  696. t = tickerid(syminfo.prefix, syminfo.ticker, session=isess)
  697. igaps = barmerge.gaps_off
  698. yesterdayHigh = security(t,"D",high[1],gaps=igaps, lookahead=barmerge.lookahead_on)
  699. yesterdayClose = security(t,"D",close[1],gaps=igaps, lookahead=barmerge.lookahead_on)
  700. yesterdayLow = security(t,"D",low[1],gaps=igaps, lookahead=barmerge.lookahead_on)
  701.  
  702.  
  703. // Plot the other time frame's data
  704. aH= timeframe.isintraday ? yesterdayHigh : na
  705.  
  706. cL= timeframe.isintraday ? yesterdayLow: na
  707.  
  708. up5on = input(true, title="5 Minute Opening Range High")
  709. down5on = input(true, title="5 Minute Opening Range Low")
  710.  
  711. is_newbar(res) => change(time(res)) != 0
  712.  
  713. adopt(r, s) => security(syminfo.ticker, r, s)
  714.  
  715. high_range = valuewhen(is_newbar('D'),high,0)
  716. low_range = valuewhen(is_newbar('D'),low,0)
  717.  
  718. high_rangeL = valuewhen(is_newbar('D'),high,0)
  719. low_rangeL = valuewhen(is_newbar('D'),low,0)
  720.  
  721. up5 =up5on ? adopt('5', high_rangeL): na
  722. down5 =down5on ? adopt('5', low_rangeL): na
  723.  
  724.  
  725. bColor = #000000
  726. rColor = #ff0a02
  727. sColor = #008f0e
  728. pColor =#0900ff
  729. mColor =color.maroon
  730.  
  731.  
  732. myWidthMainLevels = input(title="Line width for Main levels", type=input.integer, defval=1, minval=1)
  733. myStyle = plot.style_circles
  734.  
  735.  
  736. //plot(aH, title="H", color=#008f0e, linewidth=myWidthMainLevels, style=myStyle)
  737. //plot(cL, title="L", color=#ff0a02, linewidth=myWidthMainLevels, style=myStyle)
  738.  
  739. //plot(up5, title="UP", color=#000000, linewidth=myWidthMainLevels, style=myStyle)
  740. //plot(down5, title="DOWN", color=#000000, linewidth=myWidthMainLevels, style=myStyle)
  741.  
  742. //end of this part
  743.  
  744. //----- User inputs ---------------------
  745. Lookback1 = input(title="Lookback Left", type=input.integer, defval=200, minval=1)
  746. Lookback2 = input(title="Lookback Right", type=input.integer, defval=0, minval=0)
  747. VertLR = input(title="Show Vertical Left/Right", type=input.bool, defval=true)
  748. VertHL = input(title="Show Vertical Highest/Lowest", type=input.bool, defval=true)
  749. Count = input(title="Show Counts", type=input.bool, defval=true)
  750. FullCount = input(title="Count All Bars", type=input.bool, defval=false)
  751. Fibs = input(title="Show Fib Retrace Lines", type=input.bool, defval=false)
  752. FibsExtHigh = input(title="Show Fib Ext Highs", type=input.bool, defval=false)
  753. FibsExtLow = input(title="Show Fib Ext Lows", type=input.bool, defval=false)
  754.  
  755.  
  756. //----- Main ---------------------
  757. // Get left and right endpoints. Though user input says "left" and "right", they are interchangeable.
  758. // The larger number is left, smaller number right.
  759. leftHL = max(Lookback1, Lookback2)
  760. rightHL = min(Lookback1, Lookback2)
  761. // Total num bars. Must be > 0 for highest() and lowest() to work. Add 1 to left bar, if needed.
  762. leftHL := leftHL - rightHL == 0 ? leftHL + 1 : leftHL
  763. lengthHL = leftHL - rightHL
  764.  
  765. // Highest price, looking back between the left/right endpoints
  766. highBack = highest(high[rightHL], lengthHL)
  767. // Get # of bars back from present bar (offset).
  768. // NOTE: highestbars() returns a negative integer. Thus, subtract the right endpoint to get
  769. // offset from present (right-edge) bar
  770. highOffset = highestbars(high[rightHL], lengthHL) - rightHL
  771.  
  772. // Lowest price, looking back
  773. lowBack = lowest(low[rightHL], lengthHL)
  774. lowOffset = lowestbars(low[rightHL], lengthHL) - rightHL
  775.  
  776. // Create a series of timestamps per bar. Needed to determine which bars are at the right edge,
  777. // While "n" starts at zero (left-edge bar) and counts up to the right-edge bar, this timestamp
  778. // (or tick) series counts the other way: max value at the left-edge, counting down to zero
  779. // at the right-edge.
  780. // This tick series is only valid while the indicator loads because "timenow" is the timestamp
  781. // of loading and "time" is the timestamp of a bar. The difference between the two timestamps
  782. // shrinks to zero as the righ-edge bar is processed. After loading, "timenow" and "time" are
  783. // the same value. Thus, "tick" always equals zero as new bars appear. But, for this indicator
  784. // this is sufficient behavior...
  785. tick = round((timenow - time) / change(time)) // Each bar is a tick (float) in the timeline
  786. // Make a boolean mask for bars between left and right endpoints
  787. mask = FullCount ? true : tick < left and tick >= rightHL ? true : false
  788. // Determine the value of n at the left endpoint, used for visual counts of bars in mask
  789. nOffset = float(na)
  790. nOffset := FullCount ? 0 : tick == leftHL ? bar_index : nz(nOffset[1])
  791.  
  792. // Note: It would be nice to count between the highest/lowest bars, instead of left/right bars,
  793. // but this isn't possible because highOffset and lowOffset are moving around as the
  794. // indicator loads. Thus, "mask" isn't accurate...
  795.  
  796. //---- Plotting ---------------------
  797. // Horizontal Lines: Highest, Lowest dynamic lines
  798. // Params trackprice and offset make the horizontal line dynamic, adjusting to new highs/lows
  799. plot(highBack, title="Highest", color=color.red, linewidth=2, trackprice=true, offset=-9999)
  800. plot(lowBack, title="Lowest", color=color.green, linewidth=2, trackprice=true, offset=-9999)
  801.  
  802. // Veritcal Lines
  803. // Use barstate to paint/re-paint vertical lines, as new bars come into the data set.
  804. // islast - True for right most bar in data set. Use this to paint vertical bar, then push it back
  805. // in time with the offset parameter.
  806. // isrealtime - False while indicator loads. True for the right most bar, after loading.
  807. // isconfirmed - False while bar is not closed. True when close price appears.
  808. // isrealtime and isconfirmed - While indicator loads, ignore isconfirmed. After loading, isconfirmed
  809. // turns off the vertical line, as the bar closes. The next (new) bar is painted. This keeps
  810. // the vertical bar moving forward, as new bars appear, erasing the old (previous) vertical bar.
  811. VertLRShow = VertLR ? barstate.isrealtime and barstate.isconfirmed ? false :
  812. barstate.islast ? true : false : false
  813. // Can't use plot() with histogram/column because histbase can't accept "series" values
  814. bgcolor(VertLRShow ? color.gray : na, title="Vertical Left", transp=60, offset=-leftHL + 1)
  815. bgcolor(VertLRShow ? color.gray : na, title="Vertical Right", transp=60, offset=-rightHL)
  816. // Show vertical highest/lowest lines?
  817. VertHLShow = VertHL ? barstate.isrealtime and barstate.isconfirmed ? false :
  818. barstate.islast ? true : false : false
  819. bgcolor(VertHLShow ? color.red : na, title="Vertical Highest", transp=60, offset=highOffset)
  820. bgcolor(VertHLShow ? color.green : na, title="Vertical Lowest", transp=60, offset=lowOffset)
  821.  
  822. // Fib levels extension and retracement
  823. priceRange = highBack - lowBack
  824. plot(FibsExtHigh ? lowBack + 3.618 * priceRange : na, title="3.618", color=color.lime, linewidth=2, trackprice=true, offset=-9999)
  825. plot(FibsExtHigh ? lowBack + 2.618 * priceRange : na, title="2.618", color=color.lime, linewidth=2, trackprice=true, offset=-9999)
  826. plot(FibsExtHigh ? lowBack + 1.618 * priceRange : na, title="1.618", color=color.lime, linewidth=2, trackprice=true, offset=-9999)
  827. plot(FibsExtHigh ? lowBack + 1.1 * priceRange : na, color=#88888800, trackprice=true, offset=-9999, editable=false) // invisible line to work around pine plot bug
  828. plot(Fibs ? lowBack + 1.1 * priceRange : na, color=#88888800, trackprice=true, offset=-9999, editable=false) // invisible line to work around pine plot bug
  829. plot(Fibs ? lowBack + 0.786 * priceRange : na, title="0.786", color=color.aqua, linewidth=1, trackprice=true, offset=-9999)
  830. plot(Fibs ? lowBack + 0.618 * priceRange : na, title="0.618", color=color.orange, linewidth=2, trackprice=true, offset=-9999)
  831. plot(Fibs ? lowBack + 0.50 * priceRange : na, title="0.5", color=color.yellow, linewidth=2, trackprice=true, offset=-9999)
  832. plot(Fibs ? lowBack + 0.382 * priceRange : na, title="0.382", color=color.orange, linewidth=2, trackprice=true, offset=-9999)
  833. plot(Fibs ? lowBack + 0.236 * priceRange : na, title="0.236", color=color.aqua, linewidth=1, trackprice=true, offset=-9999)
  834. plot(Fibs ? highBack - 1.1 * priceRange : na, color=#88888800, trackprice=true, offset=-9999, editable=false) // invisible line to work around pine plot bug
  835. plot(FibsExtLow ? highBack - 1.1 * priceRange : na, color=#88888800, trackprice=true, offset=-9999, editable=false) // invisible line to work around pine plot bug
  836. plot(FibsExtLow ? highBack - 1.618 * priceRange : na, title="1.618", color=color.fuchsia, linewidth=2, trackprice=true, offset=-9999)
  837. plot(FibsExtLow ? highBack - 2.618 * priceRange : na, title="2.618", color=color.fuchsia, linewidth=2, trackprice=true, offset=-9999)
  838. plot(FibsExtLow ? highBack - 3.618 * priceRange : na, title="3.618", color=color.fuchsia, linewidth=2, trackprice=true, offset=-9999)
  839.  
  840. // Lookback bar count
  841. countMod = mask ? (bar_index - nOffset) % 10 : na
  842. countInt = mask ? floor((bar_index - nOffset) / 10) % 10 : na
  843. plotshape(Count and countMod != 0 ? true : na, style=shape.circle, text="-", textcolor=color.gray, color=#88888800, location=location.bottom, size=size.auto, editable=false)
  844. plotshape(Count and countMod == 0 and countInt == 0 ? true : na, style=shape.circle, text="0", textcolor=color.gray, color=#88888800, location=location.bottom, size=size.auto, editable=false)
  845. plotshape(Count and countMod == 0 and countInt == 1 ? true : na, style=shape.circle, text="1", textcolor=color.gray, color=#88888800, location=location.bottom, size=size.auto, editable=false)
  846. plotshape(Count and countMod == 0 and countInt == 2 ? true : na, style=shape.circle, text="2", textcolor=color.gray, color=#88888800, location=location.bottom, size=size.auto, editable=false)
  847. plotshape(Count and countMod == 0 and countInt == 3 ? true : na, style=shape.circle, text="3", textcolor=color.gray, color=#88888800, location=location.bottom, size=size.auto, editable=false)
  848. plotshape(Count and countMod == 0 and countInt == 4 ? true : na, style=shape.circle, text="4", textcolor=color.gray, color=#88888800, location=location.bottom, size=size.auto, editable=false)
  849. plotshape(Count and countMod == 0 and countInt == 5 ? true : na, style=shape.circle, text="5", textcolor=color.gray, color=#88888800, location=location.bottom, size=size.auto, editable=false)
  850. plotshape(Count and countMod == 0 and countInt == 6 ? true : na, style=shape.circle, text="6", textcolor=color.gray, color=#88888800, location=location.bottom, size=size.auto, editable=false)
  851. plotshape(Count and countMod == 0 and countInt == 7 ? true : na, style=shape.circle, text="7", textcolor=color.gray, color=#88888800, location=location.bottom, size=size.auto, editable=false)
  852. plotshape(Count and countMod == 0 and countInt == 8 ? true : na, style=shape.circle, text="8", textcolor=color.gray, color=#88888800, location=location.bottom, size=size.auto, editable=false)
  853. plotshape(Count and countMod == 0 and countInt == 9 ? true : na, style=shape.circle, text="9", textcolor=color.gray, color=#88888800, location=location.bottom, size=size.auto, editable=false)
  854.  
  855. //end of this part
  856.  
  857.  
  858.  
  859.  
  860. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  861. // © LonesomeTheBlue
  862.  
  863. //@version=4
  864. //study("Candlestick Reversal System", overlay = true)
  865. pivotlbar = input(defval = 5, title ="Length to Highest/Lowest")
  866. highleftempty = pivothigh(pivotlbar, 0)
  867. lowleftempty = pivotlow(pivotlbar, 0)
  868.  
  869. // Wick Reversal System
  870. l01 = input(true, title = "Enable Wick Reversal System")
  871. wick_multiplier = input(title = "Wick Multiplier", defval = 2.5, step = 0.5, maxval = 20)
  872. body_percentage = input(title = "Body Percentage", defval = 0.25, step = 0.1, maxval = 1)
  873.  
  874. O = open
  875. C = close
  876. H = high
  877. L = low
  878.  
  879. Wlongsignal = (C > O) and (O - L) >= ((C - O) * wick_multiplier) and (H - C) <= ((H - L) * body_percentage) or
  880. (C < O) and (C - L) >= ((O - C) * wick_multiplier) and (H - C) <= ((H - L) * body_percentage) or
  881. (C == O and C != H) and (H - L) >= ((H - C) * wick_multiplier) and (H - C) <= ((H - L) * body_percentage) or
  882. (O == H and C == H) and (H - L) >= sma((H - L), 50)
  883.  
  884. Wshortsignal = (C < O) and (H - O) >= ((O - C) * wick_multiplier) and (C - L) <= ((H - L) * body_percentage) or
  885. (C > O) and (H - C) >= ((C - O) * wick_multiplier) and (C - L) <= ((H -L) * body_percentage) or
  886. (C == O and C != L) and (H - L) >= ((C - L) * wick_multiplier) and (C - L) <= ((H - L) * body_percentage) or
  887. (O == L and C == L) and (H - L) >= sma((H - L), 50)
  888.  
  889. // Exteme Reversal System
  890. l02 = input(true, title = "Enable Exteme Reversal System")
  891. bodysize = input(title = "Body Size", defval = 0.525, step = 0.05, maxval = 1)
  892. barsback = input(title = "Bars Back", defval = 50, maxval = 50)
  893. bodymultiplier = input(title = "Body Multiplier", defval = 2, step = 0.25, maxval = 5)
  894.  
  895. mybodysize = abs(C - O)
  896. AverageBody = sma(mybodysize, barsback)
  897. mycandlesize = (H - L)
  898. AverageCandle = sma(mycandlesize, barsback)
  899.  
  900. Elongsignal = ((O[1] - C[1]) >= (bodysize * (H[1] - L[1]))) and ((H[1] - L[1]) > (AverageCandle * bodymultiplier)) and ((O[1] - C[1]) > AverageBody) and (C > O)
  901. Eshortsignal = ((C[1] - O[1]) >= (bodysize * (H[1] - L[1]))) and ((H[1] - L[1]) > (AverageCandle * bodymultiplier)) and ((C[1] - O[1]) > AverageBody) and (O > C)
  902.  
  903. // outside Reversal System
  904. l03 = input(true, title = "Enable Outside Reversal System")
  905.  
  906. BarMultiplier = input(title = "Body Multiplier", defval = 1.25, step = 0.05, maxval = 3.5)
  907. BarsBack = input(title = "Bars Back", defval = 50, maxval = 250)
  908. AverageCandle1 = sma(mycandlesize, BarsBack)
  909.  
  910. Olongsignal = L < L[1] and C > H[1] and (H - L) >= AverageCandle1 * BarMultiplier
  911. Oshortsignal = H > H[1] and C < L[1] and (H - L) >= AverageCandle1 * BarMultiplier
  912.  
  913. // Doji Reversal System
  914. l04 = input(true, title = "Enable Doji Reversal System")
  915.  
  916. percentage = input(title = "Body Percentage", defval = 0.10, step = 0.1, minval = 0.1)
  917.  
  918. frangehl = H[1] - L[1]
  919. frangeco = abs(C[1] - O[1])
  920. sma10 = sma(close, 10)
  921.  
  922. Dshortsignal = (frangeco <= frangehl * percentage and C < L[1] and L[1] > sma10 and C < O) or (C < L[2] and C[1] >= L[2] and frangeco <= frangeco * percentage and C < O and L[2] > sma10)
  923. Dlongsignal = (frangeco <= frangehl * percentage and C > H[1] and H[1] < sma10 and C > O) or (C > H[2] and C[1] <= H[2] and frangeco <= frangeco * percentage and C > O and H[2] < sma10)
  924.  
  925. longsignal = lowleftempty and ((l01 and Wlongsignal) or (l02 and Elongsignal) or (l03 and Olongsignal) or (l04 and Dlongsignal))
  926. shortsignal = highleftempty and ((l01 and Wlongsignal) or (l02 and Eshortsignal) or (l03 and Oshortsignal) or (l04 and Dshortsignal))
  927.  
  928. plotshape(longsignal, color = color.blue, location = location.belowbar, style = shape.triangleup, size = size.small)
  929. plotshape(shortsignal, color = color.red, location = location.abovebar, style = shape.triangledown, size = size.small)
  930.  
  931. //end of this part
  932.  
  933. //end of this part
  934.  
  935. //@version=4
  936. //
  937. // @author LonesomeTheBlue
  938. //
  939. //study("Pivot High Low Points", overlay=true)
  940. lb = input(6, title="Left Bars")
  941. rb = input(6, title="Right Bars")
  942.  
  943. mb = lb + rb + 1
  944.  
  945. plot(iff(not na(high[mb]), iff(highestbars(mb) == -lb, high[lb], na), na), style=plot.style_cross, linewidth=3, color=color.blue, offset=-lb)
  946. plot(iff(not na(low[mb]), iff(lowestbars(mb) == -lb, low[lb], na), na), style=plot.style_cross, linewidth=3, color=color.blue, offset=-lb)
  947.  
  948. //end of this part
  949.  
  950. //@version=4
  951. //study("Fork Handles by @treypeng", overlay=true)
  952.  
  953. // modify / use / steal this script in any way you like idc
  954.  
  955. // user customisation input
  956. showarrows = input(title="Show single pivot/swing arrows", type=input.bool, defval=true)
  957. showcols = input(title="Show double pivot/swing bar colours", type=input.bool, defval=true)
  958.  
  959.  
  960. // First determine which palette of hues we're going for
  961. // if downcandle=true then we want reds, pinks, browns etc
  962. // if updcandle=true then we want greens, blues, turqoise etc etc
  963. downcandle = close[2] < open[2]
  964. upcandle = close[2] > open[2]
  965.  
  966. // Do we have a double (five) candle swing?
  967. ispivotlow = not na(pivotlow(low, 2, 2))
  968. ispivothigh = not na(pivothigh(high, 2, 2))
  969.  
  970. // simple candle swings
  971. pivotlow_1 = pivotlow(low, 1, 1)
  972. pl2 = showarrows ? pivotlow_1 : na
  973. pivothigh_1 = pivothigh(high, 1, 1)
  974. ph2 = showarrows ? pivothigh_1 : na
  975.  
  976. // draw the simple swings
  977. plotshape(pl2, style=shape.triangleup, location=location.belowbar, color=color.gray, size=size.tiny, offset=-1)
  978. plotshape(ph2, style=shape.triangledown, location=location.abovebar, color=color.gray, size=size.tiny, offset=-1)
  979.  
  980. // add this line back in for cool text so your charts look confusing and professional to n00bs
  981. //plotchar(pl2, title='CR', char='△', location=location.belowbar, color=gray, offset=-2, text='CR', textcolor=gray, size=size.tiny)
  982.  
  983. ispivotboth = ispivothigh and ispivotlow
  984.  
  985. ispivothighup = ispivothigh and upcandle
  986. ispivothighdown = ispivothigh and downcandle
  987. ispivotlowup = ispivotlow and upcandle
  988. ispivotlowdown = ispivotlow and downcandle
  989. ispivotbothup = ispivotboth and upcandle
  990. ispivotbothdown = ispivotboth and downcandle
  991.  
  992.  
  993. col = ispivotbothup ? color.white : ispivotbothdown ? color.gray :
  994. ispivothighup ? color.lime : ispivothighdown ? color.red :
  995. ispivotlowup ? color.blue : ispivotlowdown ? #D2691E : na
  996.  
  997. barcolor(showcols ? col : na, -2)
  998.  
  999. //end of this part
  1000.  
  1001.  
  1002. //@version=4
  1003. //study("VJ - Killer BS", overlay=true)
  1004. //======================================================================
  1005. //Jurij
  1006. h_left = input(title="h left", type=input.integer, defval=10)
  1007. h_right = input(title="h right", type=input.integer, defval=10)
  1008. show_ptz = input(title="Show PTZ", type=input.bool, defval=true)
  1009. show_channel = input(title="Show channel", type=input.bool, defval=true)
  1010. //barCount = nz(barCount[1]) + 1
  1011. //check history and realtime PTZ
  1012. h_left_low = lowest(h_left)
  1013. h_left_high = highest(h_left)
  1014. newlow = low <= h_left_low
  1015. newhigh = high >= h_left_high
  1016. //channel_high = plot(show_channel ? h_left_low : 0, color=silver)
  1017. //channel_low = plot (show_channel ? h_left_high : 0, color=silver)
  1018. central_bar_low = low[h_right + 1]
  1019. central_bar_high = high[h_right + 1]
  1020. full_zone_low = lowest(h_left + h_right + 1)
  1021. full_zone_high = highest(h_left + h_right + 1)
  1022. central_bar_is_highest = central_bar_high >= full_zone_high
  1023. central_bar_is_lowest = central_bar_low <= full_zone_low
  1024. plotchar(central_bar_is_highest ? -1 : 0, offset=-h_right - 1, color=color.red, text="Sell")
  1025. plotchar(central_bar_is_lowest ? 1 : 0, offset=-h_right - 1, location=location.belowbar, color=color.green, text="Buy")
  1026. //plot(close)
  1027.  
  1028. //end of this part
  1029.  
  1030. //@version=4
  1031. //study(title="Peaks&Valleys", shorttitle="P&V", overlay=true)
  1032. width = input(9)
  1033. p = 0
  1034. vc = 0
  1035. for i = 0 to width * 2 by 1
  1036. p := p + (i == width ? 0 : high[i] < high[width] ? 1 : 0)
  1037. v := vc + (i == width ? 0 : low[i] > low[width] ? 1 : 0)
  1038. v
  1039. plotshape(p == width * 2, offset=-width, style=shape.labeldown)
  1040. plotshape(vc == width * 2, offset=-width, style=shape.labelup, location=location.belowbar)
  1041.  
  1042. //end of this part
  1043.  
  1044. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  1045. // © LonesomeTheBlue
  1046.  
  1047. //@version=4
  1048. //study("Double Zig Zag with HHLL", overlay = true, max_bars_back = 500)
  1049. prdx1 = input(defval = 8, title="ZigZag Period 1", minval = 2, maxval = 20)
  1050. prdx2 = input(defval = 20, title="ZigZag Period 2", minval = 2, maxval = 50)
  1051. showzz = input(defval = "Show Both", title = "Show Zig Zags", options = ["Show Zig Zag 1", "Show Zig Zag 2", "Show Both", "Show None"])
  1052. showhhll = input(defval = "Show Both", title = "Show HHLL", options = ["Show HHLL 1", "Show HHLL 2", "Show Both", "Show None"])
  1053. upcol1 = input(defval = color.lime, title = "Zig Zag 1 Up Color")
  1054. dncol1 = input(defval = color.red, title = "Zig Zag 1 Down Color")
  1055. upcol2 = input(defval = color.blue, title = "Zig Zag 2 Up Color")
  1056. dncol2 = input(defval = color.purple, title = "Zig Zag 2 Down Color")
  1057. txtcol = input(defval = color.black, title = "Text Color")
  1058. zz1style = input(defval = "Dashed", title = "Zig Zag 1 Line Style", options = ["Dashed", "Dotted"])
  1059. zz1width = input(defval = 2, title = "Zig zag 1 Line Width", minval = 1, maxval = 4)
  1060. zz2width = input(defval = 3, title = "Zig zag 2 Line Width", minval = 1, maxval = 6)
  1061.  
  1062. float ph1x = highestbars(high, prdx1) == 0 ? high : na
  1063. float pl1x = lowestbars(low, prdx1) == 0 ? low : na
  1064. float ph2x = highestbars(high, prdx2) == 0 ? high : na
  1065. float pl2x = lowestbars(low, prdx2) == 0 ? low : na
  1066.  
  1067. var dir1 = 0
  1068. var dir2 = 0
  1069. dir1 := iff(ph1x and na(pl1x), 1, iff(pl1x and na(ph1x), -1, dir1))
  1070. dir2 := iff(ph2x and na(pl2x), 1, iff(pl2x and na(ph2x), -1, dir2))
  1071.  
  1072. var max_array_sizex = 10 // [5, 2] matrix
  1073. var zigzag1 = array.new_float(0)
  1074. var zigzag2 = array.new_float(0)
  1075.  
  1076. add_to_zigzagx(pointer, value, bindex)=>
  1077. array.unshift(pointer, bindex)
  1078. array.unshift(pointer, value)
  1079. if array.size(pointer) > max_array_sizex
  1080. array.pop(pointer)
  1081. array.pop(pointer)
  1082.  
  1083. update_zigzagx(pointer, value, bindex, dir)=>
  1084. if array.size(pointer) == 0
  1085. add_to_zigzagx(pointer, value, bindex)
  1086. else
  1087. if (dir == 1 and value > array.get(pointer, 0)) or (dir == -1 and value < array.get(pointer, 0))
  1088. array.set(pointer, 0, value)
  1089. array.set(pointer, 1, bindex)
  1090. 0.
  1091.  
  1092. dir1changed = change(dir1)
  1093. if ph1x or pl1x
  1094. if dir1changed
  1095. add_to_zigzagx(zigzag1, dir1 == 1 ? ph1x : pl1x, bar_index)
  1096. else
  1097. update_zigzagx(zigzag1, dir1 == 1 ? ph1x : pl1x, bar_index, dir1)
  1098.  
  1099. dir2changed = change(dir2)
  1100. if ph2x or pl2x
  1101. if dir2changed
  1102. add_to_zigzagx(zigzag2, dir2 == 1 ? ph2x : pl2x, bar_index)
  1103. else
  1104. update_zigzagx(zigzag2, dir2 == 1 ? ph2x : pl2x, bar_index, dir2)
  1105.  
  1106. if array.size(zigzag1) >= 6
  1107. var line zzline1 = na
  1108. var label zzlabel1 = na
  1109. float val = array.get(zigzag1, 0)
  1110. int point = round(array.get(zigzag1, 1))
  1111. if change(val) or change(point)
  1112. float val1 = array.get(zigzag1, 2)
  1113. int point1 = round(array.get(zigzag1, 3))
  1114. if change(val1) == 0 and change(point1) == 0
  1115. line.delete(zzline1)
  1116. label.delete(zzlabel1)
  1117. if showzz == "Show Zig Zag 1" or showzz == "Show Both"
  1118. zzline1 := line.new(x1 = point, y1 = val, x2 = point1, y2 = val1, color = dir1 == 1 ? upcol1 : dncol1, width = zz1width, style = zz1style == "Dashed" ? line.style_dashed : line.style_dotted)
  1119. if showhhll == "Show HHLL 1" or showhhll == "Show Both"
  1120. hhlltxt = dir1 == 1 ? array.get(zigzag1, 0) > array.get(zigzag1, 4) ? "HH" : "LH" : array.get(zigzag1, 0) < array.get(zigzag1, 4) ? "LL" : "HL"
  1121. labelcol = dir1 == 1 ? array.get(zigzag1, 0) > array.get(zigzag1, 4) ? upcol1 : dncol1 : array.get(zigzag1, 0) < array.get(zigzag1, 4) ? dncol1 : upcol1
  1122. zzlabel1 := label.new(x = point, y = val, text = hhlltxt, color = labelcol, textcolor = txtcol, style = dir1 == 1 ? label.style_label_down : label.style_label_up)
  1123.  
  1124. if array.size(zigzag2) >= 6
  1125. var line zzline2 = na
  1126. var label zzlabel2 = na
  1127. float val = array.get(zigzag2, 0)
  1128. int point = round(array.get(zigzag2, 1))
  1129. if change(val) or change(point)
  1130. float val1 = array.get(zigzag2, 2)
  1131. int point1 = round(array.get(zigzag2, 3))
  1132. if change(val1) == 0 and change(point1) == 0
  1133. line.delete(zzline2)
  1134. label.delete(zzlabel2)
  1135. if showzz == "Show Zig Zag 2" or showzz == "Show Both"
  1136. zzline2 := line.new(x1 = point, y1 = val, x2 = point1, y2 = val1, color = dir2 == 1 ? upcol2 : dncol2, width = zz2width)
  1137. if showhhll == "Show HHLL 2" or showhhll == "Show Both"
  1138. hhlltxt = dir2 == 1 ? array.get(zigzag2, 0) > array.get(zigzag2, 4) ? "HH" : "LH" : array.get(zigzag2, 0) < array.get(zigzag2, 4) ? "LL" : "HL"
  1139. labelcol = dir2 == 1 ? array.get(zigzag2, 0) > array.get(zigzag2, 4) ? upcol2 : dncol2 : array.get(zigzag2, 0) < array.get(zigzag2, 4) ? dncol2 : upcol2
  1140. zzlabel2 := label.new(x = point, y = val, text = hhlltxt, color = labelcol, textcolor = txtcol, style = dir2 == 1 ? label.style_label_down : label.style_label_up)
  1141.  
  1142.  
  1143. //end of this part
  1144.  
  1145. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  1146. // © GokhanGoksin
  1147.  
  1148. //@version=4
  1149. //study("ENGUL",shorttitle="engulf",overlay=true)
  1150. x=input(title="çizgi/sağ uzat",type=input.integer,defval=5)
  1151. z=input(title="kaynak/seç/üst çizgi",type=input.source,defval=open)
  1152. y=input(title="kaynak/seç/alt çizgi",type=input.source,defval=close)
  1153. //****************************************************
  1154. en=close[1]<open[1] and close>open[1] and low[1] >low
  1155. plotshape(en,style=shape.arrowup,location=location.belowbar)
  1156. //****************************************************** enguluf destek
  1157. if en
  1158. li =line.new(time[1],y[1],time+x*(time-time[1]),y[1],xloc=xloc.bar_time,color=color.red,width=2)
  1159.  
  1160. if en
  1161. label.new(time+x*(time-time[1]),y[1],text="\n"+tostring(y[1]),xloc=xloc.bar_time,
  1162. style=label.style_none,size=size.normal,textcolor=color.white,yloc=yloc.price)
  1163. //********************************************************************** direnç
  1164. if en
  1165. line.new(time[1],z[1],time+x*(time-time[1]),z[1],xloc=xloc.bar_time,color=color.blue,width=2)
  1166. if en
  1167. l=label.new(time+x*(time-time[1]),z[1],text="\n"+tostring(z[1]),xloc=xloc.bar_time,
  1168. style=label.style_none,size=size.normal,textcolor=color.white,yloc=yloc.price)
  1169.  
  1170.  
  1171. //end of this part
  1172.  
  1173. // © weeklystockcharts
  1174.  
  1175. // @version=4
  1176. // Candle Type w/ only 3-1 Pine Script
  1177.  
  1178. //study("Candle Type w/only 3-1", overlay=true, precision=0)
  1179.  
  1180. // check for 3-1 inside + up buy
  1181. buyx = high[3] < high[2] and low[3] > low[2] and high[1] < high[2] and low[1] > low[2] and high > high[1] and (high[1] <= high[2] and low[1] >= low[2]) and not (low < low[1])
  1182. plotchar(buyx, title="Inside + Up Buy Label", text ="Up", location=location.belowbar, color=#4CAF50)
  1183.  
  1184. // check for 3-1 inside + dn sell
  1185. sellx = high[3] < high[2] and low[3] > low[2] and high[1] < high[2] and low[1] > low[2] and low < low[1] and (low[1] >= low[2] and high[1] <= high[2]) and not (high > high[1])
  1186.  
  1187. //end of this part
  1188.  
  1189. //@version=4
  1190. // ══════════════════════════════════════════════════════════════════════════════════════════════════ //
  1191. //# * ══════════════════════════════════════════════════════════════════════════════════════════════
  1192. //# *
  1193. //# * Study : Price Action - Support & Resistance
  1194. //# * - Support & Resistance based on Volume
  1195. //# * - Volume Weighted Colored Bars and Sign of Exhaustion Indication Add-On
  1196. //# * Author : @MCK
  1197. //# *
  1198. //# * Revision History
  1199. //# * Release : Jan 25, 2021
  1200. //# * Update : Jan 26, 2021 : User Request : Add price option for intruments with no volume data
  1201. //# * Update : Mar 18, 2021 : Ability to draw lines and cofigure alerts when volume spikes detected
  1202. //# * Update : Mar 21, 2021 : Ability to draw lines and cofigure alerts when high volatility detected
  1203. //# * - line customization abaility
  1204. //# *
  1205. //# * ══════════════════════════════════════════════════════════════════════════════════════════════
  1206. // ══════════════════════════════════════════════════════════════════════════════════════════════════ //
  1207.  
  1208. //study("Price Action - Support & Resistance by MCK", "S&R ʙʏ MCK", true, max_lines_count = 500)
  1209.  
  1210. // -Inputs ══════════════════════════════════════════════════════════════════════════════════════ //
  1211.  
  1212. // ---------------------------------------------------------------------------------------------- //
  1213. // Definitions ---------------------------------------------------------------------------------- //
  1214.  
  1215. group_support_and_resistance = "Consecutively Increasing Volume / Price"
  1216. tooltip_support_and_resistance = "Moments where\n" +
  1217. "- price is bullish or bearish consecutively for minimum 3 bars and on increasing volume with at least one bar's volume is above volume moving average\n" +
  1218. "or\n" +
  1219. "- price is bullish or bearish consecutively on increasing/decreasing price for minimum 3 bars"
  1220.  
  1221. group_volume_spike_sign_of_exhaustion = "Volume Spike - Sign of Exhaustion"
  1222. tooltip_volume_spike_sign_of_exhaustion = "Moments where\n" +
  1223. "huge volume detected : current volume is grater than the product of the theshold value and volume moving average\n" +
  1224. "presents idea : huge volume may be a sign of exhaustion and may lead to sharp reversals"
  1225.  
  1226. group_high_volatility = "High Volatility"
  1227. tooltip_high_volatility = "Moments where\n" +
  1228. "price range of the current bar is grater than the product of the theshold value and average true range value of defined period"
  1229.  
  1230. group_volume_weighted_colored_bars = "Volume Weighted Colored Bars"
  1231. tooltip_volume_weighted_colored_bars = "Colors bars based on the bar's volume relative to volume moving average\n" +
  1232. "trading tip : a potential breakout trading opportunity may occur when price moves above a resistance level or moves below a support level on increasing volume"
  1233.  
  1234. tooltip_volume_moving_average = "Volume simple moving average, serves as reference to\n" +
  1235. "- Support and Resistance,\n" +
  1236. "- Volume Weighted Colored Bars,\n" +
  1237. "- Volume Spike - Sign of Exhaustion\n" +
  1238. "calculations"
  1239.  
  1240. // User Input Declarations ---------------------------------------------------------------------- //
  1241.  
  1242. // ---------------------------------------------------------------------------------------------- //
  1243. // Volume Spike - Sign of Exhaustion ------------------------------------------------------------ //
  1244.  
  1245.  
  1246. i_vSpikeThresh = input(3 , "Volume Spike Theshold", minval = .1, step = .1 , inline = "SRS1", group = group_volume_spike_sign_of_exhaustion)
  1247. i_isSnRSpike = input(true , "S & R Lines" , inline = "SRS2", group = group_volume_spike_sign_of_exhaustion)
  1248. i_spLnColor = input(#ab47bc, "" , inline = "SRS2", group = group_volume_spike_sign_of_exhaustion)
  1249. i_spLnWidth = input(2 , "" , inline = "SRS2", group = group_volume_spike_sign_of_exhaustion)
  1250. i_spLnStyle = input("Solid" , "", options = ["Dashed", "Dotted", "Solid"] , inline = "SRS2", group = group_volume_spike_sign_of_exhaustion)
  1251. i_spLnBullLevel = input("High" , "Levels : Bullish", options = ["High", "Close", "Both"], inline = "SRS3", group = group_volume_spike_sign_of_exhaustion)
  1252. i_spLnBearLevel = input("Low" , " Bearish", options = ["Low" , "Close", "Both"] , inline = "SRS3", group = group_volume_spike_sign_of_exhaustion)
  1253.  
  1254. // ---------------------------------------------------------------------------------------------- //
  1255.  
  1256. // ---------------------------------------------------------------------------------------------- //
  1257. // Volume Moving Average : Base ----------------------------------------------------------------- //
  1258.  
  1259. i_vSMA = sma(nz(volume), input(90, "Volume Moving Average Length", group = "General Settings", tooltip = tooltip_volume_moving_average))
  1260.  
  1261.  
  1262. // -Calculations ════════════════════════════════════════════════════════════════════════════════ //
  1263.  
  1264. // ---------------------------------------------------------------------------------------------- //
  1265. // Definitions ---------------------------------------------------------------------------------- //
  1266.  
  1267. nzVolume = nz(volume)
  1268. risingVol = nzVolume >= nzVolume[1]
  1269.  
  1270. bullCandle = close > open
  1271. bearCandle = close < open
  1272.  
  1273. risingPrice = close > close[1]
  1274. fallingPrice = close < close[1]
  1275.  
  1276. lwstPrice = lowest (low , 3)
  1277. hstPrice = highest(high, 3)
  1278.  
  1279. ranged = abs(high - low)
  1280.  
  1281. x2 = timenow
  1282.  
  1283. // ---------------------------------------------------------------------------------------------- //
  1284.  
  1285. // ---------------------------------------------------------------------------------------------- //
  1286. // Volume Spike - Sign of Exhaustion ------------------------------------------------------------ //
  1287.  
  1288. exhaustVol = nzVolume > i_vSpikeThresh * i_vSMA
  1289.  
  1290. x1V = valuewhen(exhaustVol, time, 0)
  1291.  
  1292. // ---------------------------------------------------------------------------------------------- //
  1293.  
  1294. // ---------------------------------------------------------------------------------------------- //
  1295.  
  1296. // -Plotting ════════════════════════════════════════════════════════════════════════════════════ //
  1297.  
  1298. f_getStyle(_s) => _s == "Solid" ? line.style_solid : _s == "Dotted" ? line.style_dotted : line.style_dashed
  1299.  
  1300. // ---------------------------------------------------------------------------------------------- //
  1301. // ---------------------------------------------------------------------------------------------- //
  1302. // Volume Spike - Sign of Exhaustion ------------------------------------------------------------ //
  1303.  
  1304. var line spikeLine = na
  1305. var line spikeLine1 = na
  1306. var line spikeLine2 = na
  1307. var line spikeLine3 = na
  1308.  
  1309. if i_isSnRSpike and exhaustVol
  1310.  
  1311. if bullCandle
  1312. if i_spLnBullLevel == "High"
  1313. if exhaustVol == exhaustVol[1] and not bearCandle[1]
  1314. line.delete(spikeLine[1])
  1315. spikeLine := line.new(x1V, high , x2, high , xloc.bar_time, extend.none, i_spLnColor, f_getStyle(i_spLnStyle), i_spLnWidth)
  1316.  
  1317. else if i_spLnBullLevel == "Close"
  1318. if exhaustVol == exhaustVol[1] and not bearCandle[1]
  1319. line.delete(spikeLine[1])
  1320. spikeLine := line.new(x1V, close , x2, close , xloc.bar_time, extend.none, i_spLnColor, f_getStyle(i_spLnStyle), i_spLnWidth)
  1321.  
  1322. else
  1323. if exhaustVol == exhaustVol[1] and not bearCandle[1]
  1324. line.delete(spikeLine1[1])
  1325. line.delete(spikeLine2[1])
  1326. line.delete(spikeLine3[1])
  1327. spikeLine1 := line.new(x1V, close , x2, close , xloc.bar_time, extend.none, i_spLnColor, f_getStyle(i_spLnStyle), i_spLnWidth)
  1328. spikeLine2 := line.new(x1V, avg(high, close), x2, avg(high, close), xloc.bar_time, extend.none, i_spLnColor, f_getStyle("Dotted") , i_spLnWidth - 1)
  1329. spikeLine3 := line.new(x1V, high , x2, high , xloc.bar_time, extend.none, i_spLnColor, f_getStyle(i_spLnStyle), i_spLnWidth)
  1330.  
  1331. if bearCandle
  1332. if i_spLnBearLevel == "Low"
  1333. if exhaustVol == exhaustVol[1] and not bullCandle[1]
  1334. line.delete(spikeLine[1])
  1335. spikeLine := line.new(x1V, low , x2, low , xloc.bar_time, extend.none, i_spLnColor, f_getStyle(i_spLnStyle), i_spLnWidth)
  1336.  
  1337. else if i_spLnBearLevel == "Close"
  1338. if exhaustVol == exhaustVol[1] and not bullCandle[1]
  1339. line.delete(spikeLine[1])
  1340. spikeLine := line.new(x1V, close , x2, close , xloc.bar_time, extend.none, i_spLnColor, f_getStyle(i_spLnStyle), i_spLnWidth)
  1341.  
  1342. else
  1343. if exhaustVol == exhaustVol[1] and not bullCandle[1]
  1344. line.delete(spikeLine1[1])
  1345. line.delete(spikeLine2[1])
  1346. line.delete(spikeLine3[1])
  1347. spikeLine1 := line.new(x1V, low , x2, low , xloc.bar_time, extend.none, i_spLnColor, f_getStyle(i_spLnStyle), i_spLnWidth)
  1348. spikeLine2 := line.new(x1V, avg(low, close) , x2, avg(low, close) , xloc.bar_time, extend.none, i_spLnColor, f_getStyle("Dotted") , i_spLnWidth - 1)
  1349. spikeLine3 := line.new(x1V, close , x2, close , xloc.bar_time, extend.none, i_spLnColor, f_getStyle(i_spLnStyle), i_spLnWidth)
  1350.  
  1351.  
  1352. alertcondition(crossover(nzVolume, i_vSMA * i_vSpikeThresh), "Volume Spikes", "sign of exhaustion, huge volume increase detected\n{{exchange}}:{{ticker}}->\nOpen = {{open}}, Current = {{close}},\nTime = {{time}}")
  1353.  
  1354. // ---------------------------------------------------------------------------------------------- //
  1355.  
  1356. //end of this part
  1357.  
  1358.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement