Untitled
unknown
plain_text
5 months ago
5.1 kB
25
Indexable
//@version=5 indicator("XU100 Korelasyon Tablosu", overlay=false) // Korelasyon periyodu için input corrPeriod = input.int(100, "Korelasyon Periyodu", minval=1) // XU100 SMA hesaplaması xu100Price = request.security("BIST:XU100", timeframe.period, close) xu100Sma = ta.sma(xu100Price, corrPeriod) xu100Dev = xu100Price - xu100Sma // Her hisse için ayrı security çağrısı ve korelasyon hesaplaması akbnk = request.security("BIST:AKBNK", timeframe.period, close) akbnkCorr = ta.correlation(akbnk - ta.sma(akbnk, corrPeriod), xu100Dev, corrPeriod) arclk = request.security("BIST:ARCLK", timeframe.period, close) arclkCorr = ta.correlation(arclk - ta.sma(arclk, corrPeriod), xu100Dev, corrPeriod) asels = request.security("BIST:ASELS", timeframe.period, close) aselsCorr = ta.correlation(asels - ta.sma(asels, corrPeriod), xu100Dev, corrPeriod) bimas = request.security("BIST:BIMAS", timeframe.period, close) bimasCorr = ta.correlation(bimas - ta.sma(bimas, corrPeriod), xu100Dev, corrPeriod) ekgyo = request.security("BIST:EKGYO", timeframe.period, close) ekgyoCorr = ta.correlation(ekgyo - ta.sma(ekgyo, corrPeriod), xu100Dev, corrPeriod) eregl = request.security("BIST:EREGL", timeframe.period, close) ereglCorr = ta.correlation(eregl - ta.sma(eregl, corrPeriod), xu100Dev, corrPeriod) garan = request.security("BIST:GARAN", timeframe.period, close) garanCorr = ta.correlation(garan - ta.sma(garan, corrPeriod), xu100Dev, corrPeriod) hekts = request.security("BIST:HEKTS", timeframe.period, close) hektsCorr = ta.correlation(hekts - ta.sma(hekts, corrPeriod), xu100Dev, corrPeriod) kchol = request.security("BIST:KCHOL", timeframe.period, close) kcholCorr = ta.correlation(kchol - ta.sma(kchol, corrPeriod), xu100Dev, corrPeriod) kozal = request.security("BIST:KOZAL", timeframe.period, close) kozalCorr = ta.correlation(kozal - ta.sma(kozal, corrPeriod), xu100Dev, corrPeriod) // Korelasyon değerlerini array'e at var correlations = array.new_float(10, 0.0) var symbols = array.new_string(10, "") if barstate.islast // Array'leri doldur array.set(correlations, 0, akbnkCorr) array.set(correlations, 1, arclkCorr) array.set(correlations, 2, aselsCorr) array.set(correlations, 3, bimasCorr) array.set(correlations, 4, ekgyoCorr) array.set(correlations, 5, ereglCorr) array.set(correlations, 6, garanCorr) array.set(correlations, 7, hektsCorr) array.set(correlations, 8, kcholCorr) array.set(correlations, 9, kozalCorr) array.set(symbols, 0, "AKBNK") array.set(symbols, 1, "ARCLK") array.set(symbols, 2, "ASELS") array.set(symbols, 3, "BIMAS") array.set(symbols, 4, "EKGYO") array.set(symbols, 5, "EREGL") array.set(symbols, 6, "GARAN") array.set(symbols, 7, "HEKTS") array.set(symbols, 8, "KCHOL") array.set(symbols, 9, "KOZAL") // Tablo oluştur var korelasyonTable = table.new(position.top_right, columns=2, rows=11, bgcolor=color.rgb(0, 0, 0, 20), border_width=1) // Tabloyu güncelle if barstate.islast // Başlık satırı table.cell(korelasyonTable, 0, 0, "Hisse", bgcolor=color.rgb(0, 0, 0, 90), text_color=color.white, text_halign=text.align_center) table.cell(korelasyonTable, 1, 0, "Korelasyon", bgcolor=color.rgb(0, 0, 0, 90), text_color=color.white, text_halign=text.align_center) // Sıralama için indeks array'i var int[] sortedIndices = array.new_int(10, 0) for i = 0 to 9 array.set(sortedIndices, i, i) // Bubble sort - büyükten küçüğe sırala for i = 0 to 8 for j = 0 to 8 - i if array.get(correlations, array.get(sortedIndices, j)) < array.get(correlations, array.get(sortedIndices, j + 1)) temp = array.get(sortedIndices, j) array.set(sortedIndices, j, array.get(sortedIndices, j + 1)) array.set(sortedIndices, j + 1, temp) // Tabloyu doldur for i = 0 to 9 idx = array.get(sortedIndices, i) corrValue = array.get(correlations, idx) // Renk belirleme cellColor = corrValue >= 0.8 ? color.rgb(0, 255, 0, 80) : corrValue >= 0.6 ? color.rgb(0, 255, 0, 60) : corrValue >= 0.4 ? color.rgb(255, 255, 0, 60) : corrValue >= 0.2 ? color.rgb(255, 165, 0, 60) : color.rgb(255, 0, 0, 60) // Hisse adı hücresi table.cell(korelasyonTable, 0, i + 1, text=array.get(symbols, idx), bgcolor=color.rgb(0, 0, 0, 50), text_color=color.white, text_halign=text.align_left) // Korelasyon değeri hücresi table.cell(korelasyonTable, 1, i + 1, text=str.tostring(corrValue, "#.###"), bgcolor=cellColor, text_color=color.white, text_halign=text.align_right)
Editor is loading...
Leave a Comment