Untitled

 avatar
unknown
plain_text
4 months ago
11 kB
71
Indexable
//@version=5
indicator('Agirlikli MA ve Mtf Tablo', overlay = true)

// Bant genişliğini yüzde olarak belirlemek için input
band_genisligi_yuzde = input.float(1.0, title = 'Bant Genişliği (%)', minval = 0.01, step = 0.01)

// Kullanıcının kaç bar geriye bakacağını belirleyebileceği input
lookback = input.int(377, title = 'Geriye Bakılacak Bar Sayısı', minval = 1)



// Temasları saymak için fonksiyon (hem low hem de high değerlerini kullanarak)
temasSay(src, geriye_bak) =>
    var float toplam_temas = 0.0
    // Bant genişliği hesaplama
    band_genisligi = band_genisligi_yuzde / 100 * src
    // Eğer low veya high değeri src'nin bandı içindeyse temas say
    temas = low <= src + band_genisligi and low >= src - band_genisligi or high <= src + band_genisligi and high >= src - band_genisligi ? 1 : 0
    toplam_temas := toplam_temas + temas
    bar_index >= geriye_bak ? toplam_temas - nz(toplam_temas[geriye_bak]) : na

//--------------------------------------------------------------------------------------------------------------------------
src1 = input.source(close, title = 'KAYNAK', group = 'HAREKETLİ ORTALAMA 1 AYARLAR')
period1 = input.int(defval = 13, title = 'Hareketli Ortalama 1 Period', minval = 0, step = 1, group = 'HAREKETLİ ORTALAMA 1 AYARLAR')
mastring1 = input.string(defval = 'VWMA', title = 'Hareketli Ortalama MA Type', options = ['RMA', 'SMA', 'EMA', 'VWMA', 'WMA', 'TMA', 'HullMA', 'VAR', 'dEMA', 'ALMA'], group = 'HAREKETLİ ORTALAMA 1 AYARLAR')

//--------------------------------------------------------------------------------------------------------------------------
src2 = input.source(close, title = 'KAYNAK', group = 'HAREKETLİ ORTALAMA 2 AYARLAR')
period2 = input.int(defval = 21, title = 'Hareketli Ortalama 2 Period', minval = 0, step = 1, group = 'HAREKETLİ ORTALAMA 2 AYARLAR')
mastring2 = input.string(defval = 'VWMA', title = 'Hareketli Ortalama MA Type', options = ['RMA', 'SMA', 'EMA', 'VWMA', 'WMA', 'TMA', 'HullMA', 'VAR', 'dEMA', 'ALMA'], group = 'HAREKETLİ ORTALAMA 2 AYARLAR')

//--------------------------------------------------------------------------------------------------------------------------
src3 = input.source(close, title = 'KAYNAK', group = 'HAREKETLİ ORTALAMA 3 AYARLAR')
period3 = input.int(defval = 34, title = 'Hareketli Ortalama 3 Period', minval = 0, step = 1, group = 'HAREKETLİ ORTALAMA 3 AYARLAR')
mastring3 = input.string(defval = 'VWMA', title = 'Hareketli Ortalama MA Type', options = ['RMA', 'SMA', 'EMA', 'VWMA', 'WMA', 'TMA', 'HullMA', 'VAR', 'dEMA', 'ALMA'], group = 'HAREKETLİ ORTALAMA 3 AYARLAR')

//--------------------------------------------------------------------------------------------------------------------------
src4 = input.source(close, title = 'KAYNAK', group = 'HAREKETLİ ORTALAMA 4 AYARLAR')
period4 = input.int(defval = 55, title = 'Hareketli Ortalama 4 Period', minval = 0, step = 1, group = 'HAREKETLİ ORTALAMA 4 AYARLAR')
mastring4 = input.string(defval = 'VWMA', title = 'Hareketli Ortalama MA Type', options = ['RMA', 'SMA', 'EMA', 'VWMA', 'WMA', 'TMA', 'HullMA', 'VAR', 'dEMA', 'ALMA'], group = 'HAREKETLİ ORTALAMA 4 AYARLAR')

//--------------------------------------------------------------------------------------------------------------------------
src5 = input.source(close, title = 'KAYNAK', group = 'HAREKETLİ ORTALAMA 5 AYARLAR')
period5 = input.int(defval = 89, title = 'Hareketli Ortalama 5 Period', minval = 0, step = 1, group = 'HAREKETLİ ORTALAMA 5 AYARLAR')
mastring5 = input.string(defval = 'VWMA', title = 'Hareketli Ortalama MA Type', options = ['RMA', 'SMA', 'EMA', 'VWMA', 'WMA', 'TMA', 'HullMA', 'VAR', 'dEMA', 'ALMA'], group = 'HAREKETLİ ORTALAMA 5 AYARLAR')

