Untitled

mail@pastecode.io avatar
unknown
plain_text
17 days ago
9.8 kB
77
Indexable
Never
//@version=5
indicator("Coklu Indikator Tablosu", overlay=true)

// Zaman araliklari
rsi_length = input.int(14, "RSI Periyodu", minval=1)
macd_fast = input.int(12, "MACD Hizli Periyot", minval=1)
macd_slow = input.int(26, "MACD Yavas Periyot", minval=1)
macd_signal = input.int(9, "MACD Sinyal Periyodu", minval=1)
momentum_length = input.int(10, "Momentum Periyodu", minval=1)
adx_length = input.int(14, "ADX Periyodu", minval=1)
trix_length = input.int(18, "TRIX Periyodu", minval=1)

// Hareketli ortalama inputlari
ma1_type = input.string("SMA", "MA1 Turu", options=["SMA", "EMA", "WMA", "RMA"])
ma1_length = input.int(10, "MA1 Periyodu", minval=1)
ma2_type = input.string("EMA", "MA2 Turu", options=["SMA", "EMA", "WMA", "RMA"])
ma2_length = input.int(20, "MA2 Periyodu", minval=1)

// Indikator hesaplamalari
rsi_value = ta.rsi(close, rsi_length)
[macd_line, signal_line, hist] = ta.macd(close, macd_fast, macd_slow, macd_signal)
momentum_value = ta.mom(close, momentum_length)
[_, _, adx_value] = ta.dmi(adx_length, adx_length)

// TRIX hesaplamasi
trix_value = 10000 * ta.change(ta.ema(ta.ema(ta.ema(math.log(close), trix_length), trix_length), trix_length))

// Hareketli ortalama hesaplamalari
ma1 = switch ma1_type
    "SMA" => ta.sma(close, ma1_length)
    "EMA" => ta.ema(close, ma1_length)
    "WMA" => ta.wma(close, ma1_length)
    "RMA" => ta.rma(close, ma1_length)

ma2 = switch ma2_type
    "SMA" => ta.sma(close, ma2_length)
    "EMA" => ta.ema(close, ma2_length)
    "WMA" => ta.wma(close, ma2_length)
    "RMA" => ta.rma(close, ma2_length)

// MA konumu kontrolu
ma_position = ma1 > ma2 ? "Pozitif" : "Negatif"

// Tablo olusturma
var table indikator_tablosu = table.new(position = position.top_right, columns = 3, rows = 7, border_width = 1)

// Tablo basliklari
table.cell(indikator_tablosu, 0, 0, "Indikator", bgcolor = color.new(color.blue, 70), text_color = color.white)
table.cell(indikator_tablosu, 1, 0, "Periyot", bgcolor = color.new(color.blue, 70), text_color = color.white)
table.cell(indikator_tablosu, 2, 0, "Deger", bgcolor = color.new(color.blue, 70), text_color = color.white)

// RSI
table.cell(indikator_tablosu, 0, 1, "RSI", bgcolor = color.new(color.gray, 90))
table.cell(indikator_tablosu, 1, 1, str.tostring(rsi_length), bgcolor = color.new(color.gray, 90))
table.cell(indikator_tablosu, 2, 1, str.tostring(rsi_value, "#.##"), bgcolor = color.new(color.gray, 90))

// MACD
table.cell(indikator_tablosu, 0, 2, "MACD", bgcolor = color.new(color.gray, 90))
table.cell(indikator_tablosu, 1, 2, str.tostring(macd_fast) + "," + str.tostring(macd_slow) + "," + str.tostring(macd_signal), bgcolor = color.new(color.gray, 90))
macd_bg_color = macd_line > signal_line ? color.new(color.green, 70) : color.new(color.red, 70)
table.cell(indikator_tablosu, 2, 2, str.tostring(macd_line, "#.##"), bgcolor = macd_bg_color)

