PHP Code:
//@version=5
indicator(" [ICS 21 Bulutu]", overlay=true, max_boxes_count=500, max_lines_count=500)
// ========================================================================= //
// =============================== GÝRDÝLER ================================ //
// ========================================================================= //
grp_pos = "PENCERE AYARLARI"
i_width = input.int(45, "Grafik Geniþliði", group=grp_pos)
i_offset = input.int(5, "Yatay Uzaklýk", group=grp_pos)
i_gapX = input.int(10, "Yatay Boþluk", group=grp_pos)
i_vScale = input.float(35.0, "Dikey Ölçekleme", group=grp_pos, step=0.1)
i_vBuffer = input.float(0.02, "Dikey Tampon (%)", group=grp_pos, step=0.01)
tf1 = input.timeframe("5", "Periyot 1", group="ZAMAN DÝLÝMLERÝ")
tf2 = input.timeframe("15", "Periyot 2", group="ZAMAN DÝLÝMLERÝ")
tf3 = input.timeframe("60", "Periyot 3", group="ZAMAN DÝLÝMLERÝ")
tf4 = input.timeframe("240", "Periyot 4", group="ZAMAN DÝLÝMLERÝ")
c_up = input.color(color.new(#00e676, 0), "Yükseliþ Mumu", group="RENKLER")
c_down = input.color(color.new(#ff1744, 0), "Düþüþ Mumu", group="RENKLER")
c_bg = input.color(color.new(#1a1a1a, 85), "Arka Plan", group="RENKLER")
c_border = input.color(color.new(#ffffff, 80), "Çerçeve", group="RENKLER")
c_fillUp = input.color(color.new(#26a69a, 80), "Yükseliþ Bulutu", group="BULUT RENKLERÝ")
c_fillDn = input.color(color.new(#ef5350, 80), "Düþüþ Bulutu", group="BULUT RENKLERÝ")
c_fillRng = input.color(color.new(#888888, 80), "Yatay Bulut", group="BULUT RENKLERÝ")
// ========================================================================= //
// ================== ICS 21 MATEMATÝÐÝ (DÝZÝLERDEN ARINDIRILMIÞ) ========== //
// ========================================================================= //
f_yz_sigma(len) =>
float _yzOR = math.log(open / nz(close[1], open))
float _yzCO = math.log(close / open)
float _yzHO = math.log(high / open)
float _yzHC = math.log(high / close)
float _yzLO = math.log(low / open)
float _yzLC = math.log(low / close)
float _sqOR = ta.variance(_yzOR, len)
float _sqCO = ta.variance(_yzCO, len)
float _sqRS = ta.sma(_yzHO * _yzHC + _yzLO * _yzLC, len)
float _k = 0.34 / (1.34 + (len + 1.0) / math.max(len - 1.0, 1.0))
float _sq = nz(_sqOR) + _k * nz(_sqCO) + (1.0 - _k) * nz(_sqRS)
math.max(math.sqrt(math.max(_sq, 0.0)), 1e-10)
f_icsLine(p1, x1, p2, x2, targetX, sig) =>
float out = p1
if x1 != x2 and p1 > 0 and p2 > 0 and sig > 1e-10
float y1 = math.log(p1) / sig
float y2 = math.log(p2) / sig
float yT = y1 + (y2 - y1) * (targetX - x1) / (x2 - x1)
out := math.exp(yT * sig)
out
f_icsAngle(p1, x1, p2, x2, sig) =>
float out = 0.0
if x1 != x2 and p1 > 0 and p2 > 0 and sig > 1e-10
float y1 = math.log(p1) / sig
float y2 = math.log(p2) / sig
out := math.atan((y2 - y1) / (x2 - x1)) * 180.0 / math.pi
out
// Nativ ICS hesaplayýcýsý (Çökmeyi engellemek için array kullanmaz)
f_ics_calc() =>
int P = 21
float sig = f_yz_sigma(20)
float h0 = ta.highest(high, P), float l0 = ta.lowest(low, P)
// Yeterli bar yoksa doðrudan fiyatý döndür
if bar_index < P * 5
[h0, l0, 0.0]
else
float h1 = h0[P], float l1 = l0[P]
float h2 = h0[P*2], float l2 = l0[P*2]
float h3 = h0[P*3], float l3 = l0[P*3]
float h4 = h0[P*4], float l4 = l0[P*4]
float g0 = (h0 > 0 and l0 > 0) ? math.exp((math.log(h0) + math.log(l0)) / 2.0) : na
float g1 = (h1 > 0 and l1 > 0) ? math.exp((math.log(h1) + math.log(l1)) / 2.0) : na
float g2 = (h2 > 0 and l2 > 0) ? math.exp((math.log(h2) + math.log(l2)) / 2.0) : na
float g3 = (h3 > 0 and l3 > 0) ? math.exp((math.log(h3) + math.log(l3)) / 2.0) : na
float g4 = (h4 > 0 and l4 > 0) ? math.exp((math.log(h4) + math.log(l4)) / 2.0) : na
int pd = g0 > g1 ? 1 : -1
int seg = 1
if g0 != g1
if (g1 > g2 ? 1 : (g1 < g2 ? -1 : 0)) == pd
seg := 2
if (g2 > g3 ? 1 : (g2 < g3 ? -1 : 0)) == pd
seg := 3
if (g3 > g4 ? 1 : (g3 < g4 ? -1 : 0)) == pd
seg := 4
int cx0 = int(-P/2), int cx1 = cx0 - P, int cx2 = cx1 - P, int cx3 = cx2 - P, int cx4 = cx3 - P
float fHH = h0, float fLH = h0, float fHL = l0, float fLL = l0
int xHH = cx0, int xLH = cx0, int xHL = cx0, int xLL = cx0
if seg >= 1
if h1 > fHH
fHH := h1, xHH := cx1
if h1 < fLH
fLH := h1, xLH := cx1
if l1 > fHL
fHL := l1, xHL := cx1
if l1 < fLL
fLL := l1, xLL := cx1
if seg >= 2
if h2 > fHH
fHH := h2, xHH := cx2
if h2 < fLH
fLH := h2, xLH := cx2
if l2 > fHL
fHL := l2, xHL := cx2
if l2 < fLL
fLL := l2, xLL := cx2
if seg >= 3
if h3 > fHH
fHH := h3, xHH := cx3
if h3 < fLH
fLH := h3, xLH := cx3
if l3 > fHL
fHL := l3, xHL := cx3
if l3 < fLL
fLL := l3, xLL := cx3
if seg >= 4
if h4 > fHH
fHH := h4, xHH := cx4
if h4 < fLH
fLH := h4, xLH := cx4
if l4 > fHL
fHL := l4, xHL := cx4
if l4 < fLL
fLL := l4, xLL := cx4
int sLx = seg == 1 ? cx1 : seg == 2 ? cx2 : seg == 3 ? cx3 : cx4
int sRx = cx0
float endG = seg == 1 ? g1 : seg == 2 ? g2 : seg == 3 ? g3 : g4
float ang = f_icsAngle(endG, sLx, g0, sRx, sig)
int dir = math.abs(ang) <= 0.5 ? 0 : pd
float uY1 = fHH, float uY2 = fHH, float lY1 = fLL, float lY2 = fLL
if dir == 1
uY1 := f_icsLine(fLH, xLH, fHH, xHH, sLx, sig), uY2 := f_icsLine(fLH, xLH, fHH, xHH, sRx, sig)
lY1 := f_icsLine(fLL, xLL, fHL, xHL, sLx, sig), lY2 := f_icsLine(fLL, xLL, fHL, xHL, sRx, sig)
else if dir == -1
uY1 := f_icsLine(fHH, xHH, fLH, xLH, sLx, sig), uY2 := f_icsLine(fHH, xHH, fLH, xLH, sRx, sig)
lY1 := f_icsLine(fHL, xHL, fLL, xLL, sLx, sig), lY2 := f_icsLine(fHL, xHL, fLL, xLL, sRx, sig)
float uYa = f_icsLine(uY1, sLx, uY2, sRx, 0, sig)
float lYa = f_icsLine(lY1, sLx, lY2, sRx, 0, sig)
[uYa, lYa, float(dir)]
// ========================================================================= //
// =================== HTF (BÜYÜK ZAMAN) VERÝ PAKETLEYÝCÝ ================== //
// ========================================================================= //
// 15 mumluk veriyi çökmeyi engelleyecek þekilde sabit statik dizilere paketliyoruz.
f_veri_paketi() =>
o_arr = array.new_float(15, na), h_arr = array.new_float(15, na), l_arr = array.new_float(15, na), c_arr = array.new_float(15, na)
u_arr = array.new_float(15, na), dn_arr = array.new_float(15, na), dir_arr = array.new_float(15, na)
[u, dn, dir] = f_ics_calc()
for i = 0 to 14
array.set(o_arr, i, open[i])
array.set(h_arr, i, high[i])
array.set(l_arr, i, low[i])
array.set(c_arr, i, close[i])
array.set(u_arr, i, u[i])
array.set(dn_arr, i, dn[i])
array.set(dir_arr, i, dir[i])
[o_arr, h_arr, l_arr, c_arr, u_arr, dn_arr, dir_arr]
[o1, h1, l1, c1, u1, dn1, dir1] = request.security(syminfo.tickerid, tf1, f_veri_paketi())
[o2, h2, l2, c2, u2, dn2, dir2] = request.security(syminfo.tickerid, tf2, f_veri_paketi())
[o3, h3, l3, c3, u3, dn3, dir3] = request.security(syminfo.tickerid, tf3, f_veri_paketi())
[o4, h4, l4, c4, u4, dn4, dir4] = request.security(syminfo.tickerid, tf4, f_veri_paketi())
// ========================================================================= //
// =========================== ÇÝZÝM MOTORU ================================ //
// ========================================================================= //
var box[] kutu_bg = array.new_box()
var box[] kutu_bulut = array.new_box()
var box[] kutu_mum = array.new_box()
var line[] cizgi_mum = array.new_line()
f_temizle() =>
for b in kutu_bg
box.delete(b)
for b in kutu_bulut
box.delete(b)
for b in kutu_mum
box.delete(b)
for l in cizgi_mum
line.delete(l)
array.clear(kutu_bg), array.clear(kutu_bulut), array.clear(kutu_mum), array.clear(cizgi_mum)
f_isim_ver(tf) =>
float num = str.tonumber(tf)
string res = tf
if not na(num)
res := num >= 60 ? str.tostring(int(num / 60)) + "S" : str.tostring(int(num)) + "D"
else
res := tf == "D" ? "GÜN" : tf == "W" ? "HFT" : tf
res
f_mini_grafik_ciz(o_arr, h_arr, l_arr, c_arr, u_arr, dn_arr, dir_arr, tf_label, level) =>
if array.size(c_arr) > 0 and not na(array.get(c_arr, 0))
float max_h = array.max(h_arr)
float min_l = array.min(l_arr)
// Bulut sýnýrlarýný da kutu dýþýna taþmamasý için kontrol ediyoruz
for i = 0 to 14
float u_val = array.get(u_arr, i)
float l_val = array.get(dn_arr, i)
if not na(u_val)
max_h := math.max(max_h, u_val), min_l := math.min(min_l, u_val)
if not na(l_val)
max_h := math.max(max_h, l_val), min_l := math.min(min_l, l_val)
float hv = ta.highest(high, 300)
float lv = ta.lowest(low, 300)
float cr = hv - lv == 0 ? syminfo.mintick * 100 : hv - lv
float my = (hv + lv) / 2
float er = cr * i_vScale
int col_idx = level % 2
int row_idx = int(level / 2)
float row_gap = er * i_vBuffer
float bh = (er - row_gap * 2) / 3
float start_y = my + er / 2
float top_y = start_y - row_idx * (bh + row_gap)
float bot_y = top_y - bh
int start_x = bar_index + i_offset + col_idx * (i_width + i_gapX)
int end_x = start_x + i_width
float itop = top_y - bh * 0.02
float ibot = bot_y + bh * 0.02
float ir = itop - ibot
float hr = max_h - min_l == 0 ? syminfo.mintick : max_h - min_l
// 1. EKRAN ARKA PLANI
box arka_plan = box.new(start_x, top_y, end_x, bot_y, border_color=c_border, bgcolor=c_bg)
box.set_text(arka_plan, f_isim_ver(tf_label))
box.set_text_color(arka_plan, color.gray)
box.set_text_halign(arka_plan, text.align_center)
box.set_text_valign(arka_plan, text.align_bottom)
box.set_text_size(arka_plan, size.small)
array.push(kutu_bg, arka_plan)
float bs = float(i_width) / 15
int box_w = math.max(1, int(bs / 2))
for i = 0 to 14
int idx = 14 - i
float _o = array.get(o_arr, idx)
float _h = array.get(h_arr, idx)
float _l = array.get(l_arr, idx)
float _c = array.get(c_arr, idx)
float u_val = array.get(u_arr, idx)
float l_val = array.get(dn_arr, idx)
float d_val = array.get(dir_arr, idx)
float so = ibot + ((_o - min_l) / hr) * ir
float sh = ibot + ((_h - min_l) / hr) * ir
float sl = ibot + ((_l - min_l) / hr) * ir
float sc = ibot + ((_c - min_l) / hr) * ir
int xp = end_x - int(i * bs)
color col = _c >= _o ? c_up : c_down
// 2. BULUT DOLGUSU (Mumlarýn arkasýnda kalmasý için önce çizilir)
if not na(u_val) and not na(l_val)
float sy_u = ibot + ((u_val - min_l) / hr) * ir
float sy_l = ibot + ((l_val - min_l) / hr) * ir
color cCloud = d_val == 1 ? c_fillUp : d_val == -1 ? c_fillDn : c_fillRng
// Bulut dolgusu efekti vermek için her bara þeffaf bir kutu çiziyoruz
array.push(kutu_bulut, box.new(xp - box_w, sy_u, xp + box_w, sy_l, bgcolor=cCloud, border_color=na))
// 3. MUMLAR (Bulutun üstüne çizilir)
array.push(cizgi_mum, line.new(xp, sh, xp, sl, color=col))
array.push(kutu_mum, box.new(xp - 1, so, xp + 1, sc, border_color=col, bgcolor=col))
if barstate.islast
f_temizle()
f_mini_grafik_ciz(o1, h1, l1, c1, u1, dn1, dir1, tf1, 0)
f_mini_grafik_ciz(o2, h2, l2, c2, u2, dn2, dir2, tf2, 1)
f_mini_grafik_ciz(o3, h3, l3, c3, u3, dn3, dir3, tf3, 2)
f_mini_grafik_ciz(o4, h4, l4, c4, u4, dn4, dir4, tf4, 3)
denemek ve geliþtirmek isteyene...
Yer Ýmleri