//--------------------------------------------------------------------------------------------------------------------------
src6 = input.source(close, title = 'KAYNAK', group = 'HAREKETLİ ORTALAMA 6 AYARLAR')
period6 = input.int(defval = 144, title = 'Hareketli Ortalama 6 Period', minval = 0, step = 1, group = 'HAREKETLİ ORTALAMA 6 AYARLAR')
mastring6 = input.string(defval = 'VWMA', title = 'Hareketli Ortalama MA Type', options = ['RMA', 'SMA', 'EMA', 'VWMA', 'WMA', 'TMA', 'HullMA', 'VAR', 'dEMA', 'ALMA'], group = 'HAREKETLİ ORTALAMA 6 AYARLAR')

// ╠════════════════════ HAREKETLİ ORTALAMA FONKSİYONLARI ═════════════════════╣

f_var(src, period) =>
    valpha = 2 / (period + 1)
    vud = src > src[1] ? src - src[1] : 0
    vdd = src < src[1] ? src[1] - src : 0
    vUD = math.sum(vud, 9)
    vDD = math.sum(vdd, 9)
    vCMO = nz((vUD - vDD) / (vUD + vDD))
    VAR = 0.0
    VAR := nz(valpha * math.abs(vCMO) * src) + (1 - valpha * math.abs(vCMO)) * nz(VAR[1])
    VAR
    //

f_tma(src, period) =>
    TMA = ta.sma(ta.sma(src, math.ceil(period / 2)), math.floor(period / 2) + 1)
    TMA
    //

f_dema(src, period) =>
    DEMA = 2 * ta.ema(src, period) - ta.ema(ta.ema(src, period), period)
    DEMA
    //

f_alma(src, period) =>
    ALMA = ta.alma(src, period, 0.95, 6)
    ALMA
    //

// ╠════════════════════════════ SONUÇ FONKSİYONU ═════════════════════════════╣


f_ortalama(src, period, ortalama_turu) =>
    sonuc = ortalama_turu == 'RMA' ? ta.rma(src, period) : ortalama_turu == 'SMA' ? ta.sma(src, period) : ortalama_turu == 'EMA' ? ta.ema(src, period) : ortalama_turu == 'VWMA' ? ta.vwma(src, period) : ortalama_turu == 'WMA' ? ta.wma(src, period) : ortalama_turu == 'HullMA' ? ta.hma(src, period) : ortalama_turu == 'TMA' ? f_tma(src, period) : ortalama_turu == 'VAR' ? f_var(src, period) : ortalama_turu == 'dEMA' ? f_dema(src, period) : ortalama_turu == 'ALMA' ? f_alma(src, period) : na
    sonuc
    //

// ╠════════════════════════════════ SONUÇLAR ═════════════════════════════════╣

ma1 = f_ortalama(src1, period1, mastring1)
ma2 = f_ortalama(src2, period2, mastring2)
ma3 = f_ortalama(src3, period3, mastring3)
ma4 = f_ortalama(src4, period4, mastring4)
ma5 = f_ortalama(src5, period5, mastring5)
ma6 = f_ortalama(src6, period6, mastring6)



// Kullanıcının belirlediği bar sayısına göre her EMA için temasları say
temas1 = temasSay(src1, lookback)
temas2 = temasSay(src2, lookback)
temas3 = temasSay(src3, lookback)
temas4 = temasSay(src4, lookback)
temas5 = temasSay(src5, lookback)
temas6 = temasSay(src6, lookback)

// Toplam temasları hesapla
toplam_temas = temas1 + temas2 + temas3 + temas4 + temas5 + temas6

// Sıfıra bölmeyi önlemek için kontrol
toplam_temas := toplam_temas == 0 ? 1 : toplam_temas

// Temaslara göre ağırlıkları hesapla
a1 = temas1 / toplam_temas
a2 = temas2 / toplam_temas
a3 = temas3 / toplam_temas
a4 = temas4 / toplam_temas
a5 = temas5 / toplam_temas
a6 = temas6 / toplam_temas

// Ağırlıklı MA'yı hesapla
agirlikli_ma = a1 * ma1 + a2 * ma2 + a3 * ma3 + a4 * ma4 + a5 * ma5 + a6 * ma6

// Ağırlıklı EMA'yı çiz
plot(agirlikli_ma, color = color.yellow, title = 'Optimize MA')

