Untitled
unknown
plain_text
7 months ago
17 kB
51
Indexable
//@version=6 indicator('MACD, RSI & Stokastik + Uyumsuzluklar', shorttitle = 'MRS + DIV', max_lines_count = 500, max_labels_count = 500, max_bars_back = 5000, overlay = false) i_hi = input.string('high', title = '', group = 'source [high - low]', inline = 'hl', options = ['high', 'close', 'max open/close']) i_lo = input.string('low', title = '', group = 'source [high - low]', inline = 'hl', options = ['low', 'close', 'min open/close']) left = input.int(10, 'left ', inline = 'l') iBl_Reg = input.bool(true, 'Bullish Regular DIV ', inline = 'a') iColBl_Reg = input.color(color.lime, '', inline = 'a') iBl_Hid = input.bool(false, 'Bullish Hidden DIV ', inline = 'b') iColBl_Hid = input.color(color.gray, '', inline = 'b') iBr_Reg = input.bool(true, 'Bearish Regular DIV', inline = 'c') iColBr_Reg = input.color(color.red, '', inline = 'c') iBr_Hid = input.bool(false, 'Bearish Hidden DIV ', inline = 'd') iColBr_Hid = input.color(color.gray, '', inline = 'd') show = input.string('rsi', 'show ', options = ['rsi', 'stoch', 'macd', 'hist', 'none'], group = 'settings', inline = 's') src = input(close, title = 'Source', group = 'settings') lenrsi = input.int(14, title = 'rsi ', group = 'settings', inline = 'rsi') lenK = input.int(14, title = 'stoch ', group = 'settings', inline = 'stoch') smoothK = input.int(3, title = '', group = 'settings', inline = 'stoch') smoothD = input.int(3, title = '', group = 'settings', inline = 'stoch') fastLen = input.int(12, title = 'macd ', group = 'settings', inline = 'macd') slowLen = input.int(26, title = '', group = 'settings', inline = 'macd') signLen = input.int(9, title = '', group = 'settings', inline = 'macd') maxBack = input.int(1000, 'Lookback', minval = 500, maxval = 2000, tooltip = 'lines can be max x bars long') bars = math.max(maxBack + 1, input.int(1000, 'only last ', inline = 'bars', minval = 500, maxval = 5000)) last_b = input.bool(true, 'bars (=faster)', inline = 'bars') frstPiv = input.bool(true, 'left osc point must be a Pivot Point') lines = input.bool(true, title = 'Show Lines') arrows = input.bool(false, title = 'Show Arrows') symbl = input.string(title = 'Style', defval = 'Label', group = 'Labels', options = ['Label', 'Arrow', 'Triangle', 'Circle', 'Square', 'Xcross', 'Cross', 'Flag', 'Diamond']) size = input.string(title = 'Label Size', defval = 'Auto', group = 'Labels', options = ['Tiny', 'Small', 'Normal', 'Auto']) hi = i_hi == 'high' ? high : i_hi == 'close' ? close : math.max(open, close) lo = i_lo == 'low' ? low : i_hi == 'close' ? close : math.min(open, close) rsi = ta.rsi(src, lenrsi) k = ta.sma(ta.stoch(rsi, rsi, rsi, lenK), smoothK) d = ta.sma(k, smoothD) islast_b = last_b ? last_bar_index - bar_index < bars : true [macd, sign, hist] = ta.macd(close, fastLen, slowLen, signLen) sBull = label.style_label_up sBear = label.style_label_down _size = size.auto switch symbl 'Label' => sBull := label.style_label_up sBear := label.style_label_down sBear 'Arrow' => sBull := label.style_arrowup sBear := label.style_arrowdown sBear 'Triangle' => sBull := label.style_triangleup sBear := label.style_triangledown sBear 'Circle' => sBull := label.style_circle sBear := label.style_circle sBear 'Square' => sBull := label.style_square sBear := label.style_square sBear 'Xcross' => sBull := label.style_xcross sBear := label.style_xcross sBear 'Cross' => sBull := label.style_cross sBear := label.style_cross sBear 'Flag' => sBull := label.style_flag sBear := label.style_flag sBear 'Diamond' => sBull := label.style_diamond sBear := label.style_diamond sBear switch size 'Tiny' => _size := size.tiny _size 'Small' => _size := size.small _size 'Normal' => _size := size.normal _size 'Auto' => _size := size.auto _size osc = switch show 'rsi' => rsi 'stoch' => k 'macd' => macd 'hist' => hist => na ph = ta.pivothigh(hi, left, 1) pl = ta.pivotlow(lo, left, 1) // drawWhenPh(osc) => if bool(ph) and islast_b for i = 2 to maxBack by 1 if nz(hi[i], hi) > nz(hi[i + 1], hi) and nz(hi[i], hi) > nz(hi[i - 1], hi) broken = false testline = line.new(bar_index - i, nz(hi[i], hi), bar_index - 1, ph) for j = 1 to i by 1 if hi[j] > line.get_price(testline, bar_index - j) broken := true break if broken == false maxOSCp1 = math.max(osc[i], osc[i + 1], osc[i + 2]) idx1 = maxOSCp1 == osc[i] ? i : maxOSCp1 == osc[i + 1] ? i + 1 : i + 2 maxOSCp2 = 0. //math.max(osc , osc[ 1], osc[ 2]) idx2 = 0 //maxOSCp2 == osc ? 0 : maxOSCp2 == osc[ 1] ? 1 : 2 // isHgst1 = osc[1] > osc and osc[1] > osc[2] isHgst2 = osc[2] > osc[1] and osc[2] > osc[3] maxOSCp2 := isHgst1 ? osc[1] : isHgst2 ? osc[2] : na idx2 := isHgst1 ? 1 : isHgst2 ? 2 : na // x1 = bar_index - idx1 y1 = maxOSCp1 x2 = bar_index - idx2 y2 = maxOSCp2 if isHgst1 or isHgst2 testln2_OSC = frstPiv ? line.new(x1 - left, y1 - (y2 - y1) / (x2 - x1) * left, x2, y2) : line.new(x1, y1, x2, y2) for l = 1 to frstPiv ? i + left : i by 1 if osc[l] > line.get_price(testln2_OSC, bar_index - l) broken := true break if broken == false if iBr_Hid and maxOSCp2 > maxOSCp1 and ph < nz(hi[i], hi) if arrows label.new(bar_index - idx2, maxOSCp2, style = sBear, color = iColBr_Hid, yloc = yloc.price, size = _size) if lines line.new(bar_index - idx1, maxOSCp1, bar_index - idx2, maxOSCp2, color = color.gray) if iBr_Reg and maxOSCp2 < maxOSCp1 and ph > nz(hi[i], hi) if arrows label.new(bar_index - idx2, maxOSCp2, style = sBear, color = iColBr_Reg, yloc = yloc.price, size = _size) if lines line.new(bar_index - idx1, maxOSCp1, bar_index - idx2, maxOSCp2, color = color.red) line.delete(testln2_OSC) line.delete(testline) // if bool(ph[1]) and islast_b for i = 3 to maxBack by 1 if nz(hi[i], hi) > nz(hi[i + 1], hi) and nz(hi[i], hi) > nz(hi[i - 1], hi) broken = false testline = line.new(bar_index - i, nz(hi[i], hi), bar_index - 2, ph[1]) for j = 2 to i by 1 if hi[j] > line.get_price(testline, bar_index - j) broken := true break if broken == false maxOSCp1 = math.max(osc[i], osc[i + 1], osc[i + 2]) idx1 = maxOSCp1 == osc[i] ? i : maxOSCp1 == osc[i + 1] ? i + 1 : i + 2 maxOSCp2 = 0. idx2 = 0 isHgst1 = osc[1] > osc and osc[1] > osc[2] maxOSCp2 := isHgst1 ? osc[1] : na idx2 := isHgst1 ? 1 : na x1 = bar_index - idx1 y1 = maxOSCp1 x2 = bar_index - idx2 y2 = maxOSCp2 if isHgst1 testln2_OSC = frstPiv ? line.new(x1 - left, y1 - (y2 - y1) / (x2 - x1) * left, x2, y2) : line.new(x1, y1, x2, y2) for l = 2 to frstPiv ? i + left : i by 1 if osc[l] > line.get_price(testln2_OSC, bar_index - l) broken := true break if broken == false if iBr_Hid and maxOSCp2 > maxOSCp1 and ph[1] < nz(hi[i], hi) if arrows label.new(bar_index - idx2, maxOSCp2, style = sBear, color = iColBr_Hid, yloc = yloc.price, size = _size) if lines line.new(bar_index - idx1, maxOSCp1, bar_index - idx2, maxOSCp2, color = color.gray) if iBr_Reg and maxOSCp2 < maxOSCp1 and ph[1] > nz(hi[i], hi) if arrows label.new(bar_index - idx2, maxOSCp2, style = sBear, color = iColBr_Reg, yloc = yloc.price, size = _size) if lines line.new(bar_index - idx1, maxOSCp1, bar_index - idx2, maxOSCp2, color = color.red) line.delete(testln2_OSC) line.delete(testline) // drawWhenPl(osc) => if bool(pl) and islast_b for i = 1 to maxBack by 1 if nz(lo[i], lo) < nz(lo[i + 1], lo) and nz(lo[i], lo) < nz(lo[i - 1], lo) broken = false testline = line.new(bar_index - i, nz(lo[i], lo), bar_index - 1, pl) for j = 1 to i by 1 if lo[j] < line.get_price(testline, bar_index - j) broken := true break if broken == false minOSCp1 = math.min(osc[i], osc[i + 1], osc[i + 2]) idx1 = minOSCp1 == osc[i] ? i : minOSCp1 == osc[i + 1] ? i + 1 : i + 2 minOSCp2 = 0. idx2 = 0 isLwst1 = osc[1] < osc and osc[1] < osc[2] isLwst2 = osc[2] < osc[1] and osc[2] < osc[3] minOSCp2 := isLwst1 ? osc[1] : isLwst2 ? osc[2] : na idx2 := isLwst1 ? 1 : isLwst2 ? 2 : na x1 = bar_index - idx1 y1 = minOSCp1 x2 = bar_index - idx2 y2 = minOSCp2 if isLwst1 or isLwst2 testln2_OSC = frstPiv ? line.new(x1 - left, y1 - (y2 - y1) / (x2 - x1) * left, x2, y2) : line.new(x1, y1, x2, y2) for l = 1 to frstPiv ? i + left : i by 1 if osc[l] < line.get_price(testln2_OSC, bar_index - l) broken := true break if broken == false if iBl_Hid and minOSCp2 < minOSCp1 and pl > nz(lo[i], lo) if arrows label.new(bar_index - idx2, minOSCp2, style = sBull, color = iColBl_Hid, yloc = yloc.price, size = _size) if lines line.new(bar_index - idx1, minOSCp1, bar_index - idx2, minOSCp2, color = color.gray) if iBl_Reg and minOSCp2 > minOSCp1 and pl < nz(lo[i], lo) if arrows label.new(bar_index - idx2, minOSCp2, style = sBull, color = iColBl_Reg, yloc = yloc.price, size = _size) if lines line.new(bar_index - idx1, minOSCp1, bar_index - idx2, minOSCp2, color = color.lime) line.delete(testln2_OSC) line.delete(testline) // if bool(pl[1]) and islast_b for i = 3 to maxBack by 1 if nz(lo[i], lo) < nz(lo[i + 1], lo) and nz(lo[i], lo) < nz(lo[i - 1], lo) broken = false testline = line.new(bar_index - i, nz(lo[i], lo), bar_index - 2, pl[1]) for j = 2 to i by 1 if lo[j] < line.get_price(testline, bar_index - j) broken := true break if broken == false minOSCp1 = math.min(osc[i], osc[i + 1], osc[i + 2]) idx1 = minOSCp1 == osc[i] ? i : minOSCp1 == osc[i + 1] ? i + 1 : i + 2 minOSCp2 = 0. idx2 = 0 isLwst1 = osc[1] < osc and osc[1] < osc[2] minOSCp2 := isLwst1 ? osc[1] : na idx2 := isLwst1 ? 1 : na x1 = bar_index - idx1 y1 = minOSCp1 x2 = bar_index - idx2 y2 = minOSCp2 if isLwst1 testln2_OSC = frstPiv ? line.new(x1 - left, y1 - (y2 - y1) / (x2 - x1) * left, x2, y2) : line.new(x1, y1, x2, y2) for l = 2 to frstPiv ? i + left : i by 1 if osc[l] < line.get_price(testln2_OSC, bar_index - l) broken := true break if broken == false if iBl_Hid and minOSCp2 < minOSCp1 and pl[1] > nz(lo[i], lo) if arrows label.new(bar_index - idx2, minOSCp2, style = sBull, color = iColBl_Hid, yloc = yloc.price, size = _size) if lines line.new(bar_index - idx1, minOSCp1, bar_index - idx2, minOSCp2, color = color.gray) if iBl_Reg and minOSCp2 > minOSCp1 and pl[1] < nz(lo[i], lo) if arrows label.new(bar_index - idx2, minOSCp2, style = sBull, color = iColBl_Reg, yloc = yloc.price, size = _size) if lines line.new(bar_index - idx1, minOSCp1, bar_index - idx2, minOSCp2, color = color.lime) line.delete(testln2_OSC) line.delete(testline) drawWhenPh(osc) drawWhenPl(osc) pk = plot(show == 'stoch' ? k : na, linewidth = 2, color = color.new(color.aqua, 50), title = 'Stoch \'k\'') pd = plot(show == 'stoch' ? d : na, linewidth = 2, color = color.new(color.red, 50), title = 'Stoch \'d\'') fill(pk, pd, color.new(k > d ? color.green : color.red, 75), title = 'BG Over/Undersold RSI') plot(show == 'rsi' ? rsi : na, linewidth = 1, color = color.yellow, title = 'RSI') col_black = color.new(color.black, 100) colT = input.color(color.new(color.red, 80), '', inline = 'lT', group = 'Hlines') colM = input.color(color.new(color.yellow, 20), '', inline = 'lM', group = 'Hlines') colB = input.color(color.new(color.lime, 80), '', inline = 'lB', group = 'Hlines') h2 = hline(show == 'rsi' or show == 'stoch' ? input.int(20, '', inline = 'lB', group = 'Hlines') : na, color = show == 'rsi' or show == 'stoch' ? col_black : color(na), linestyle = hline.style_dotted, title = 'Extreme Oversold Stoch Rsi') h3 = hline(show == 'rsi' or show == 'stoch' ? input.int(30, '', inline = 'lB', group = 'Hlines') : na, color = show == 'rsi' or show == 'stoch' ? col_black : color(na), linestyle = hline.style_dotted, title = 'Oversold Stoch Rsi') h5 = hline(show == 'rsi' or show == 'stoch' ? input.int(50, '', inline = 'lM', group = 'Hlines') : na, color = show == 'rsi' or show == 'stoch' ? colM : color(na), linestyle = hline.style_dotted, title = 'Middle line') h7 = hline(show == 'rsi' or show == 'stoch' ? input.int(70, '', inline = 'lT', group = 'Hlines') : na, color = show == 'rsi' or show == 'stoch' ? col_black : color(na), linestyle = hline.style_dotted, title = 'Overbought Stoch Rsi') h8 = hline(show == 'rsi' or show == 'stoch' ? input.int(80, '', inline = 'lT', group = 'Hlines') : na, color = show == 'rsi' or show == 'stoch' ? col_black : color(na), linestyle = hline.style_dotted, title = 'Extreme Overbought Stoch Rsi') fill(h3, h2, color = colB, title = 'BG Color overbought to extreme overbought zone') fill(h8, h7, color = colT, title = 'BG Color oversold to extreme oversold zone') col_grow_above = #26A69A col_grow_below = #FFCDD2 col_fall_above = #B2DFDB col_fall_below = #EF5350 col_macd = #0094ff col_signal = #ff6a00 plot(show == 'macd' or show == 'hist' ? hist : na, title = 'Histogram', style = plot.style_columns, color = hist >= 0 ? hist[1] < hist ? col_grow_above : col_fall_above : hist[1] < hist ? col_grow_below : col_fall_below) plot(show == 'macd' or show == 'hist' ? macd : na, title = 'MACD', color = col_macd, linewidth = 2) plot(show == 'macd' or show == 'hist' ? sign : na, title = 'Signal', color = col_signal, linewidth = 2)
Editor is loading...
Leave a Comment