// Momentum
table.cell(indikator_tablosu, 0, 3, "Momentum", bgcolor = color.new(color.gray, 90))
table.cell(indikator_tablosu, 1, 3, str.tostring(momentum_length), bgcolor = color.new(color.gray, 90))
table.cell(indikator_tablosu, 2, 3, str.tostring(momentum_value, "#.##"), bgcolor = color.new(color.gray, 90))

// ADX
table.cell(indikator_tablosu, 0, 4, "ADX", bgcolor = color.new(color.gray, 90))
table.cell(indikator_tablosu, 1, 4, str.tostring(adx_length), bgcolor = color.new(color.gray, 90))
table.cell(indikator_tablosu, 2, 4, str.tostring(adx_value, "#.##"), bgcolor = color.new(color.gray, 90))

// TRIX
table.cell(indikator_tablosu, 0, 5, "TRIX", bgcolor = color.new(color.gray, 90))
table.cell(indikator_tablosu, 1, 5, str.tostring(trix_length), bgcolor = color.new(color.gray, 90))
table.cell(indikator_tablosu, 2, 5, str.tostring(trix_value, "#.####"), bgcolor = color.new(color.gray, 90))

// MA Konumu
table.cell(indikator_tablosu, 0, 6, "MA Konumu", bgcolor = color.new(color.gray, 90))
table.cell(indikator_tablosu, 1, 6, ma1_type + "(" + str.tostring(ma1_length) + "), " + ma2_type + "(" + str.tostring(ma2_length) + ")", bgcolor = color.new(color.gray, 90))
ma_bg_color = ma_position == "Pozitif" ? color.new(color.green, 70) : color.new(color.red, 70)
table.cell(indikator_tablosu, 2, 6, ma_position, bgcolor = ma_bg_color)

// Hareketli ortalamalari cizelgeye cizme
plot(ma1, color=color.blue, title="MA1")
plot(ma2, color=color.red, title="MA2")

//@version=5
//indicator("l", shorttitle="g", overlay=true)

lengthInput = input.int(100, title="Length", minval = 1, maxval = 5000)
sourceInput = input.source(close, title="Source")

group1 = "Channel Settings"
useUpperDevInput = input.bool(true, title="Upper Deviation", inline = "Upper Deviation", group = group1)
upperMultInput = input.float(2.0, title="", inline = "Upper Deviation", group = group1)
useLowerDevInput = input.bool(true, title="Lower Deviation", inline = "Lower Deviation", group = group1)
lowerMultInput = input.float(2.0, title="", inline = "Lower Deviation", group = group1)

group2 = "Display Settings"
showPearsonInput = input.bool(true, "Show Pearson's R", group = group2)
extendLeftInput = input.bool(false, "Extend Lines Left", group = group2)
extendRightInput = input.bool(true, "Extend Lines Right", group = group2)
extendStyle = switch
    extendLeftInput and extendRightInput => extend.both
    extendLeftInput => extend.left
    extendRightInput => extend.right
    => extend.none

group3 = "Color Settings"
colorUpper = input.color(color.new(color.blue, 85), "", inline = group3, group = group3)
colorLower = input.color(color.new(color.red, 85), "", inline = group3, group = group3)

calcSlope(source, length) =>
    max_bars_back(source, 5000)
    if not barstate.islast or length <= 1
        [float(na), float(na), float(na)]
    else
        sumX = 0.0
        sumY = 0.0
        sumXSqr = 0.0
        sumXY = 0.0
        for i = 0 to length - 1 by 1
            val = source[i]
            per = i + 1.0
            sumX += per
            sumY += val
            sumXSqr += per * per
            sumXY += val * per
        slope = (length * sumXY - sumX * sumY) / (length * sumXSqr - sumX * sumX)
        average = sumY / length
        intercept = average - slope * sumX / length + slope
        [slope, average, intercept]
        