// Bant genişliğini hesapla ve bantları çiz
band_genisligi = band_genisligi_yuzde / 100 * agirlikli_ma
ust_band = agirlikli_ma + band_genisligi
alt_band = agirlikli_ma - band_genisligi

// Bantları çiz
p1 = plot(ust_band, color = color.blue, title = 'Üst Band')
p2 = plot(alt_band, color = color.blue, title = 'Alt Band')

// Bantların arasını doldur
fill(p1, p2, color = color.new(color.blue, 90))


// Alarm ----------------------------------------------------------------
alertcondition(close > ust_band, title = 'HO Long', message = 'Hareketli Ortalama Long')
alertcondition(close < alt_band, title = 'HO Short', message = 'Hareketli Ortalama Short')

// Arka Plan ve Renk Ayarları
gr6 = 'Tablo ArkaPlan Rengi'
dashColor = input.color(color.new(#00b2ff, 100), 'Renk ve Kontrast', group = gr6, inline = '3')

// İstatistik Tablosu
Group1 = 'HO Trend Tablo'
TikTab = input(true, 'HO Trend Tablo', group = Group1)

times1 = input.timeframe('15', 'Zaman Dilimi - A', group = Group1)
times2 = input.timeframe('60', 'Zaman Dilimi - B', group = Group1)
times3 = input.timeframe('120', 'Zaman Dilimi - C', group = Group1)
times4 = input.timeframe('240', 'Zaman Dilimi - D', group = Group1)
times5 = input.timeframe('D', 'Zaman Dilimi  - E', group = Group1)
times6 = input.timeframe('W', 'Zaman Dilimi  - F', group = Group1)

TablePos = input.string('Sağ Yukarı', 'Tablo Pozisyonu', ['Sağ Yukarı', 'Sağ Orta', 'Sol Alt', 'Sağ Alt'], group = Group1)
TablePosTextCol = input.color(color.white, 'Text', inline = '1', group = Group1)
TextSize1 = input.string('Normal', 'Tablo Yazı Büyüklüğü', ['Normal', 'Küçük', 'Büyük'], group = Group1)
textSize = TextSize1 == 'Normal' ? size.small : TextSize1 == 'Küçük' ? size.tiny : size.normal
tabPos = TablePos == 'Sağ Yukarı' ? position.top_right : TablePos == 'Sol Alt' ? position.bottom_left : TablePos == 'Sağ Orta' ? position.middle_right : position.bottom_right
var MA_Crossover_Table = table.new(tabPos, 7, 3, color.rgb(4, 125, 196, 50), color.new(color.black, 1), 1, color.new(color.black, 1), 1)


// MA Kesişimleri
crossoverSignal = close > ust_band ? 'Yukarı Kesişim' : na
crossunderSignal = close < alt_band ? 'Aşağı Kesişim' : na


// Tablo Fonksiyonu
fTable(rowNumber, times) =>
    crossoverText = request.security(syminfo.ticker, times, crossoverSignal)
    crossunderText = request.security(syminfo.ticker, times, crossunderSignal)

    // Kesişim ve Arka Plan Rengini Belirle
    trendText = crossoverText != na ? 'Yükseliş' + '\n' + 'Up Trend' : crossunderText != na ? 'Düşüş' + '\n' + 'Down Trend' : na
    bgcolor = crossoverText != na ? color.green : crossunderText != na ? color.red : color.new(#00b2ff, 100)

    if TikTab
        // Birinci Satır: Zaman Dilimleri
        table.cell(MA_Crossover_Table, 0, 0, 'Zaman Dilimi' + '\n' + 'TimeFrame :', text_color = TablePosTextCol, text_size = textSize, bgcolor = color.new(color.black, 100))
        table.cell(MA_Crossover_Table, 0, 1, 'Trend', text_color = TablePosTextCol, text_size = textSize, bgcolor = color.new(color.black, 100))

        // İkinci Satır: Kesişim Türü ve Trend
        tfDes = times == '' ? timeframe.period : times
        table.cell(MA_Crossover_Table, rowNumber, 0, tfDes, text_color = TablePosTextCol, text_size = textSize, bgcolor = dashColor)
        table.cell(MA_Crossover_Table, rowNumber, 1, trendText, text_color = TablePosTextCol, text_size = textSize, bgcolor = bgcolor)

// Tabloyu Oluştur
fTable(1, times1)
fTable(2, times2)
fTable(3, times3)
fTable(4, times4)
fTable(5, times5)
fTable(6, times6)


var table logo = table.new(position.bottom_right, 2, 2)
if barstate.islast
    table.cell(logo, 0, 0, 'Mehmet ONAT', text_size = size.normal, text_color = color.gray)
Editor is loading...
Leave a Comment