Advertisement
xmd79

scalping combo1

Jan 16th, 2022
700
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 44.70 KB | None | 0 0
  1. //@version=5
  2. indicator('Gann medians', overlay=true, format=format.price, precision=12, max_bars_back=500)
  3.  
  4.  
  5.  
  6. method1 = input.string('Median', options=['EMA', 'Median', 'SMA'])
  7. length1 = input(12)
  8. mult1 = input.int(1, minval=0, maxval=1)
  9.  
  10. method2 = input.string('Median', options=['EMA', 'Median', 'SMA'])
  11. length2 = input(27)
  12. mult2 = input.int(1, minval=0, maxval=1)
  13.  
  14. method3 = input.string('Median', options=['EMA', 'Median', 'SMA'])
  15. length3 = input(56)
  16. mult3 = input.int(1, minval=0, maxval=1)
  17. //----
  18. Avg(x, length, method) =>
  19. sma_1 = ta.sma(x, length)
  20. ema_1 = ta.ema(x, length)
  21. percentile_linear_interpolation_1 = ta.percentile_linear_interpolation(x, length, 50)
  22. method == 'SMA' ? sma_1 : method == 'EMA' ? ema_1 : percentile_linear_interpolation_1
  23. //----
  24. a1 = ta.highest(length1) - math.max(close, open)
  25. b1 = math.min(close, open) - ta.lowest(length1)
  26. c1 = math.max(close, open) + a1 * mult1
  27. d1 = math.min(close, open) - b1 * mult1
  28.  
  29. a2 = ta.highest(length2) - math.max(close, open)
  30. b2 = math.min(close, open) - ta.lowest(length2)
  31. c2 = math.max(close, open) + a2 * mult2
  32. d2 = math.min(close, open) - b2 * mult2
  33.  
  34. a3 = ta.highest(length3) - math.max(close, open)
  35. b3 = math.min(close, open) - ta.lowest(length3)
  36. c3 = math.max(close, open) + a3 * mult3
  37. d3 = math.min(close, open) - b3 * mult3
  38. //----
  39. e1 = Avg(c1, length1, method1)
  40. f1 = Avg(d1, length1, method1)
  41. g1 = 0
  42. cross_1 = ta.cross(close, f1)
  43. g1 := ta.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 = ta.cross(close, f2)
  49. g2 := ta.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 = ta.cross(close, f3)
  55. g3 := ta.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, trackprice=true, transp=0)
  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, trackprice=true, transp=0)
  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, trackprice=true, transp=0)
  68.  
  69.  
  70. //end of this part
  71.  
  72.  
  73. testStartYear = input(2019, 'Backtest Start Year')
  74. testStartMonth = input(10, 'Backtest Start Month')
  75. testStartDay = input(20, 'Backtest Start Day')
  76. testStartHour = input(0, 'Backtest Start Hour')
  77. testStartMin = input(0, 'Backtest Start Minute')
  78. testPeriodStart = timestamp(testStartYear, testStartMonth, testStartDay, testStartHour, testStartMin)
  79. testStopYear = input(2099, 'Backtest Stop Year')
  80. testStopMonth = input(1, 'Backtest Stop Month')
  81. testStopDay = input(30, 'Backtest Stop Day')
  82. testPeriodStop = timestamp(testStopYear, testStopMonth, testStopDay, 0, 0)
  83. testPeriod() =>
  84. time >= testPeriodStart and time <= testPeriodStop ? true : false
  85.  
  86.  
  87. lenH = input.int(title='Length High', defval=20, minval=1)
  88. lenL = input.int(title='Length Low', defval=20, minval=1)
  89.  
  90. fun(src, len, isHigh, _style, _yloc, _color) =>
  91. p = nz(src[len])
  92. isFound = true
  93. for i = 0 to len * 2 by 1
  94. if isHigh and src[i] > p
  95. isFound := false
  96. isFound
  97. if not isHigh and src[i] < p
  98. isFound := false
  99. isFound
  100. if isFound and testPeriod()
  101. label.new(bar_index[len], p, str.tostring(p), style=_style, yloc=_yloc, color=_color)
  102. line.new(bar_index[len], p, bar_index, p, extend=extend.right, color=_color)
  103.  
  104.  
  105.  
  106. fun(high, lenH, true, label.style_label_down, yloc.abovebar, color.red)
  107. fun(low, lenL, false, label.style_label_up, yloc.belowbar, color.green)
  108.  
  109. //end of this part
  110.  
  111.  
  112. price = input(defval=ohlc4)
  113.  
  114. // Strategy vars setup here
  115. Depth = input(56, title='Depth') // Depth
  116. Deviation = input(5, title='Deviation') // Deviation
  117.  
  118. // main logic
  119. // ZigZag
  120. lastlow = 0.0
  121. lasthigh = 0.0
  122. lastlow := nz(lastlow[1])
  123. lasthigh := nz(lasthigh[1])
  124.  
  125. data(x) =>
  126. d = request.security(syminfo.tickerid, timeframe.period, x, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
  127. d
  128. getLow(x, y, z, a) =>
  129. lastlow = y
  130. v = data(x)
  131. m = v == lastlow or data(z) - v > a * syminfo.mintick
  132. if v != lastlow
  133. lastlow := v
  134. lastlow
  135. if m
  136. v := 0.0
  137. v
  138. [v, lastlow]
  139. getHigh(x, y, z, a) =>
  140. lasthigh = y
  141. v = data(x)
  142. m = v == lasthigh or v - data(z) > a * syminfo.mintick
  143. if v != lasthigh
  144. lasthigh := v
  145. lasthigh
  146. if m
  147. v := 0.0
  148. v
  149. [v, lasthigh]
  150.  
  151. [v, e] = getLow(ta.lowest(Depth), lastlow, low, Deviation)
  152. lastlow := e
  153. zBB = v != 0.0
  154. [v1, ee1] = getHigh(ta.highest(Depth), lasthigh, high, Deviation)
  155. lasthigh := ee1
  156. zSS = v1 != 0.0
  157.  
  158. zigzagDirection = -1
  159. zigzagHigh = 0
  160. zigzagLow = 0
  161. zigzagDirection := zBB ? 0 : zSS ? 1 : nz(zigzagDirection[1], -1)
  162. virtualLow = zigzagLow[1] + 1
  163. if not zBB or zBB and zigzagDirection == zigzagDirection[1] and low > low[virtualLow]
  164. zigzagLow := nz(zigzagLow[1]) + 1
  165. zigzagLow
  166.  
  167. virtualHigh = zigzagHigh[1] + 1
  168. if not zSS or zSS and zigzagDirection == zigzagDirection[1] and high < high[virtualHigh]
  169. zigzagHigh := nz(zigzagHigh[1]) + 1
  170. zigzagHigh
  171. a = bar_index - zigzagLow
  172. b = bar_index - zigzagHigh
  173. var color c = na
  174. c := fixnan(a < b[1] ? color.lime : a > b[1] ? color.red : na)
  175. //barcolor(color=color.lime)
  176. line zigzag = line.new(bar_index - zigzagLow, low[zigzagLow], bar_index - zigzagHigh, high[zigzagHigh], color=c, style=line.style_solid, width=4)
  177. if zigzagDirection == zigzagDirection[1]
  178. line.delete(zigzag[1])
  179.  
  180. l = label.new(bar_index - zigzagHigh, na)
  181. label.set_text(l, 'Sell')
  182. label.set_color(l, color.red)
  183. label.set_yloc(l, yloc.abovebar)
  184. label.set_style(l, label.style_label_down)
  185. if zigzagDirection == zigzagDirection[1]
  186. label.delete(l[1])
  187.  
  188.  
  189.  
  190. l_b = label.new(bar_index - zigzagLow, na)
  191. label.set_text(l_b, 'Buy')
  192. label.set_color(l_b, color.green)
  193. label.set_yloc(l_b, yloc.belowbar)
  194. label.set_style(l_b, label.style_label_up)
  195. if zigzagDirection == zigzagDirection[1]
  196. label.delete(l_b[1])
  197.  
  198.  
  199. zzPrevHigh = zigzagHigh[1]
  200. zzPrevLow = zigzagLow[1]
  201. if not na(zzPrevHigh[1])
  202. zzPrevHigh := zzPrevHigh[1] + 1
  203. zzPrevHigh
  204.  
  205. if not na(zzPrevLow[1])
  206. zzPrevLow := zzPrevLow[1] + 1
  207. zzPrevLow
  208.  
  209. if zigzagDirection != zigzagDirection[1]
  210. if zigzagDirection == 1
  211. zzPrevHigh := zigzagHigh[1] + 1
  212. zzPrevHigh
  213. if zigzagDirection == 0
  214. zzPrevLow := zigzagLow[1] + 1
  215. zzPrevLow
  216.  
  217. //end of this part
  218.  
  219. // RSI Settings for user
  220. rsiSource = input(title='RSI Source', defval=close)
  221. rsiLength = input(title='RSI Length', defval=7)
  222. rsiOverbought = input.int(title='RSI Overbought', defval=70, minval=50, maxval=100)
  223. rsiOvesold = input.int(title='RSI Oversold', defval=30, minval=1, maxval=50)
  224.  
  225. // RSI value based on inbuilt RSI
  226. rsiValue = ta.rsi(rsiSource, rsiLength)
  227.  
  228. // Get the current state
  229. isOverbought = rsiValue >= rsiOverbought
  230. isOversold = rsiValue <= rsiOvesold
  231.  
  232. // State of the last extreme 0 for initialization, 1 = overbought, 2 = oversold
  233. var laststate = 0
  234.  
  235. // Highest and Lowest prices since the last state change
  236. var hh = low
  237. var ll = high
  238.  
  239. // Labels
  240. var label labelll = na
  241. var label labelhh = na
  242.  
  243. // Swing lines
  244. var line line_up = na
  245. var line line_down = na
  246.  
  247.  
  248. // We go from overbought straight to oversold NEW DRAWINGS CREATED HERE
  249. if laststate == 1 and isOversold
  250. ll := low
  251. labelll := label.new(bar_index, low, style=label.style_label_up, color=color.green, size=size.tiny)
  252. labelhh_low = label.get_x(labelhh)
  253. labelhh_pos = label.get_y(labelhh)
  254. line_down := line.new(bar_index, high, labelhh_low, labelhh_pos, width=2)
  255. line_down
  256.  
  257. // We go from oversold straight to overbought NEW DRAWINGS CREATED HERE
  258. if laststate == 2 and isOverbought
  259. hh := high
  260. labelhh := label.new(bar_index, high, style=label.style_label_down, color=color.red, size=size.tiny)
  261. labelll_low = label.get_x(labelll)
  262. labelll_pos = label.get_y(labelll)
  263. line_up := line.new(bar_index, high, labelll_low, labelll_pos, width=2)
  264. line_up
  265.  
  266.  
  267. // If we are overbought
  268. if isOverbought
  269. if high >= hh
  270. hh := high
  271. label.set_x(labelhh, bar_index)
  272. label.set_y(labelhh, high)
  273. line.set_x1(line_up, bar_index)
  274. line.set_y1(line_up, high)
  275. laststate := 1
  276. laststate
  277.  
  278. // If we are oversold
  279. if isOversold
  280. if low <= ll
  281. ll := low
  282. label.set_x(labelll, bar_index)
  283. label.set_y(labelll, low)
  284. line.set_x1(line_down, bar_index)
  285. line.set_y1(line_down, low)
  286. laststate := 2
  287. laststate
  288.  
  289.  
  290. // If last state was overbought and we are overbought
  291. if laststate == 1 and isOverbought
  292. if hh <= high
  293. hh := high
  294. label.set_x(labelhh, bar_index)
  295. label.set_y(labelhh, high)
  296. line.set_x1(line_up, bar_index)
  297. line.set_y1(line_up, high)
  298.  
  299. //If we are oversold and the last state was oversold, move the drawings to the lowest price
  300. if laststate == 2 and isOversold
  301. if low <= ll
  302. ll := low
  303. label.set_x(labelll, bar_index)
  304. label.set_y(labelll, low)
  305. line.set_x1(line_down, bar_index)
  306. line.set_y1(line_down, low)
  307.  
  308.  
  309. // If last state was overbought
  310. if laststate == 1
  311. if hh <= high
  312. hh := high
  313. label.set_x(labelhh, bar_index)
  314. label.set_y(labelhh, high)
  315. line.set_x1(line_up, bar_index)
  316. line.set_y1(line_up, high)
  317.  
  318. // If last stare was oversold
  319. if laststate == 2
  320. if ll >= low
  321. ll := low
  322. label.set_x(labelll, bar_index)
  323. label.set_y(labelll, low)
  324. line.set_x1(line_down, bar_index)
  325. line.set_y1(line_down, low)
  326.  
  327. //end of this part
  328.  
  329. //study("momentum zigzag", overlay = true)
  330. lengthZZZ = input(10, title='High/Low length')
  331. hZZZ = ta.highest(high, lengthZZZ * 2 + 1)
  332. lZZZ = ta.lowest(low, lengthZZZ * 2 + 1)
  333. f_isMin(len) =>
  334. lZZZ == low[len]
  335. f_isMax(len) =>
  336. hZZZ == high[len]
  337.  
  338. var dirUp = false
  339. var lastLow = high * 100
  340. var lastHigh = 0.0
  341. var timeLow = bar_index
  342. var timeHigh = bar_index
  343. var line li = na
  344. f_drawLine() =>
  345. _li_color = dirUp ? color.gray : color.gray
  346. line.new(timeHigh - lengthZZZ, lastHigh, timeLow - lengthZZZ, lastLow, xloc.bar_index, color=_li_color, width=1)
  347.  
  348. if dirUp
  349. if f_isMin(lengthZZZ) and low[lengthZZZ] < lastLow
  350. lastLow := low[lengthZZZ]
  351. timeLow := bar_index
  352. line.delete(li)
  353. li := f_drawLine()
  354. li
  355.  
  356. if f_isMax(lengthZZZ) and high[lengthZZZ] > lastLow
  357. lastHigh := high[lengthZZZ]
  358. timeHigh := bar_index
  359. dirUp := false
  360. li := f_drawLine()
  361. li
  362.  
  363. if not dirUp
  364. if f_isMax(lengthZZZ) and high[lengthZZZ] > lastHigh
  365. lastHigh := high[lengthZZZ]
  366. timeHigh := bar_index
  367. line.delete(li)
  368. li := f_drawLine()
  369. li
  370. if f_isMin(lengthZZZ) and low[lengthZZZ] < lastHigh
  371. lastLow := low[lengthZZZ]
  372. timeLow := bar_index
  373. dirUp := true
  374. li := f_drawLine()
  375. if f_isMax(lengthZZZ) and high[lengthZZZ] > lastLow
  376. lastHigh := high[lengthZZZ]
  377. timeHigh := bar_index
  378. dirUp := false
  379. li := f_drawLine()
  380. li
  381.  
  382. //end of this part
  383.  
  384.  
  385. use_alt_series = input(defval=false, title='Use alternative source?')
  386. alt_src = input(defval=close, title='Alternative source:')
  387. hSR = use_alt_series ? alt_src : high
  388. lSR = use_alt_series ? alt_src : low
  389.  
  390. window = input(defval=14, title='lookback window :')
  391. percent_of_range_for_trade_zone = input(defval=15.0, title='Percent of the range to use for trade zone') * 0.01
  392.  
  393. short_term_top = ta.valuewhen(hSR >= ta.highest(hSR, window), hSR, 0)
  394. short_term_bot = ta.valuewhen(lSR <= ta.lowest(lSR, window), lSR, 0)
  395.  
  396. short_term_resist = ta.change(short_term_top) != 0 ? na : short_term_top
  397. short_term_suport = ta.change(short_term_bot) != 0 ? na : short_term_bot
  398.  
  399. short_term_resist_plot = plot(series=short_term_resist, title='STR', color=color.new(color.fuchsia, 0), linewidth=2, style=plot.style_linebr)
  400. short_term_suport_plot = plot(series=short_term_suport, title='STS', color=color.new(color.aqua, 0), linewidth=2, style=plot.style_linebr)
  401.  
  402. fill(short_term_suport_plot, short_term_resist_plot, color=color.new(color.aqua, 95), title=' Trade Zone ')
  403.  
  404. // Calculate entry zone:
  405. float short_term_resist_trade_limit = na
  406. float short_term_suport_trade_limit = na
  407.  
  408. range_1 = fixnan(short_term_resist) - fixnan(short_term_suport)
  409.  
  410. if not na(short_term_resist)
  411. if not na(short_term_resist_trade_limit[1])
  412. short_term_resist_trade_limit := short_term_resist_trade_limit[1]
  413. short_term_resist_trade_limit
  414. else
  415. short_term_resist_trade_limit := short_term_resist - range_1 * percent_of_range_for_trade_zone
  416. short_term_resist_trade_limit
  417.  
  418. if not na(short_term_suport)
  419. if not na(short_term_suport_trade_limit[1])
  420. short_term_suport_trade_limit := short_term_suport_trade_limit[1]
  421. short_term_suport_trade_limit
  422. else
  423. short_term_suport_trade_limit := short_term_suport + range_1 * percent_of_range_for_trade_zone
  424. short_term_suport_trade_limit
  425.  
  426. short_term_resist_trade_limit_plot = plot(series=short_term_resist_trade_limit, title='', color=color.new(color.red, 0), linewidth=1, style=plot.style_linebr)
  427. short_term_suport_trade_limit_plot = plot(series=short_term_suport_trade_limit, title='', color=color.new(color.yellow, 0), linewidth=1, style=plot.style_linebr)
  428.  
  429. //end of this part
  430.  
  431. lookback = input(defval=20, title='# of Candles to Look Back')
  432. srcAA = 'Close'
  433.  
  434. pivothigh_1 = ta.pivothigh(high, lookback, lookback)
  435. pivothigh_2 = ta.pivothigh(high, lookback, lookback)
  436. pivot_high = srcAA == 'Close' ? pivothigh_1 : pivothigh_2
  437. pivotlow_1 = ta.pivotlow(low, lookback, lookback)
  438. pivotlow_2 = ta.pivotlow(low, lookback, lookback)
  439. pivot_low = srcAA == 'Close' ? pivotlow_1 : pivotlow_2
  440.  
  441. valuewhen_9 = ta.valuewhen(pivot_high, high[lookback], 0)
  442. valuewhen_10 = ta.valuewhen(pivot_high, high[lookback], 0)
  443. plot_high = srcAA == 'Close' ? valuewhen_9 : valuewhen_10
  444. valuewhen_11 = ta.valuewhen(pivot_low, low[lookback], 0)
  445. valuewhen_12 = ta.valuewhen(pivot_low, low[lookback], 0)
  446. plot_low = srcAA == 'Close' ? valuewhen_11 : valuewhen_12
  447.  
  448. resistance = plot(plot_high, style=plot.style_line, title='Resistance Line', color=color.new(color.orange, 0), show_last=1, linewidth=2, trackprice=true)
  449. support = plot(plot_low, style=plot.style_line, title='Support Line', color=color.new(color.orange, 0), show_last=1, linewidth=2, trackprice=true)
  450.  
  451.  
  452.  
  453. //end of this part
  454.  
  455.  
  456.  
  457. // - INPUTS
  458. ShowPivots = input(true, title='Show Pivot Points')
  459. ShowHHLL = input(true, title='Show HH,LL,LH,HL markers on Pivots Points')
  460. left = input.int(5, minval=1, title='Pivot Length Left Hand Side')
  461. right = input.int(5, minval=1, title='Pivot Length Right Hand Side')
  462. //
  463.  
  464. var barCounter = 0
  465. barCounter := barCounter + 1
  466. f_draw_infopanel(_x, _y, _line, _text) =>
  467. _rep_text = ''
  468. if barstate.islast
  469. for _l = 0 to _line by 1
  470. _rep_text := _rep_text + '\n'
  471. _rep_text
  472. _rep_text := _rep_text + _text
  473. var label _la = na
  474. //a = label.get_text(_la)
  475. label.delete(_la)
  476. _la := label.new(x=_x, y=_y, text=_rep_text, xloc=xloc.bar_time, yloc=yloc.price, color=color.black, style=label.style_label_up, textcolor=color.silver, size=size.small)
  477. _la
  478.  
  479. // Determine pivots
  480. pvtLenL = left
  481. pvtLenR = right
  482.  
  483. // Get High and Low Pivot Points
  484. pvthi_ = ta.pivothigh(high, pvtLenL, pvtLenR)
  485. pvtlo_ = ta.pivotlow(low, pvtLenL, pvtLenR)
  486.  
  487. // Force Pivot completion before plotting.
  488. pvthi = pvthi_
  489. pvtlo = pvtlo_
  490.  
  491. // ||-----------------------------------------------------------------------------------------------------||
  492. // ||--- Higher Highs, Lower Highs, Higher Lows, Lower Lows -------------------------------------------||
  493. valuewhen_1 = ta.valuewhen(pvthi, high[pvtLenR], 1)
  494. valuewhen_2 = ta.valuewhen(pvthi, high[pvtLenR], 0)
  495. higherhigh = na(pvthi) ? na : valuewhen_1 < valuewhen_2 ? pvthi : na
  496. valuewhen_3 = ta.valuewhen(pvthi, high[pvtLenR], 1)
  497. valuewhen_4 = ta.valuewhen(pvthi, high[pvtLenR], 0)
  498. lowerhigh = na(pvthi) ? na : valuewhen_3 > valuewhen_4 ? pvthi : na
  499. valuewhen_5 = ta.valuewhen(pvtlo, low[pvtLenR], 1)
  500. valuewhen_6 = ta.valuewhen(pvtlo, low[pvtLenR], 0)
  501. higherlow = na(pvtlo) ? na : valuewhen_5 < valuewhen_6 ? pvtlo : na
  502. valuewhen_7 = ta.valuewhen(pvtlo, low[pvtLenR], 1)
  503. valuewhen_8 = ta.valuewhen(pvtlo, low[pvtLenR], 0)
  504. lowerlow = na(pvtlo) ? na : valuewhen_7 > valuewhen_8 ? pvtlo : na
  505.  
  506.  
  507. // If selected Display the HH/LL above/below candle.
  508. plotshape(ShowHHLL ? higherhigh : na, title='HH', location=location.abovebar, color=color.new(color.green, 0), text='HH', offset=-pvtLenR)
  509. plotshape(ShowHHLL ? higherlow : na, title='HL', location=location.belowbar, color=color.new(color.green, 0), text='HL', offset=-pvtLenR)
  510. plotshape(ShowHHLL ? lowerhigh : na, title='LH', location=location.abovebar, color=color.new(color.red, 0), text='LH', offset=-pvtLenR)
  511. plotshape(ShowHHLL ? lowerlow : na, title='LL', location=location.belowbar, color=color.new(color.red, 0), text='LL', offset=-pvtLenR)
  512.  
  513.  
  514. useColors = input(title='Fill with colors?', defval=true)
  515. isess = session.regular
  516. t = ticker.new(syminfo.prefix, syminfo.ticker, session=isess)
  517. igaps = barmerge.gaps_off
  518. yesterdayHigh = request.security(t, 'D', high[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
  519. yesterdayClose = request.security(t, 'D', close[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
  520. yesterdayLow = request.security(t, 'D', low[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
  521.  
  522.  
  523. // Plot the other time frame's data
  524. aH = timeframe.isintraday ? yesterdayHigh : na
  525.  
  526. cL = timeframe.isintraday ? yesterdayLow : na
  527.  
  528. up5on = input(true, title='5 Minute Opening Range High')
  529. down5on = input(true, title='5 Minute Opening Range Low')
  530.  
  531. is_newbar(res) =>
  532. ta.change(time(res)) != 0
  533.  
  534. adopt(r, s) =>
  535. request.security(syminfo.ticker, r, s)
  536.  
  537. high_range = ta.valuewhen(is_newbar('D'), high, 0)
  538. low_range = ta.valuewhen(is_newbar('D'), low, 0)
  539.  
  540. high_rangeL = ta.valuewhen(is_newbar('D'), high, 0)
  541. low_rangeL = ta.valuewhen(is_newbar('D'), low, 0)
  542.  
  543. up5 = up5on ? adopt('5', high_rangeL) : na
  544. down5 = down5on ? adopt('5', low_rangeL) : na
  545.  
  546.  
  547. bColor = #000000
  548. rColor = #ff0a02
  549. sColor = #008f0e
  550. pColor = #0900ff
  551. mColor = color.maroon
  552.  
  553.  
  554. myWidthMainLevels = input.int(title='Line width for Main levels', defval=1, minval=1)
  555. myStyle = plot.style_circles
  556.  
  557.  
  558. //plot(aH, title="H", color=#008f0e, linewidth=myWidthMainLevels, style=myStyle)
  559. //plot(cL, title="L", color=#ff0a02, linewidth=myWidthMainLevels, style=myStyle)
  560.  
  561. //plot(up5, title="UP", color=#000000, linewidth=myWidthMainLevels, style=myStyle)
  562. //plot(down5, title="DOWN", color=#000000, linewidth=myWidthMainLevels, style=myStyle)
  563.  
  564. //end of this part
  565.  
  566. //----- User inputs ---------------------
  567. Lookback1 = input.int(title='Lookback Left', defval=200, minval=1)
  568. Lookback2 = input.int(title='Lookback Right', defval=0, minval=0)
  569. VertLR = input(title='Show Vertical Left/Right', defval=true)
  570. VertHL = input(title='Show Vertical Highest/Lowest', defval=true)
  571. Count = input(title='Show Counts', defval=true)
  572. FullCount = input(title='Count All Bars', defval=false)
  573. Fibs = input(title='Show Fib Retrace Lines', defval=false)
  574. FibsExtHigh = input(title='Show Fib Ext Highs', defval=false)
  575. FibsExtLow = input(title='Show Fib Ext Lows', defval=false)
  576.  
  577.  
  578. //----- Main ---------------------
  579. // Get left and right endpoints. Though user input says "left" and "right", they are interchangeable.
  580. // The larger number is left, smaller number right.
  581. leftHL = math.max(Lookback1, Lookback2)
  582. rightHL = math.min(Lookback1, Lookback2)
  583. // Total num bars. Must be > 0 for highest() and lowest() to work. Add 1 to left bar, if needed.
  584. leftHL := leftHL - rightHL == 0 ? leftHL + 1 : leftHL
  585. lengthHL = leftHL - rightHL
  586.  
  587. // Highest price, looking back between the left/right endpoints
  588. highBack = ta.highest(high[rightHL], lengthHL)
  589. // Get # of bars back from present bar (offset).
  590. // NOTE: highestbars() returns a negative integer. Thus, subtract the right endpoint to get
  591. // offset from present (right-edge) bar
  592. highOffset = ta.highestbars(high[rightHL], lengthHL) - rightHL
  593.  
  594. // Lowest price, looking back
  595. lowBack = ta.lowest(low[rightHL], lengthHL)
  596. lowOffset = ta.lowestbars(low[rightHL], lengthHL) - rightHL
  597.  
  598. // Create a series of timestamps per bar. Needed to determine which bars are at the right edge,
  599. // While "n" starts at zero (left-edge bar) and counts up to the right-edge bar, this timestamp
  600. // (or tick) series counts the other way: max value at the left-edge, counting down to zero
  601. // at the right-edge.
  602. // This tick series is only valid while the indicator loads because "timenow" is the timestamp
  603. // of loading and "time" is the timestamp of a bar. The difference between the two timestamps
  604. // shrinks to zero as the righ-edge bar is processed. After loading, "timenow" and "time" are
  605. // the same value. Thus, "tick" always equals zero as new bars appear. But, for this indicator
  606. // this is sufficient behavior...
  607. tick = math.round((timenow - time) / ta.change(time)) // Each bar is a tick (float) in the timeline
  608. // Make a boolean mask for bars between left and right endpoints
  609. mask = FullCount ? true : tick < left and tick >= rightHL ? true : false
  610. // Determine the value of n at the left endpoint, used for visual counts of bars in mask
  611. nOffset = float(na)
  612. nOffset := FullCount ? 0 : tick == leftHL ? bar_index : nz(nOffset[1])
  613.  
  614. // Note: It would be nice to count between the highest/lowest bars, instead of left/right bars,
  615. // but this isn't possible because highOffset and lowOffset are moving around as the
  616. // indicator loads. Thus, "mask" isn't accurate...
  617.  
  618. //---- Plotting ---------------------
  619. // Horizontal Lines: Highest, Lowest dynamic lines
  620. // Params trackprice and offset make the horizontal line dynamic, adjusting to new highs/lows
  621. plot(highBack, title='Highest', color=color.new(color.red, 0), linewidth=2, trackprice=true, offset=-9999)
  622. plot(lowBack, title='Lowest', color=color.new(color.green, 0), linewidth=2, trackprice=true, offset=-9999)
  623.  
  624. // Veritcal Lines
  625. // Use barstate to paint/re-paint vertical lines, as new bars come into the data set.
  626. // islast - True for right most bar in data set. Use this to paint vertical bar, then push it back
  627. // in time with the offset parameter.
  628. // isrealtime - False while indicator loads. True for the right most bar, after loading.
  629. // isconfirmed - False while bar is not closed. True when close price appears.
  630. // isrealtime and isconfirmed - While indicator loads, ignore isconfirmed. After loading, isconfirmed
  631. // turns off the vertical line, as the bar closes. The next (new) bar is painted. This keeps
  632. // the vertical bar moving forward, as new bars appear, erasing the old (previous) vertical bar.
  633. VertLRShow = VertLR ? barstate.isrealtime and barstate.isconfirmed ? false : barstate.islast ? true : false : false
  634. // Can't use plot() with histogram/column because histbase can't accept "series" values
  635. bgcolor(VertLRShow ? color.gray : na, title='Vertical Left', offset=-leftHL + 1, transp=60)
  636. bgcolor(VertLRShow ? color.gray : na, title='Vertical Right', offset=-rightHL, transp=60)
  637. // Show vertical highest/lowest lines?
  638. VertHLShow = VertHL ? barstate.isrealtime and barstate.isconfirmed ? false : barstate.islast ? true : false : false
  639. bgcolor(VertHLShow ? color.red : na, title='Vertical Highest', offset=highOffset, transp=60)
  640. bgcolor(VertHLShow ? color.green : na, title='Vertical Lowest', offset=lowOffset, transp=60)
  641.  
  642. // Fib levels extension and retracement
  643. priceRange = highBack - lowBack
  644. plot(FibsExtHigh ? lowBack + 3.618 * priceRange : na, title='3.618', color=color.new(color.lime, 0), linewidth=2, trackprice=true, offset=-9999)
  645. plot(FibsExtHigh ? lowBack + 2.618 * priceRange : na, title='2.618', color=color.new(color.lime, 0), linewidth=2, trackprice=true, offset=-9999)
  646. plot(FibsExtHigh ? lowBack + 1.618 * priceRange : na, title='1.618', color=color.new(color.lime, 0), linewidth=2, trackprice=true, offset=-9999)
  647. plot(FibsExtHigh ? lowBack + 1.1 * priceRange : na, color=color.new(#88888800, 0), trackprice=true, offset=-9999, editable=false) // invisible line to work around pine plot bug
  648. plot(Fibs ? lowBack + 1.1 * priceRange : na, color=color.new(#88888800, 0), trackprice=true, offset=-9999, editable=false) // invisible line to work around pine plot bug
  649. plot(Fibs ? lowBack + 0.786 * priceRange : na, title='0.786', color=color.new(color.aqua, 0), linewidth=1, trackprice=true, offset=-9999)
  650. plot(Fibs ? lowBack + 0.618 * priceRange : na, title='0.618', color=color.new(color.orange, 0), linewidth=2, trackprice=true, offset=-9999)
  651. plot(Fibs ? lowBack + 0.50 * priceRange : na, title='0.5', color=color.new(color.yellow, 0), linewidth=2, trackprice=true, offset=-9999)
  652. plot(Fibs ? lowBack + 0.382 * priceRange : na, title='0.382', color=color.new(color.orange, 0), linewidth=2, trackprice=true, offset=-9999)
  653. plot(Fibs ? lowBack + 0.236 * priceRange : na, title='0.236', color=color.new(color.aqua, 0), linewidth=1, trackprice=true, offset=-9999)
  654. plot(Fibs ? highBack - 1.1 * priceRange : na, color=color.new(#88888800, 0), trackprice=true, offset=-9999, editable=false) // invisible line to work around pine plot bug
  655. plot(FibsExtLow ? highBack - 1.1 * priceRange : na, color=color.new(#88888800, 0), trackprice=true, offset=-9999, editable=false) // invisible line to work around pine plot bug
  656. plot(FibsExtLow ? highBack - 1.618 * priceRange : na, title='1.618', color=color.new(color.fuchsia, 0), linewidth=2, trackprice=true, offset=-9999)
  657. plot(FibsExtLow ? highBack - 2.618 * priceRange : na, title='2.618', color=color.new(color.fuchsia, 0), linewidth=2, trackprice=true, offset=-9999)
  658. plot(FibsExtLow ? highBack - 3.618 * priceRange : na, title='3.618', color=color.new(color.fuchsia, 0), linewidth=2, trackprice=true, offset=-9999)
  659.  
  660. // Lookback bar count
  661. countMod = mask ? (bar_index - nOffset) % 10 : na
  662. countInt = mask ? math.floor((bar_index - nOffset) / 10) % 10 : na
  663. plotshape(Count and countMod != 0 ? true : na, style=shape.circle, text='-', textcolor=color.new(color.gray, 0), color=color.new(#88888800, 0), location=location.bottom, size=size.auto, editable=false)
  664. plotshape(Count and countMod == 0 and countInt == 0 ? true : na, style=shape.circle, text='0', textcolor=color.new(color.gray, 0), color=color.new(#88888800, 0), location=location.bottom, size=size.auto, editable=false)
  665. plotshape(Count and countMod == 0 and countInt == 1 ? true : na, style=shape.circle, text='1', textcolor=color.new(color.gray, 0), color=color.new(#88888800, 0), location=location.bottom, size=size.auto, editable=false)
  666. plotshape(Count and countMod == 0 and countInt == 2 ? true : na, style=shape.circle, text='2', textcolor=color.new(color.gray, 0), color=color.new(#88888800, 0), location=location.bottom, size=size.auto, editable=false)
  667. plotshape(Count and countMod == 0 and countInt == 3 ? true : na, style=shape.circle, text='3', textcolor=color.new(color.gray, 0), color=color.new(#88888800, 0), location=location.bottom, size=size.auto, editable=false)
  668. plotshape(Count and countMod == 0 and countInt == 4 ? true : na, style=shape.circle, text='4', textcolor=color.new(color.gray, 0), color=color.new(#88888800, 0), location=location.bottom, size=size.auto, editable=false)
  669. plotshape(Count and countMod == 0 and countInt == 5 ? true : na, style=shape.circle, text='5', textcolor=color.new(color.gray, 0), color=color.new(#88888800, 0), location=location.bottom, size=size.auto, editable=false)
  670. plotshape(Count and countMod == 0 and countInt == 6 ? true : na, style=shape.circle, text='6', textcolor=color.new(color.gray, 0), color=color.new(#88888800, 0), location=location.bottom, size=size.auto, editable=false)
  671. plotshape(Count and countMod == 0 and countInt == 7 ? true : na, style=shape.circle, text='7', textcolor=color.new(color.gray, 0), color=color.new(#88888800, 0), location=location.bottom, size=size.auto, editable=false)
  672. plotshape(Count and countMod == 0 and countInt == 8 ? true : na, style=shape.circle, text='8', textcolor=color.new(color.gray, 0), color=color.new(#88888800, 0), location=location.bottom, size=size.auto, editable=false)
  673. plotshape(Count and countMod == 0 and countInt == 9 ? true : na, style=shape.circle, text='9', textcolor=color.new(color.gray, 0), color=color.new(#88888800, 0), location=location.bottom, size=size.auto, editable=false)
  674.  
  675. //end of this part
  676.  
  677.  
  678.  
  679. //
  680. // @author LonesomeTheBlue
  681. //
  682. //study("Pivot High Low Points", overlay=true)
  683. lb = input(6, title='Left Bars')
  684. rb = input(6, title='Right Bars')
  685.  
  686. mb = lb + rb + 1
  687.  
  688. highestbars_1 = ta.highestbars(mb)
  689. iff_1 = highestbars_1 == -lb ? high[lb] : na
  690. plot(not na(high[mb]) ? iff_1 : na, style=plot.style_cross, linewidth=3, color=color.new(color.blue, 0), offset=-lb)
  691. lowestbars_1 = ta.lowestbars(mb)
  692. iff_2 = lowestbars_1 == -lb ? low[lb] : na
  693. plot(not na(low[mb]) ? iff_2 : na, style=plot.style_cross, linewidth=3, color=color.new(color.blue, 0), offset=-lb)
  694.  
  695. //end of this part
  696.  
  697.  
  698.  
  699. //end of this part
  700.  
  701.  
  702. //study("VJ - Killer BS", overlay=true)
  703. //======================================================================
  704. //Jurij
  705. h_left = input(title='h left', defval=10)
  706. h_right = input(title='h right', defval=10)
  707. show_ptz = input(title='Show PTZ', defval=true)
  708. show_channel = input(title='Show channel', defval=true)
  709. //barCount = nz(barCount[1]) + 1
  710. //check history and realtime PTZ
  711. h_left_low = ta.lowest(h_left)
  712. h_left_high = ta.highest(h_left)
  713. newlow = low <= h_left_low
  714. newhigh = high >= h_left_high
  715. //channel_high = plot(show_channel ? h_left_low : 0, color=silver)
  716. //channel_low = plot (show_channel ? h_left_high : 0, color=silver)
  717. central_bar_low = low[h_right + 1]
  718. central_bar_high = high[h_right + 1]
  719. full_zone_low = ta.lowest(h_left + h_right + 1)
  720. full_zone_high = ta.highest(h_left + h_right + 1)
  721. central_bar_is_highest = central_bar_high >= full_zone_high
  722. central_bar_is_lowest = central_bar_low <= full_zone_low
  723. plotchar(central_bar_is_highest ? -1 : 0, offset=-h_right - 1, color=color.new(color.red, 0), text='Sell')
  724. plotchar(central_bar_is_lowest ? 1 : 0, offset=-h_right - 1, location=location.belowbar, color=color.new(color.green, 0), text='Buy')
  725. //plot(close)
  726.  
  727. //end of this part
  728.  
  729. //study(title="Peaks&Valleys", shorttitle="P&V", overlay=true)
  730. width = input(9)
  731. p = 0
  732. vc = 0
  733. for i = 0 to width * 2 by 1
  734. p := p + (i == width ? 0 : high[i] < high[width] ? 1 : 0)
  735. v := vc + (i == width ? 0 : low[i] > low[width] ? 1 : 0)
  736. v
  737. plotshape(p == width * 2, offset=-width, style=shape.labeldown)
  738. plotshape(vc == width * 2, offset=-width, style=shape.labelup, location=location.belowbar)
  739.  
  740. //end of this part
  741.  
  742. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  743. // © LonesomeTheBlue
  744.  
  745. //study("Double Zig Zag with HHLL", overlay = true, max_bars_back = 500)
  746. prdx1 = input.int(defval=8, title='ZigZag Period 1', minval=2, maxval=20)
  747. prdx2 = input.int(defval=20, title='ZigZag Period 2', minval=2, maxval=50)
  748. showzz = input.string(defval='Show Both', title='Show Zig Zags', options=['Show Zig Zag 1', 'Show Zig Zag 2', 'Show Both', 'Show None'])
  749. showhhll = input.string(defval='Show Both', title='Show HHLL', options=['Show HHLL 1', 'Show HHLL 2', 'Show Both', 'Show None'])
  750. upcol1 = input(defval=color.lime, title='Zig Zag 1 Up Color')
  751. dncol1 = input(defval=color.red, title='Zig Zag 1 Down Color')
  752. upcol2 = input(defval=color.blue, title='Zig Zag 2 Up Color')
  753. dncol2 = input(defval=color.purple, title='Zig Zag 2 Down Color')
  754. txtcol = input(defval=color.black, title='Text Color')
  755. zz1style = input.string(defval='Dashed', title='Zig Zag 1 Line Style', options=['Dashed', 'Dotted'])
  756. zz1width = input.int(defval=2, title='Zig zag 1 Line Width', minval=1, maxval=4)
  757. zz2width = input.int(defval=3, title='Zig zag 2 Line Width', minval=1, maxval=6)
  758.  
  759. float ph1x = ta.highestbars(high, prdx1) == 0 ? high : na
  760. float pl1x = ta.lowestbars(low, prdx1) == 0 ? low : na
  761. float ph2x = ta.highestbars(high, prdx2) == 0 ? high : na
  762. float pl2x = ta.lowestbars(low, prdx2) == 0 ? low : na
  763.  
  764. var dir1 = 0
  765. var dir2 = 0
  766. iff_3 = pl1x and na(ph1x) ? -1 : dir1
  767. dir1 := ph1x and na(pl1x) ? 1 : iff_3
  768. iff_4 = pl2x and na(ph2x) ? -1 : dir2
  769. dir2 := ph2x and na(pl2x) ? 1 : iff_4
  770.  
  771. var max_array_sizex = 10 // [5, 2] matrix
  772. var zigzag1 = array.new_float(0)
  773. var zigzag2 = array.new_float(0)
  774.  
  775. add_to_zigzagx(pointer, value, bindex) =>
  776. array.unshift(pointer, bindex)
  777. array.unshift(pointer, value)
  778. if array.size(pointer) > max_array_sizex
  779. array.pop(pointer)
  780. array.pop(pointer)
  781.  
  782. update_zigzagx(pointer, value, bindex, dir) =>
  783. if array.size(pointer) == 0
  784. add_to_zigzagx(pointer, value, bindex)
  785. else
  786. if dir == 1 and value > array.get(pointer, 0) or dir == -1 and value < array.get(pointer, 0)
  787. array.set(pointer, 0, value)
  788. array.set(pointer, 1, bindex)
  789. 0.
  790.  
  791. dir1changed = ta.change(dir1)
  792. if ph1x or pl1x
  793. if dir1changed
  794. add_to_zigzagx(zigzag1, dir1 == 1 ? ph1x : pl1x, bar_index)
  795. else
  796. update_zigzagx(zigzag1, dir1 == 1 ? ph1x : pl1x, bar_index, dir1)
  797.  
  798. dir2changed = ta.change(dir2)
  799. if ph2x or pl2x
  800. if dir2changed
  801. add_to_zigzagx(zigzag2, dir2 == 1 ? ph2x : pl2x, bar_index)
  802. else
  803. update_zigzagx(zigzag2, dir2 == 1 ? ph2x : pl2x, bar_index, dir2)
  804.  
  805. if array.size(zigzag1) >= 6
  806. var line zzline1 = na
  807. var label zzlabel1 = na
  808. float val = array.get(zigzag1, 0)
  809. int point = math.round(array.get(zigzag1, 1))
  810. if ta.change(val) or ta.change(point)
  811. float val1 = array.get(zigzag1, 2)
  812. int point1 = math.round(array.get(zigzag1, 3))
  813. if ta.change(val1) == 0 and ta.change(point1) == 0
  814. line.delete(zzline1)
  815. label.delete(zzlabel1)
  816. if showzz == 'Show Zig Zag 1' or showzz == 'Show Both'
  817. 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)
  818. zzline1
  819. if showhhll == 'Show HHLL 1' or showhhll == 'Show Both'
  820. hhlltxt = dir1 == 1 ? array.get(zigzag1, 0) > array.get(zigzag1, 4) ? 'HH' : 'LH' : array.get(zigzag1, 0) < array.get(zigzag1, 4) ? 'LL' : 'HL'
  821. labelcol = dir1 == 1 ? array.get(zigzag1, 0) > array.get(zigzag1, 4) ? upcol1 : dncol1 : array.get(zigzag1, 0) < array.get(zigzag1, 4) ? dncol1 : upcol1
  822. zzlabel1 := label.new(x=point, y=val, text=hhlltxt, color=labelcol, textcolor=txtcol, style=dir1 == 1 ? label.style_label_down : label.style_label_up)
  823. zzlabel1
  824.  
  825. if array.size(zigzag2) >= 6
  826. var line zzline2 = na
  827. var label zzlabel2 = na
  828. float val = array.get(zigzag2, 0)
  829. int point = math.round(array.get(zigzag2, 1))
  830. if ta.change(val) or ta.change(point)
  831. float val1 = array.get(zigzag2, 2)
  832. int point1 = math.round(array.get(zigzag2, 3))
  833. if ta.change(val1) == 0 and ta.change(point1) == 0
  834. line.delete(zzline2)
  835. label.delete(zzlabel2)
  836. if showzz == 'Show Zig Zag 2' or showzz == 'Show Both'
  837. zzline2 := line.new(x1=point, y1=val, x2=point1, y2=val1, color=dir2 == 1 ? upcol2 : dncol2, width=zz2width)
  838. zzline2
  839. if showhhll == 'Show HHLL 2' or showhhll == 'Show Both'
  840. hhlltxt = dir2 == 1 ? array.get(zigzag2, 0) > array.get(zigzag2, 4) ? 'HH' : 'LH' : array.get(zigzag2, 0) < array.get(zigzag2, 4) ? 'LL' : 'HL'
  841. labelcol = dir2 == 1 ? array.get(zigzag2, 0) > array.get(zigzag2, 4) ? upcol2 : dncol2 : array.get(zigzag2, 0) < array.get(zigzag2, 4) ? dncol2 : upcol2
  842. zzlabel2 := label.new(x=point, y=val, text=hhlltxt, color=labelcol, textcolor=txtcol, style=dir2 == 1 ? label.style_label_down : label.style_label_up)
  843. zzlabel2
  844.  
  845.  
  846. //end of this part
  847.  
  848. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  849. // © GokhanGoksin
  850.  
  851. //study("ENGUL",shorttitle="engulf",overlay=true)
  852. x = input(title='çizgi/sağ uzat', defval=5)
  853. z = input(title='kaynak/seç/üst çizgi', defval=open)
  854. y = input(title='kaynak/seç/alt çizgi', defval=close)
  855. //****************************************************
  856. en = close[1] < open[1] and close > open[1] and low[1] > low
  857. plotshape(en, style=shape.arrowup, location=location.belowbar)
  858. //****************************************************** enguluf destek
  859. if en
  860. li = line.new(time[1], y[1], time + x * (time - time[1]), y[1], xloc=xloc.bar_time, color=color.red, width=2)
  861. li
  862.  
  863. if en
  864. label.new(time + x * (time - time[1]), y[1], text='\n' + str.tostring(y[1]), xloc=xloc.bar_time, style=label.style_none, size=size.normal, textcolor=color.white, yloc=yloc.price)
  865. //********************************************************************** direnç
  866. if en
  867. line.new(time[1], z[1], time + x * (time - time[1]), z[1], xloc=xloc.bar_time, color=color.blue, width=2)
  868. if en
  869. l = label.new(time + x * (time - time[1]), z[1], text='\n' + str.tostring(z[1]), xloc=xloc.bar_time, style=label.style_none, size=size.normal, textcolor=color.white, yloc=yloc.price)
  870. l
  871.  
  872.  
  873. //end of this part
  874.  
  875. // © weeklystockcharts
  876.  
  877. // Candle Type w/ only 3-1 Pine Script
  878.  
  879. //study("Candle Type w/only 3-1", overlay=true, precision=0)
  880.  
  881. // check for 3-1 inside + up buy
  882. 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])
  883. plotchar(buyx, title='Inside + Up Buy Label', text='Up', location=location.belowbar, color=color.new(#4CAF50, 0))
  884.  
  885. // check for 3-1 inside + dn sell
  886. 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])
  887. plotchar(sellx, title='Inside + Up Buy Label', text='Down', location=location.abovebar, color=color.new(color.red, 0))
  888. //end of this part
  889.  
  890.  
  891.  
  892. //study("The system no.1", shorttitle="System no.1", overlay=true)
  893.  
  894. _length = input(title='Length', defval=21)
  895. _offset = input(title='Offset', defval=0)
  896.  
  897. _smooth = input.int(title='WMA Length', defval=8, minval=1)
  898.  
  899.  
  900. _source = close
  901.  
  902. _lsma = ta.linreg(_source, _length, _offset)
  903. _lsmaS = ta.wma(_lsma, _smooth)
  904. _lsmaC = ta.cross(_lsma, _lsmaS) ? (_lsma + _lsmaS) * 0.5 : na
  905. //iscross() => _lsmaC
  906. plot(_lsma, color=color.new(color.white, 0), linewidth=2)
  907. plot(_lsmaS, color=color.new(#2299CC, 0), linewidth=2)
  908. plotshape(_lsmaC, color=color.new(color.green, 0), style=shape.xcross)
  909.  
  910. //barcolor(iscross() ? yellow : na)
  911.  
  912. //coppock
  913.  
  914. wmaLength = input(title='WMA Length', defval=10)
  915. longRoCLength = input(title='Long RoC Length', defval=14)
  916. shortRoCLength = input(title='Short RoC Length', defval=11)
  917.  
  918. _crossoverMA = input.int(title='Crossover WMA Lenth', defval=5, minval=1)
  919. _histogramMultiplier = input.float(title='Histogram Multiplier', defval=2)
  920.  
  921. _sourcec = close
  922.  
  923. _curve = ta.wma(ta.roc(_sourcec, longRoCLength) + ta.roc(_sourcec, shortRoCLength), wmaLength)
  924. _curveWMA = ta.wma(_curve, _crossoverMA)
  925.  
  926. _h = (_curve - _curveWMA) * _histogramMultiplier
  927.  
  928. _curveWMAx = ta.cross(_curve, _curveWMA) ? (_curve + _curveWMA) * 0.5 : na
  929.  
  930. //final decision
  931. check(x, y) =>
  932. ta.cross(_curve[x], _curveWMA[x]) and ta.cross(_lsma[y], _lsmaS[y])
  933. check00 = check(0, 0)
  934. check01 = check(0, 1)
  935. check02 = check(0, 2)
  936. check10 = check(1, 0)
  937. //check11 = check(1,1)
  938. //check12 = check(1,2)
  939. check20 = check(2, 0)
  940. //check21 = check(2,1)
  941. check03 = check(0, 3)
  942. //check13 = check(1,3)
  943. //check23 = check(2,3)
  944. check30 = check(3, 0)
  945. //check22 = check(2,2)
  946. checkcross = check00 ? true : check01 ? true : check02 ? true : check10 ? true : check30 ? true : check20 ? true : check03 ? true : na
  947.  
  948.  
  949.  
  950. //checking value
  951. mathcall = (math.abs(ta.lowest(_curve, 50)) + math.abs(ta.highest(_curve, 50))) * 0.3
  952. highalert = ta.highest(_curve, 50) - mathcall
  953. lowalert = ta.lowest(_curve, 50) + mathcall
  954.  
  955. // sell position
  956. sellcheck = _curveWMA > _curve ? true : false
  957. sellcheck1 = _lsma < _lsmaS ? true : false
  958. sellcheck2 = _curve > highalert
  959.  
  960. SELLSIGNAL = checkcross and sellcheck and sellcheck1 and sellcheck2
  961. barcolor(SELLSIGNAL ? color.yellow : na)
  962.  
  963. // buy position
  964. buycheck = _curveWMA < _curve ? true : false
  965. buycheck1 = _lsma > _lsmaS ? true : false
  966. buycheck2 = _curve < lowalert
  967.  
  968. BUYSIGNAL = checkcross and buycheck and buycheck1 and buycheck2
  969. barcolor(BUYSIGNAL ? color.blue : na)
  970.  
  971. //end of this part
  972.  
  973. //
  974. //@author BillionaireLau
  975. //
  976.  
  977. //study("Key price levels", overlay=true)
  978. lbc = input.int(15, title='Number of bars searching backward', minval=1)
  979. rbc = input.int(15, title='Number of bars searching forward', minval=1)
  980.  
  981. showsupres = input(true, title='Show Support/Resistance')
  982. changebarcol = input(true, title='Change Bar Color')
  983. mbc = lbc + rbc + 1
  984.  
  985. highestbars_2 = ta.highestbars(high, mbc) // Pivot High
  986. iff_5 = highestbars_2 == -lbc ? high[lbc] : na
  987. phc = not na(high[mbc]) ? iff_5 : na
  988. lowestbars_2 = ta.lowestbars(low, mbc) // Pivot Low
  989. iff_6 = lowestbars_2 == -lbc ? low[lbc] : na
  990. plc = not na(low[mbc]) ? iff_6 : na
  991.  
  992. hlc = int(na)
  993. iff_7 = plc ? -1 : na // Trend direction
  994. hlc := phc ? 1 : iff_7
  995. zz = float(na)
  996. iff_8 = plc ? plc : na // similar to zigzag but may have multiple highs/lows
  997. zz := phc ? phc : iff_8
  998. valuewhen_13 = ta.valuewhen(hlc, hlc, 1)
  999. valuewhen_14 = ta.valuewhen(zz, zz, 1)
  1000. zz := plc and hlc == -1 and valuewhen_13 == -1 and plc > valuewhen_14 ? na : zz
  1001. valuewhen_15 = ta.valuewhen(hlc, hlc, 1)
  1002. valuewhen_16 = ta.valuewhen(zz, zz, 1)
  1003. zz := phc and hlc == 1 and valuewhen_15 == 1 and phc < valuewhen_16 ? na : zz
  1004.  
  1005. valuewhen_17 = ta.valuewhen(hlc, hlc, 1)
  1006. valuewhen_18 = ta.valuewhen(zz, zz, 1)
  1007. hlc := hlc == -1 and valuewhen_17 == 1 and zz > valuewhen_18 ? na : hlc
  1008. valuewhen_19 = ta.valuewhen(hlc, hlc, 1)
  1009. valuewhen_20 = ta.valuewhen(zz, zz, 1)
  1010. hlc := hlc == 1 and valuewhen_19 == -1 and zz < valuewhen_20 ? na : hlc
  1011. zz := na(hlc) ? na : zz
  1012.  
  1013. findprevious() => // finds previous three points (b, c, d, e)
  1014. ehl = hlc == 1 ? -1 : 1
  1015. loc1 = 0.0
  1016. loc2 = 0.0
  1017. loc3 = 0.0
  1018. loc4 = 0.0
  1019. xx = 0
  1020. for x = 1 to 1000 by 1
  1021. if hlc[x] == ehl and not na(zz[x])
  1022. loc1 := zz[x]
  1023. xx := x + 1
  1024. break
  1025. ehl := hlc
  1026. for x = xx to 1000 by 1
  1027. if hlc[x] == ehl and not na(zz[x])
  1028. loc2 := zz[x]
  1029. xx := x + 1
  1030. break
  1031. ehl := hlc == 1 ? -1 : 1
  1032. for x = xx to 1000 by 1
  1033. if hlc[x] == ehl and not na(zz[x])
  1034. loc3 := zz[x]
  1035. xx := x + 1
  1036. break
  1037. ehl := hlc
  1038. for x = xx to 1000 by 1
  1039. if hlc[x] == ehl and not na(zz[x])
  1040. loc4 := zz[x]
  1041. break
  1042. [loc1, loc2, loc3, loc4]
  1043.  
  1044. axx = float(na)
  1045. bxx = float(na)
  1046. cxx = float(na)
  1047. dxx = float(na)
  1048. exx = float(na)
  1049. if not na(hlc)
  1050. [loc1, loc2, loc3, loc4] = findprevious()
  1051. axx := zz
  1052. bxx := loc1
  1053. cxx := loc2
  1054. dxx := loc3
  1055. exx := loc4
  1056. exx
  1057.  
  1058. _hh = zz and axx > bxx and axx > cxx and cxx > bxx and cxx > dxx
  1059. _ll = zz and axx < bxx and axx < cxx and cxx < bxx and cxx < dxx
  1060. _hl = zz and (axx >= cxx and bxx > cxx and bxx > dxx and dxx > cxx and dxx > exx or axx < bxx and axx > cxx and bxx < dxx)
  1061. _lh = zz and (axx <= cxx and bxx < cxx and bxx < dxx and dxx < cxx and dxx < exx or axx > bxx and axx < cxx and bxx > dxx)
  1062.  
  1063.  
  1064. //Lows
  1065. if _ll
  1066. label.new(bar_index[lbc], na, str.tostring(low[lbc], '####.##'), color=color.lime, textcolor=color.lime, style=label.style_none, yloc=yloc.belowbar)
  1067. if _hl
  1068. label.new(bar_index[lbc], na, str.tostring(low[lbc], '####.##'), color=color.lime, textcolor=color.lime, style=label.style_none, yloc=yloc.belowbar)
  1069.  
  1070. //Highs
  1071. if _lh
  1072. label.new(bar_index[lbc], na, str.tostring(high[lbc], '####.##'), color=color.red, textcolor=color.red, style=label.style_none, yloc=yloc.abovebar)
  1073. if _hh
  1074. label.new(bar_index[lbc], na, str.tostring(high[lbc], '####.##'), color=color.red, textcolor=color.red, style=label.style_none, yloc=yloc.abovebar)
  1075.  
  1076.  
  1077.  
  1078.  
  1079.  
  1080.  
  1081. res = float(na)
  1082. sup = float(na)
  1083. res := _lh ? zz : res[1]
  1084. sup := _hl ? zz : sup[1]
  1085.  
  1086. trend = int(na)
  1087. iff_9 = close < sup ? -1 : nz(trend[1])
  1088. trend := close > res ? 1 : iff_9
  1089.  
  1090. res := trend == 1 and _hh or trend == -1 and _lh ? zz : res
  1091. sup := trend == 1 and _hl or trend == -1 and _ll ? zz : sup
  1092.  
  1093. //plot(showsupres ? res : na, title="Resistance", color=na(res) ? na : color.red, linewidth=2, style=plot.style_circles, offset=-lb)
  1094. //plot(showsupres ? sup : na, title="Support", color=na(sup) ? na : color.blue, linewidth=2, style=plot.style_circles, offset=-lb)
  1095.  
  1096.  
  1097. //end of this part
  1098.  
  1099.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement