PHP Code:
//@version=6
indicator('...', overlay = true, max_lines_count = 500, max_labels_count = 500)
ma_tt = '=== Moving Average Cycle ==='
_source = close
_p = input(100, title = 'Period', inline = 'set1', group = ma_tt)
//macycle_note_1 = input(false, '1. MA Cycle above 0, background is filled by blue', group = ma_tt)
//macycle_note_2 = input(false, '2. MA Cycle below 0, background is filled by red', group = ma_tt)
//_fill = input.bool(true, title = 'Fill background', group = ma_tt)
_c = ta.ema(close, _p) - ta.sma(close, _p)
//
//rsi_tt = '=== RSI ==='
//rsi_len = input.int(14, title = 'Period', inline = 'set', group = rsi_tt)
//rsi_ovb_lv = input.int(70, title = 'Overbought', inline = 'set2', group = rsi_tt)
//rsi_ovs_lv = input.int(30, title = 'Oversold', inline = 'set2', group = rsi_tt)
//rsi_note_1 = input(false, '1. RSI Overbought show as Hot Face', group = rsi_tt)
//rsi_note_2 = input(false, '2. RSI Oversold show as Cold Face', group = rsi_tt)
//_rsi_show = input(true, title = 'Show RSI', inline = 'set3', group = rsi_tt)
//_rsi = ta.rsi(close, rsi_len)
//_rsi_ovb = _rsi[0] > rsi_ovb_lv[0]
//_rsi_ovs = _rsi[0] < rsi_ovs_lv[0]
//plotshape(_rsi_show and _rsi_ovb ? _rsi : na, title = 'RSI Overbought', style = shape.labeldown, location = location.bottom, color = color.new(color.aqua, 100), offset = 0, text = '', textcolor = color.new(color.black, 0))
//plotshape(_rsi_show and _rsi_ovs ? _rsi : na, title = 'RSI Oversold', style = shape.labeldown, location = location.bottom, color = color.new(color.aqua, 100), offset = 0, text = '', textcolor = color.new(color.black, 0))
//_rsi_ovb_log = _rsi_ovb[1] == false and _rsi_ovb == true
//_rsi_ovs_log = _rsi_ovs[1] == false and _rsi_ovs == true
//_rsi_ovb_index = bar_index > 0 ? bar_index - ta.valuewhen(_rsi_ovb_log, bar_index, 0) : 1
//_rsi_ovs_index = bar_index > 0 ? bar_index - ta.valuewhen(_rsi_ovs_log, bar_index, 0) : 1
//MACD
//macd_tt = '=== MACD ==='
//macd_source = close
//macd_fast = input.int(12, title = 'Fast', inline = 'set1', group = macd_tt)
//macd_slow = input.int(26, title = 'Slow', inline = 'set1', group = macd_tt)
//macd_sig = input.int(9, title = 'Signal', inline = 'set1', group = macd_tt)
//macd_note_1 = input(false, '1. MACD show as circle', group = macd_tt)
//macd_note_2 = input(false, '2. MACD Buy Signal show as Arrow Up', group = macd_tt)
//macd_note_3 = input(false, '3. MACD Sell Signal show as Arrow Down', group = macd_tt)
//_macd_show = input(true, title = 'Show MACD', inline = 'set2', group = macd_tt)
//[_macd, _signal, _hist] = ta.macd(macd_source, macd_fast, macd_slow, macd_sig)
//_macd_buy_signal = _macd[1] < _signal[1] and _macd[0] > _signal[0]
//_macd_sell_signal = _macd[1] > _signal[1] and _macd[0] < _signal[0]
//plotshape(_macd_show and _macd_buy_signal == false and _macd_sell_signal == false ? _macd : na, title = 'MACD', style = shape.circle, location = location.bottom, color = _macd > _signal ? color.new(color.lime, 0) : color.new(color.red, 0), offset = 0)
//plotshape(_macd_show and _macd_buy_signal ? _macd : na, title = 'MACD Buy Signal', style = shape.arrowup, location = location.bottom, color = color.new(color.lime, 0), offset = 0)
//plotshape(_macd_show and _macd_sell_signal ? _macd : na, title = 'MACD Sell Signal', style = shape.arrowdown, location = location.bottom, color = color.new(color.red, 0), offset = 0)
//
//var _rsi_val = 0
_m = 0
//if _rsi_ovb_index < _rsi_ovs_index
//_rsi_val := -1
//_rsi_val
//else
//if _rsi_ovb_index > _rsi_ovs_index
//_rsi_val := 1
//_rsi_val
//else
//_rsi_val := _rsi_val[1]
//_rsi_val
//if _rsi_val == -1 and _macd_sell_signal == true
//_m := -1
//_m
//else
//if _rsi_val == 1 and _macd_buy_signal == true
//_m := 1
//_m
//else
//_m := _m[1]
//_m
//
//rsi_macd = 'RSI MACD Background Filling'
//rsi_macd_note_1 = input(false, '1. MACD Buy Signal after RSI Oversold, background is filled by blue', group = rsi_macd)
//rsi_macd_note_2 = input(false, '2. MACD Sell Signal after RSI Overbought, background is filled by red', group = rsi_macd)
//_fill_rsi_macd = input.bool(false, title = 'Fill background', group = rsi_macd)
//Gaussian Filter script by Alex Orekhov (everget)
//gf_tt = '=== Gaussian Filter ==='
//cyclePeriod = input.int(title = 'Period', minval = 1, defval = 100, inline = 'set', group = gf_tt)
//src = input(title = 'Source', defval = close, inline = 'set', group = gf_tt)
//gf_note_1 = input(false, '1. Price moving above Gaussian Filter, background is filled by blue', group = gf_tt)
//gf_note_2 = input(false, '2. Price moving below Gaussian Filter, background is filled by red', group = gf_tt)
//_fill_gf = input.bool(false, title = 'Fill background', group = gf_tt)
//Calculate GF with Number of Poles = 4
//PI = 2 * math.asin(1)
//beta = (1 - math.cos(2 * PI / cyclePeriod)) / (math.pow(2, 1 / 4.0) - 1)
//alpha = -beta + math.sqrt(math.pow(beta, 2) + 2 * beta)
//getGF() =>
//filter = 0.0
//filter := math.pow(alpha, 4) * src + 4 * (1 - alpha) * nz(filter[1]) - 6 * math.pow(1 - alpha, 2) * nz(filter[2]) + 4 * math.pow(1 - alpha, 3) * nz(filter[3]) - math.pow(1 - alpha, 4) * nz(filter[4])
//filter
//gf = getGF()
//_g = close > gf ? 1 : -1
//
sr_group = '=== Support Resistance ==='
Left = input.int(4, title = '.', minval = 1, group = sr_group)
Right = input.int(4, title = '.', minval = 0, group = sr_group)
trading_group = '=== Trading Setup ==='
trading_setup = input.string('Both', title = 'Setup', options = ['Long Only', 'Short Only', 'Both', 'MA Cycle', 'RSI_MACD', 'Gaussian_Filter'], group = trading_group)
var Long = false
Short = false
if trading_setup == 'Long Only'
Long := true
Short := false
Short
else if trading_setup == 'Short Only'
Long := false
Short := true
Short
else if trading_setup == 'MA Cycle'
if _c > 0
Long := true
Short := false
Short
else
Long := false
Short := true
Short
//else if trading_setup == 'RSI_MACD'
//if _m > 0
//Long := true
//Short := false
//Short
//else
//Long := false
//Short := true
//Short
//else if trading_setup == 'Gaussian_Filter'
//if _g > 0
//Long := true
//Short := false
//Short
//else
//Long := false
//Short := true
//Short
else
Long := true
Short := true
Short
//Background Filling
//bgcolor(color = _fill and trading_setup == 'MA Cycle' ? _c > 0 ? color.new(color.blue, 80) : color.new(color.red, 80) : na, offset = 0)
//bgcolor(color = _fill_rsi_macd and trading_setup == 'RSI_MACD' ? _m > 0 ? color.new(color.blue, 80) : color.new(color.red, 80) : na, offset = 0)
//bgcolor(color = _fill_gf and trading_setup == 'Gaussian_Filter' ? _g > 0 ? color.new(color.blue, 80) : color.new(color.red, 80) : na, offset = 0)
isFractal(x) =>
ta.highestbars(x, Left + Right + 1) == -Right
sF = isFractal(-low)
support = low
support := sF ? low[Right] : support[1]
rF = isFractal(high)
resistance = high
resistance := rF ? high[Right] : resistance[1]
//plot(support, title="Support", color=sF ? #00000000 : color.blue, linewidth=2, offset=-Right)
//plot(resistance, title="Resistance", color=rF ? #00000000 : color.red, linewidth=2, offset=-Right)
//plotshape(sF ? low[Right] : na, title = 'Fractal Low', style = shape.circle, location = location.absolute, color = color.blue, offset = -Right, size = size.tiny)
//plotshape(rF ? high[Right] : na, title = 'Fractal High', style = shape.circle, location = location.absolute, color = color.red, offset = -Right, size = size.tiny)
//drawLabel(_offset, _pivot, _text, _style, _color, _textColor) =>
//if not na(_pivot)
//label.new(bar_index[_offset], _pivot, _text, style = _style, color = _color, textcolor = _textColor)
//label.new(bar_index[_offset], _pivot, _text+str.tostring(_pivot, format.mintick), style=_style, color=_color, textcolor=_textColor)
//drawLine(x1, y1, x2, y2, ext, clr, sty, wid) =>
//if not na(x1)
//line.new(x1, y1, x2, y2, xloc = xloc.bar_index, extend = ext, color = clr, style = sty, width = wid)
//Value & Index
ph = rF
ph_val = ta.valuewhen(ph, resistance, 0)
res = ph_val
ph_index = ta.valuewhen(ph, bar_index - Right, 0)
pl = sF
pl_val = ta.valuewhen(pl, support, 0)
sup = pl_val
pl_index = ta.valuewhen(pl, bar_index - Right, 0)
//Long setup
var long_sup_index = 0
long_sup_val = 0.0
long_res_val = 0.0
if pl_index < ph_index
long_sup_index := pl_index
long_sup_val := pl_val
long_res_val := ph_val
long_res_val
else
long_sup_index := long_sup_index[1]
long_sup_val := long_sup_val[1]
long_sup_val
if long_sup_index == long_sup_index[1]
long_res_val := long_res_val[1]
long_res_val
//Long Condition
long_cond = close > long_sup_val and Long
//Resistance Line
long_res_x1 = long_sup_index
long_res_y1 = long_cond ? long_res_val : na
long_res_x2 = bar_index
long_res_y2 = long_res_y1
long_res_ext = extend.right
long_res_clr = color.new(color.red, 0)
long_res_textColor = color.new(color.white, 0)
long_res_sty = line.style_dotted
long_res_width = 2
//long_res_line = drawLine(long_res_x1, long_res_y1, long_res_x2, long_res_y2, long_res_ext, long_res_clr, long_res_sty, long_res_width)
//line.delete(long_res_line[1])
//Label
//long_ph_lab = drawLabel(0, long_cond ? long_res_y1 : na, 'Break Even', label.style_label_left, color.red, color.white)
//label.delete(long_ph_lab[1])
//Value
plot(long_cond ? long_res_y1 : na, title = 'Long Arttır', color = color.new(color.red, 100))
//Support Line
long_sup_x1 = long_sup_index
long_sup_y1 = Long ? long_sup_val : na
long_sup_x2 = bar_index
long_sup_y2 = long_sup_y1
long_sup_ext = extend.right
long_sup_clr = color.new(color.blue, 0)
long_sup_textColor = color.new(color.white, 0)
long_sup_sty = line.style_dotted
long_sup_width = 2
//long_sup_line = drawLine(long_sup_x1, long_sup_y1, long_sup_x2, long_sup_y2, long_sup_ext, long_sup_clr, long_sup_sty, long_sup_width)
//line.delete(long_sup_line[1])
//Label
//long_pl_lab = drawLabel(0, Long ? long_sup_val : na, 'Long Invalidation', label.style_label_left, color.blue, color.white)
//label.delete(long_pl_lab[1])
//Value
plot(Long ? long_sup_val : na, title = 'Long DüşünME', color = color.new(color.blue, 100))
//Fib50 Line
long_fib50_x1 = long_sup_index
long_fib50_y1 = long_cond ? (long_res_y1 + long_sup_y1) * 0.5 : na
long_fib50_x2 = bar_index
long_fib50_y2 = long_fib50_y1
long_fib50_ext = extend.right
long_fib50_clr = color.new(color.blue, 0)
long_fib50_textColor = color.new(color.white, 0)
long_fib50_sty = line.style_dotted
long_fib50_width = 2
//long_fib50_line = drawLine(long_fib50_x1, long_fib50_y1, long_fib50_x2, long_fib50_y2, long_fib50_ext, long_fib50_clr, long_fib50_sty, long_fib50_width)
//line.delete(long_fib50_line[1])
//Label
//long_fib50_lab = drawLabel(0, long_cond ? long_fib50_y1 : na, 'Level 50', label.style_label_left, color.blue, color.white)
//label.delete(long_fib50_lab[1])
//Value
plot(long_cond ? long_fib50_y1 : na, title = 'Long Başla', color = color.new(color.blue, 100))
//Fib618 Line
long_fib618_x1 = long_sup_index
long_fib618_y1 = long_cond ? long_res_y1 - (long_res_y1 - long_sup_y1) * 0.618 : na
long_fib618_x2 = bar_index
long_fib618_y2 = long_fib618_y1
long_fib618_ext = extend.right
long_fib618_clr = color.new(color.blue, 0)
long_fib618_textColor = color.new(color.white, 0)
long_fib618_sty = line.style_dotted
long_fib618_width = 2
//long_fib618_line = drawLine(long_fib618_x1, long_fib618_y1, long_fib618_x2, long_fib618_y2, long_fib618_ext, long_fib618_clr, long_fib618_sty, long_fib618_width)
//line.delete(long_fib618_line[1])
//Label
//long_fib618_lab = drawLabel(0, long_cond ? long_fib618_y1 : na, 'Level 61.8', label.style_label_left, color.blue, color.white)
//label.delete(long_fib618_lab[1])
//Value
//plot(long_cond ? long_fib618_y1 : na, title = '61.8', color = color.new(color.blue, 100))
//tp1
long_tp1_x1 = long_sup_index
long_tp1_y1 = long_cond ? long_res_y1 + (long_res_y1 - long_sup_y1) * 0.382 : na
long_tp1_x2 = bar_index
long_tp1_y2 = long_tp1_y1
long_tp1_ext = extend.right
long_tp1_clr = color.new(color.blue, 0)
long_tp1_textColor = color.new(color.white, 0)
long_tp1_sty = line.style_dotted
long_tp1_width = 2
//long_tp1_line = drawLine(long_tp1_x1, long_tp1_y1, long_tp1_x2, long_tp1_y2, long_tp1_ext, long_tp1_clr, long_tp1_sty, long_tp1_width)
//line.delete(long_tp1_line[1])
//Label
//long_tp1_lab = drawLabel(0, long_cond ? long_tp1_y1 : na, 'Tp1', label.style_label_left, color.blue, color.white)
//label.delete(long_tp1_lab[1])
//Value
plot(long_cond ? long_tp1_y1 : na, title = 'Long Kapat', color = color.new(color.blue, 100))
//tp2
long_tp2_x1 = long_sup_index
long_tp2_y1 = long_cond ? long_res_y1 + long_res_y1 - long_sup_y1 : na
long_tp2_x2 = bar_index
long_tp2_y2 = long_tp2_y1
long_tp2_ext = extend.right
long_tp2_clr = color.new(color.blue, 0)
long_tp2_textColor = color.new(color.white, 0)
long_tp2_sty = line.style_dotted
long_tp2_width = 2
//long_tp2_line = drawLine(long_tp2_x1, long_tp2_y1, long_tp2_x2, long_tp2_y2, long_tp2_ext, long_tp2_clr, long_tp2_sty, long_tp2_width)
//line.delete(long_tp2_line[1])
//Label
//long_tp2_lab = drawLabel(0, long_cond ? long_tp2_y1 : na, 'Tp2', label.style_label_left, color.blue, color.white)
//label.delete(long_tp2_lab[1])
//Value
plot(long_cond ? long_tp2_y1 : na, title = 'Long Kesin Kapat', color = color.new(color.blue, 100))
//Buy Zone
//if long_cond
//linefill.new(long_fib50_line, long_sup_line, color.new(color.blue, 90))
//Short setup
var short_res_index = 0
short_res_val = 0.0
short_sup_val = 0.0
if pl_index > ph_index
short_res_index := ph_index
short_res_val := ph_val
short_sup_val := pl_val
short_sup_val
else
short_res_index := short_res_index[1]
short_res_val := short_res_val[1]
short_res_val
if short_res_index == short_res_index[1]
short_sup_val := short_sup_val[1]
short_sup_val
//Short Condition
short_cond = close < short_res_val and Short
//Resistance Line
short_res_x1 = short_res_index
short_res_y1 = Short ? short_res_val : na
short_res_x2 = bar_index
short_res_y2 = short_res_y1
short_res_ext = extend.right
short_res_clr = color.new(color.red, 0)
short_res_textColor = color.new(color.white, 0)
short_res_sty = line.style_dotted
short_res_width = 2
//short_res_line = drawLine(short_res_x1, short_res_y1, short_res_x2, short_res_y2, short_res_ext, short_res_clr, short_res_sty, short_res_width)
//line.delete(short_res_line[1])
//Label
//short_ph_lab = drawLabel(0, Short ? short_res_val : na, 'Short Invalidation', label.style_label_left, color.red, color.white)
//label.delete(short_ph_lab[1])
//Value
plot(Short ? short_res_val : na, title = 'Short DüşünME', color = color.new(color.red, 100))
//Support Line
short_sup_x1 = short_res_index
short_sup_y1 = short_cond ? short_sup_val : na
short_sup_x2 = bar_index
short_sup_y2 = short_sup_y1
short_sup_ext = extend.right
short_sup_clr = color.new(color.blue, 0)
short_sup_textColor = color.new(color.white, 0)
short_sup_sty = line.style_dotted
short_sup_width = 2
//short_sup_line = drawLine(short_sup_x1, short_sup_y1, short_sup_x2, short_sup_y2, short_sup_ext, short_sup_clr, short_sup_sty, short_sup_width)
//line.delete(short_sup_line[1])
//Label
//short_pl_lab = drawLabel(0, short_cond ? short_sup_y1 : na, 'Break Even', label.style_label_left, color.blue, color.white)
//label.delete(short_pl_lab[1])
//Value
plot(short_cond ? short_sup_y1 : na, title = 'Short Arttır', color = color.new(color.blue, 100))
//Fib50 Line
short_fib50_x1 = short_res_index
short_fib50_y1 = short_cond ? (short_res_y1 + short_sup_y1) * 0.5 : na
short_fib50_x2 = bar_index
short_fib50_y2 = short_fib50_y1
short_fib50_ext = extend.right
short_fib50_clr = color.new(color.red, 0)
short_fib50_textColor = color.new(color.white, 0)
short_fib50_sty = line.style_dotted
short_fib50_width = 2
//short_fib50_line = drawLine(short_fib50_x1, short_fib50_y1, short_fib50_x2, short_fib50_y2, short_fib50_ext, short_fib50_clr, short_fib50_sty, short_fib50_width)
//line.delete(short_fib50_line[1])
//Label
//short_fib50_lab = drawLabel(0, short_cond ? short_fib50_y1 : na, 'Level 50', label.style_label_left, color.red, color.white)
//label.delete(short_fib50_lab[1])
//Value
plot(short_cond ? short_fib50_y1 : na, title = 'Short Başla', color = color.new(color.red, 100))
//Fib618 Line
short_fib618_x1 = short_res_index
short_fib618_y1 = short_cond ? short_sup_y1 + (short_res_y1 - short_sup_y1) * 0.618 : na
short_fib618_x2 = bar_index
short_fib618_y2 = short_fib618_y1
short_fib618_ext = extend.right
short_fib618_clr = color.new(color.red, 0)
short_fib618_textColor = color.new(color.white, 0)
short_fib618_sty = line.style_dotted
short_fib618_width = 2
//short_fib618_line = drawLine(short_fib618_x1, short_fib618_y1, short_fib618_x2, short_fib618_y2, short_fib618_ext, short_fib618_clr, short_fib618_sty, short_fib618_width)
//line.delete(short_fib618_line[1])
//Label
//short_fib618_lab = drawLabel(0, short_cond ? short_fib618_y1 : na, 'Level 61.8', label.style_label_left, color.red, color.white)
//label.delete(short_fib618_lab[1])
//Value
//plot(short_cond ? short_fib618_y1 : na, title = '61.8', color = color.new(color.red, 100))
//tp1
short_tp1_x1 = short_res_index
short_tp1_y1 = short_cond ? short_sup_y1 - (short_res_y1 - short_sup_y1) * 0.382 : na
short_tp1_x2 = bar_index
short_tp1_y2 = short_tp1_y1
short_tp1_ext = extend.right
short_tp1_clr = color.new(color.red, 0)
short_tp1_textColor = color.new(color.white, 0)
short_tp1_sty = line.style_dotted
short_tp1_width = 2
//short_tp1_line = drawLine(short_tp1_x1, short_tp1_y1, short_tp1_x2, short_tp1_y2, short_tp1_ext, short_tp1_clr, short_tp1_sty, short_tp1_width)
//line.delete(short_tp1_line[1])
//Label
//short_tp1_lab = drawLabel(0, short_cond ? short_tp1_y1 : na, 'Tp1', label.style_label_left, color.red, color.white)
//label.delete(short_tp1_lab[1])
//Value
plot(short_cond ? short_tp1_y1 : na, title = 'Short Kapat', color = color.new(color.red, 100))
//tp2
short_tp2_x1 = short_res_index
short_tp2_y1 = short_cond ? short_sup_y1 - (short_res_y1 - short_sup_y1) : na
short_tp2_x2 = bar_index
short_tp2_y2 = short_tp2_y1
short_tp2_ext = extend.right
short_tp2_clr = color.new(color.red, 0)
short_tp2_textColor = color.new(color.white, 0)
short_tp2_sty = line.style_dotted
short_tp2_width = 2
//short_tp2_line = drawLine(short_tp2_x1, short_tp2_y1, short_tp2_x2, short_tp2_y2, short_tp2_ext, short_tp2_clr, short_tp2_sty, short_tp2_width)
//line.delete(short_tp2_line[1])
//Label
//short_tp2_lab = drawLabel(0, short_cond ? short_tp2_y1 : na, 'Tp2', label.style_label_left, color.red, color.white)
//label.delete(short_tp2_lab[1])
//Value
plot(short_cond ? short_tp2_y1 : na, title = 'Short Kesin Kapat', color = color.new(color.red, 100))
//Sell Zone
//if short_cond
//linefill.new(short_fib50_line, short_res_line, color.new(color.red, 90))
//Alert
//long_buy_zone = close < long_fib50_y1 and long_cond
//short_sell_zone = close > short_fib50_y1 and short_cond
//alertcondition(long_buy_zone or short_sell_zone, title = 'Alert active', message = 'Inside the zone')
//EOF
/// --------------------------------------------------------------------------------------------------------------------}
//
// --------------------------------------------------------------------------------------------------------------------{
bool trend_on = input.bool(true, "", inline = "trend", group = "Trend")
float trend_ = input.float(4, "Trend", step = 0.01, inline = "trend", group = "Trend")
color col1 = input.color(#26905d, "", inline = "trend", group = "Trend")
color col2 = input.color(#74286d, "",inline = "trend", group = "Trend")
int extend = input.int(15, "Extend", group = "Fibonacci", inline = "1"), fill_col = input.color(#2689901c, "", group = "Fibonacci", inline = "1")
float v_236 = input.float(0.236, "1")*100
float v_382 = input.float(0.382, "2")*100
float v_618 = input.float(0.618, "3")*100
float v_786 = input.float(0.786, "4")*100
// UDT
type data
line fib05 = na
line fib0 = na
line fib236 = na
line fib382 = na
line fib618 = na
line fib786 = na
line fib_ = na
line fib_di = na
label H = na
label L = na
label L0 = na
label L236 = na
label L382 = na
label L618 = na
label L786 = na
label L_ = na
var fib_d = data.new()
// --------------------------------------------------------------------------------------------------------------------}
//
// --------------------------------------------------------------------------------------------------------------------{
[supertrend, direction] = ta.supertrend(trend_, 25)
draw_fibb(trend)=>
var h = float(na)
var l = float(na)
var hi = int(na)
var li = int(na)
var val_0 = float(na)
var val_ = float(na)
atr = ta.atr(200)
// delete previous fibb
if trend != trend[1]
line.delete(fib_d.fib_)
line.delete(fib_d.fib0)
line.delete(fib_d.fib05)
line.delete(fib_d.fib_di)
line.delete(fib_d.fib236)
line.delete(fib_d.fib382)
line.delete(fib_d.fib618)
line.delete(fib_d.fib786)
label.delete(fib_d.H)
label.delete(fib_d.L)
label.delete(fib_d.L0)
label.delete(fib_d.L_)
label.delete(fib_d.L236)
label.delete(fib_d.L382)
label.delete(fib_d.L618)
label.delete(fib_d.L786)
// Creat Fib Lines at the bottom and the top
if trend != trend[1] and trend == -1
fib_d.fib_ := line.new(bar_index, low, bar_index, low, color = chart.fg_color, width = 2)
fib_d.fib0 := line.new(bar_index, high+atr*3, bar_index, high+atr*3, color = chart.fg_color, width = 2)
if trend != trend[1] and trend == 1
fib_d.fib_ := line.new(bar_index, high, bar_index, high, color = chart.fg_color, width = 2)
fib_d.fib0 := line.new(bar_index, low-atr*3, bar_index, low-atr*3, color = chart.fg_color, width = 2)
fib_d.fib_di := line.new(li, l, hi, h, style = line.style_dashed, color = chart.fg_color)
// Extend fibb lines during a trend
if trend == trend[1]
// Update High and low of Fibb
if low < fib_d.fib_.get_y1()
fib_d.fib_.set_y1(low)
fib_d.fib_.set_y2(low)
if high > fib_d.fib0.get_y1()
fib_d.fib0.set_y1(high)
fib_d.fib0.set_y2(high)
// High and low labels
//if high == fib_d.fib0.get_y1()
//h := high
//hi := bar_index
//label.delete((fib_d[1]).H)
//fib_d.H := label.new(hi, h, str.tostring(h, "#,###.####"), color = #15373b)
//if low == fib_d.fib_.get_y1()
//l := low
//li := bar_index
//label.delete((fib_d[1]).L)
//fib_d.L := label.new(li, l, str.tostring(l, "#,###.####"), style = label.style_label_up, color = #15373b)
//fib_d.fib_.set_x2(bar_index+extend)
//fib_d.fib0.set_x2(bar_index+extend)
//line.delete((fib_d[1]).fib_di)
//fib_d.fib_di := line.new(li, l, hi, h, style = line.style_dashed, color = chart.fg_color)
//if fib_d.fib_di.get_x1() < fib_d.fib0.get_x1() or fib_d.fib_di.get_x2() < fib_d.fib0.get_x1()
//line.delete(fib_d.fib_di)
//size_step = (fib_d.fib0.get_y1() - fib_d.fib_.get_y1()) / 100
//line.delete((fib_d[1]).fib05)
//line.delete((fib_d[1]).fib382)
//line.delete((fib_d[1]).fib236)
//line.delete((fib_d[1]).fib618)
//line.delete((fib_d[1]).fib786)
if trend == -1
val_0 := fib_d.fib0.get_y1()
val_ := fib_d.fib_.get_y1()
if trend == 1
val_0 := fib_d.fib_.get_y1()
val_ := fib_d.fib0.get_y1()
//fib_d.fib236 := line.new(fib_d.fib0.get_x1(), val_0 - size_step * v_236 * trend*-1, fib_d.fib0.get_x2(), val_0 - size_step * v_236 * trend*-1, color = chart.fg_color)
//fib_d.fib382 := line.new(fib_d.fib0.get_x1(), val_0 - size_step * v_382 * trend*-1, fib_d.fib0.get_x2(), val_0 - size_step * v_382 * trend*-1, color = chart.fg_color)
//fib_d.fib05 := line.new(fib_d.fib0.get_x1(), val_0 - size_step * 50 * trend*-1, fib_d.fib0.get_x2(), val_0 - size_step * 50 * trend*-1, color = color.new(chart.fg_color, 50), style = line.style_dotted)
//fib_d.fib618 := line.new(fib_d.fib0.get_x1(), val_0 - size_step * v_618 * trend*-1, fib_d.fib0.get_x2(), val_0 - size_step * v_618 * trend*-1, color = chart.fg_color)
//fib_d.fib786 := line.new(fib_d.fib0.get_x1(), val_0 - size_step * v_786 * trend*-1, fib_d.fib0.get_x2(), val_0 - size_step * v_786 * trend*-1, color = chart.fg_color)
//label.delete((fib_d[1]).L0)
//label.delete((fib_d[1]).L_)
//label.delete((fib_d[1]).L236)
//label.delete((fib_d[1]).L382)
//label.delete((fib_d[1]).L618)
//label.delete((fib_d[1]).L786)
//fib_d.L0 := label.new(bar_index+extend, val_0, text = "0 " + str.tostring(val_0, "(#,###.####)"), textcolor = chart.fg_color, color = chart.bg_color, style = label.style_label_left)
//fib_d.L_ := label.new(bar_index+extend, val_, text = "1 " + str.tostring(val_, "(#,###.####)"), textcolor = chart.fg_color, color = chart.bg_color, style = label.style_label_left)
//fib_d.L236 := label.new(bar_index+extend, fib_d.fib236.get_y1(), text = str.tostring(v_236/100) + str.tostring(fib_d.fib236.get_y1(), " (#,###.####)"), textcolor = chart.fg_color, color = chart.bg_color, style = label.style_label_left)
//fib_d.L382 := label.new(bar_index+extend, fib_d.fib382.get_y1(), text = str.tostring(v_382/100) + str.tostring(fib_d.fib382.get_y1(), " (#,###.####)"), textcolor = chart.fg_color, color = chart.bg_color, style = label.style_label_left)
//fib_d.L618 := label.new(bar_index+extend, fib_d.fib618.get_y1(), text = str.tostring(v_618/100) + str.tostring(fib_d.fib618.get_y1(), " (#,###.####)"), textcolor = chart.fg_color, color = chart.bg_color, style = label.style_label_left)
//fib_d.L786 := label.new(bar_index+extend, fib_d.fib786.get_y1(), text = str.tostring(v_786/100) + str.tostring(fib_d.fib786.get_y1(), " (#,###.####)"), textcolor = chart.fg_color, color = chart.bg_color, style = label.style_label_left)
//linefill.new(fib_d.fib618, fib_d.fib786, fill_col)
//linefill.new(fib_d.fib05, fib_d.fib786, fill_col)
// --------------------------------------------------------------------------------------------------------------------}
//
// --------------------------------------------------------------------------------------------------------------------{
draw_fibb(direction)
color = trend_on ? (direction == 1 ? col2 : col1) : na
p1 = plot(supertrend, "Trend", color = direction != direction[1] ? na : color, style = plot.style_linebr)
//p2 = plot(hl2, display = display.none)
//fill(p1, p2, hl2, supertrend, na, direction != direction[1] ? na : color.new(color, 90))
// --------------------------------------------------------------------------------------------------------------------}
// ============================================================================
// KAMA PARAMETERS
// ============================================================================
kama1_length = input.int(2, 'KAMA 1 Length', minval = 1, group = 'KAMA Settings')
kama1_fast = input.int(1, 'KAMA 1 Fast Length', minval = 1, group = 'KAMA Settings')
kama1_slow = input.int(3, 'KAMA 1 Slow Length', minval = 1, group = 'KAMA Settings')
kama2_length = input.int(3, 'KAMA 2 Length', minval = 1, group = 'KAMA Settings')
kama2_fast = input.int(2, 'KAMA 2 Fast Length', minval = 1, group = 'KAMA Settings')
kama2_slow = input.int(4, 'KAMA 2 Slow Length', minval = 1, group = 'KAMA Settings')
kama3_length = input.int(4, 'KAMA 3 Length', minval = 1, group = 'KAMA Settings')
kama3_fast = input.int(3, 'KAMA 3 Fast Length', minval = 1, group = 'KAMA Settings')
kama3_slow = input.int(5, 'KAMA 3 Slow Length', minval = 1, group = 'KAMA Settings')
kama4_length = input.int(5, 'KAMA 4 Length', minval = 1, group = 'KAMA Settings')
kama4_fast = input.int(4, 'KAMA 4 Fast Length', minval = 1, group = 'KAMA Settings')
kama4_slow = input.int(6, 'KAMA 4 Slow Length', minval = 1, group = 'KAMA Settings')
kama5_length = input.int(6, 'KAMA 5 Length', minval = 1, group = 'KAMA Settings')
kama5_fast = input.int(7, 'KAMA 5 Fast Length', minval = 1, group = 'KAMA Settings')
kama5_slow = input.int(8, 'KAMA 5 Slow Length', minval = 1, group = 'KAMA Settings')
src874 = input.source(close, 'Source', group = 'KAMA Settings')
// ============================================================================
// TREND COLORING PARAMETERS
// ============================================================================
color color_bearish_price_state = input.color(color.rgb(2, 243, 251), 'Bearish Trend', group = 'Colors')
color color_bullish_price_state = input.color(#f1f6f7, 'Bullish Trend', group = 'Colors')
color color_bullish_resistance_state = input.color(color.rgb(243, 3, 3, 52), 'Bullish Resistance', group = 'Colors')
color color_bearish_support_state = input.color(color.rgb(226, 247, 2, 52), 'Bearish Support', group = 'Colors')
float atr_multiplier_gray = input.float(14, 'ATR Multiplier (Gray Zone)', minval = 0.1, group = 'Ribbon Settings')
float atr_multiplier_yellow = input.float(14, 'ATR Multiplier (Yellow Zone)', minval = 0.1, group = 'Ribbon Settings')
// ============================================================================
// KAMA CALCULATION FUNCTION
// ============================================================================
f_kama(float src874, int length, int fastLength, int slowLength) =>
mom = math.abs(ta.change(src874, length))
volatility = math.sum(math.abs(ta.change(src874)), length)
er = volatility != 0 ? mom / volatility : 0
fastAlpha = 2 / (fastLength + 1)
slowAlpha = 2 / (slowLength + 1)
alpha = math.pow(er * (fastAlpha - slowAlpha) + slowAlpha, 2)
var float kama = na
kama := alpha * src874 + (1 - alpha) * nz(kama[1], src874)
kama
// ============================================================================
// CALCULATE ALL KAMAS
// ============================================================================
float kama1 = f_kama(src874, kama1_length, kama1_fast, kama1_slow)
float kama2 = f_kama(src874, kama2_length, kama2_fast, kama2_slow)
float kama3 = f_kama(src874, kama3_length, kama3_fast, kama3_slow)
float kama4 = f_kama(src874, kama4_length, kama4_fast, kama4_slow)
float kama5 = f_kama(src874, kama5_length, kama5_fast, kama5_slow)
// ============================================================================
// KAMA STACK RIBBON LOGIC (Replaces SMA Stack)
// ============================================================================
bool is_bullish_stack = kama1 > kama2 and kama2 > kama3 and kama3 > kama4 and kama4 > kama5
bool is_bearish_stack = kama1 < kama2 and kama2 < kama3 and kama3 < kama4 and kama4 < kama5
float atr_gray = ta.atr(14) * atr_multiplier_gray
float atr_yellow = ta.atr(14) * atr_multiplier_yellow
float kama_spread = math.abs(kama1 - kama5)
bool is_narrowing_gray = not is_bullish_stack and not is_bearish_stack and kama_spread < atr_gray
bool is_narrowing_yellow = not is_bullish_stack and not is_bearish_stack and kama_spread < atr_yellow
var bool was_bullish_stack = false
var bool was_bearish_stack = false
was_bullish_stack := is_bullish_stack ? true : is_bearish_stack ? false : was_bullish_stack
was_bearish_stack := is_bearish_stack ? true : is_bullish_stack ? false : was_bearish_stack
// ============================================================================
color kama_ribbon_color = is_bearish_stack ? color_bearish_price_state : is_narrowing_yellow and not was_bullish_stack ? color_bearish_support_state : is_narrowing_gray and was_bullish_stack ? color_bullish_resistance_state : is_bullish_stack ? color_bullish_price_state : na
// ============================================================================
plotcandle(open, high, low, close, color = kama_ribbon_color, wickcolor = kama_ribbon_color, bordercolor = kama_ribbon_color, title = 'MUM')
/////////////////////
// Only act after candle closes
isClosed = barstate.isconfirmed
// Your raw retracement rules
bullRaw = isClosed and close[1] < open[1] and close < open and close < low[1]
bearRaw = isClosed and close[1] > open[1] and close > open and close > high[1]
// Small wick-based spacing
spaceUp = (high - close) * 0.35
spaceDown = (open - low) * 0.35
// Colors
brightRed = color.rgb(255, 0, 0)
brightGreen = color.rgb(0, 255, 0)
// Wave locks
var bool bullWaveLocked = false
var bool bearWaveLocked = false
// Reset locks when opposite candle prints
if isClosed and close > open
bullWaveLocked := false
bullWaveLocked
if isClosed and close < open
bearWaveLocked := false
bearWaveLocked
// BEARISH WAVE (Red)
if bullRaw and not bullWaveLocked
label.new(bar_index - 1, high[1] + (high[1] - close[1]) * 0.35, 'L', style = label.style_none, textcolor = brightRed, size = size.large)
label.new(bar_index, high + spaceUp, 'o', style = label.style_none, textcolor = brightRed, size = size.large)
bullWaveLocked := true
bullWaveLocked
// BULLISH WAVE (Green)
if bearRaw and not bearWaveLocked
label.new(bar_index - 1, low[1] - (open[1] - low[1]) * 0.35, 'L', style = label.style_none, textcolor = brightGreen, size = size.large)
label.new(bar_index, low - spaceDown, 'o', style = label.style_none, textcolor = brightGreen, size = size.large)
bearWaveLocked := true
bearWaveLocked
/////////////////////////
örnek
Yer İmleri