[s, a, i] = calcSlope(sourceInput, lengthInput)
startPrice = i + s * (lengthInput - 1)
endPrice = i
var line baseLine = na
if na(baseLine) and not na(startPrice)
    baseLine := line.new(bar_index - lengthInput + 1, startPrice, bar_index, endPrice, width=1, extend=extendStyle, color=color.new(colorLower, 0))
else
    line.set_xy1(baseLine, bar_index - lengthInput + 1, startPrice)
    line.set_xy2(baseLine, bar_index, endPrice)
    na
    
calcDev(source, length, slope, average, intercept) =>
    upDev = 0.0
    dnDev = 0.0
    stdDevAcc = 0.0
    dsxx = 0.0
    dsyy = 0.0
    dsxy = 0.0
    periods = length - 1
    daY = intercept + slope * periods / 2
    val = intercept
    for j = 0 to periods by 1
        price = high[j] - val
        if price > upDev
            upDev := price
        price := val - low[j]
        if price > dnDev
            dnDev := price
        price := source[j]
        dxt = price - average
        dyt = val - daY
        price -= val
        stdDevAcc += price * price
        dsxx += dxt * dxt
        dsyy += dyt * dyt
        dsxy += dxt * dyt
        val += slope
    stdDev = math.sqrt(stdDevAcc / (periods == 0 ? 1 : periods))
    pearsonR = dsxx == 0 or dsyy == 0 ? 0 : dsxy / math.sqrt(dsxx * dsyy)
    [stdDev, pearsonR, upDev, dnDev]
    
[stdDev, pearsonR, upDev, dnDev] = calcDev(sourceInput, lengthInput, s, a, i)
upperStartPrice = startPrice + (useUpperDevInput ? upperMultInput * stdDev : upDev)
upperEndPrice = endPrice + (useUpperDevInput ? upperMultInput * stdDev : upDev)
var line upper = na
lowerStartPrice = startPrice + (useLowerDevInput ? -lowerMultInput * stdDev : -dnDev)
lowerEndPrice = endPrice + (useLowerDevInput ? -lowerMultInput * stdDev : -dnDev)
var line lower = na
if na(upper) and not na(upperStartPrice)
    upper := line.new(bar_index - lengthInput + 1, upperStartPrice, bar_index, upperEndPrice, width=1, extend=extendStyle, color=color.new(colorUpper, 0))
else
    line.set_xy1(upper, bar_index - lengthInput + 1, upperStartPrice)
    line.set_xy2(upper, bar_index, upperEndPrice)
    na
if na(lower) and not na(lowerStartPrice)
    lower := line.new(bar_index - lengthInput + 1, lowerStartPrice, bar_index, lowerEndPrice, width=1, extend=extendStyle, color=color.new(colorUpper, 0))
else
    line.set_xy1(lower, bar_index - lengthInput + 1, lowerStartPrice)
    line.set_xy2(lower, bar_index, lowerEndPrice)
    na
linefill.new(upper, baseLine, color = colorUpper)
linefill.new(baseLine, lower, color = colorLower)

float trend = math.sign(startPrice - endPrice)
alertcondition(sourceInput > line.get_price(upper, bar_index) or sourceInput < line.get_price(lower, bar_index), title='Regression Channel Exited', message="The price movement has exited Regression Channel's bounds")
alertcondition(trend[1] >= 0 and trend < 0, title='Switched to Uptrend', message='The Regression Channel trend switched from Downtrend to Uptrend')
alertcondition(trend[1] <= 0 and trend > 0, title='Switched to Downtrend', message='The Regression Channel trend switched from Uptrend to Downtrend')

// Pearson's R
var label r = na
label.delete(r[1])
if showPearsonInput and not na(pearsonR)
    r := label.new(bar_index - lengthInput + 1, lowerStartPrice, str.tostring(pearsonR, "#.################"), color = color.new(color.white, 100), textcolor=color.new(colorUpper, 0), size=size.normal, style=label.style_label_up)
Leave a Comment