Matriks Destek ve Yardım Platformu

Matriks Ürünleri ile ilgili tüm sorularınız için bizlere buradan ulaşabilirsiniz. Daha önce sorulan soruları ve verilen cevapları ilgili sekmelerden ve arama üzerinden inceleyebilirsiniz. Sağ taraftaki kategoriler üzerinden İlgilendiğiniz özelliklerle ilgili soruları filtreleyebilirsiniz. Soru ve cevapları sosyal medyada paylaşabilirsiniz. Sorduğunuz ve cevapladığınız soruların ve yorumlarınızın aldığı oylar üzerinden puan kazanırsınız. Puan sistemine bağlı kampanyamızla ücretsiz kullanım avantajlarından faydalanabilirsiniz.

0

indikatör veya tarama

Soruldu
Kategori
Dashboard
Görüntülenme
332 görüntülenme
Durum
Cevaplandı
sizden ricam tradingView de olan bu kod indikatör olrak yapmak indikator olmuyorsa bu kodlar ile expoler taramasını yapabilirmisiniz

indicator("Dynamic Risk-Adjusted Performance Ratios with Table", "DRPRT | [DeV]", overlay=false)

method calc(float src, int len) =>
    array<float> a_prtr = array.new<float>()
    array<float> a_nrtr = array.new<float>()
    array<float> a_rtr  = array.new<float>()
    float rtr = src / src[1] - 1

    for i = 0 to len - 1
        if rtr[i] < 0.
            a_nrtr.push(rtr[i])
        else    
            a_prtr.push(rtr[i])

        a_rtr.push(rtr[i])

    // Sharpe Ratio
    var float srp = na
    if array.size(a_rtr) > 0
        srp := array.avg(a_rtr) / array.stdev(a_rtr) * math.sqrt(len)
        srp := math.round(srp, 2)

    // Sortino Ratio
    var float srt = na
    if array.size(a_nrtr) > 0
        srt := array.avg(a_rtr) / array.stdev(a_nrtr) * math.sqrt(len)
        srt := math.round(srt, 2)

    // Omega Ratio
    var float omg = na
    if array.size(a_nrtr) > 0
        omg := array.sum(a_prtr) / math.abs(array.sum(a_nrtr))
        omg := math.round(omg, 2)

    [srp, srt, omg]

var string gc = "Calculation", var string gp = "Display"
src   = input.source(close, "Source", group=gc)
len   = input.int(30, "Period", group=gc)
blsrp = input.bool  (true , "Sharpe"   , group = gp)
blstn = input.bool  (true , "Sortino"  , group = gp)
blomg = input.bool  (true , "Omega"    , group = gp)
blmid = input.bool  (true , "Zero Line", group = gp)
var ratiosTable = table.new(position.middle_right, 4, 16, bgcolor=color.new(color.silver, 90))

if bar_index == 0
    table.cell(ratiosTable, 0, 0, "Asset", text_color=color.white, bgcolor=color.new(color.blue, 80), text_formatting=text.format_bold)
    table.cell(ratiosTable, 1, 0, "Sharpe", text_color=color.white, bgcolor=color.new(color.blue, 80), text_formatting=text.format_bold)
    table.cell(ratiosTable, 2, 0, "Sortino", text_color=color.white, bgcolor=color.new(color.blue, 80), text_formatting=text.format_bold)
    table.cell(ratiosTable, 3, 0, "Omega", text_color=color.white, bgcolor=color.new(color.blue, 80), text_formatting=text.format_bold)

[asset1_srp, asset1_srt, asset1_omg] = calc(request.security(asset1, timeframe.period, src), len)
[asset2_srp, asset2_srt, asset2_omg] = calc(request.security(asset2, timeframe.period, src), len)
[asset3_srp, asset3_srt, asset3_omg] = calc(request.security(asset3, timeframe.period, src), len)
[asset4_srp, asset4_srt, asset4_omg] = calc(request.security(asset4, timeframe.period, src), len)
[asset5_srp, asset5_srt, asset5_omg] = calc(request.security(asset5, timeframe.period, src), len)
[asset6_srp, asset6_srt, asset6_omg] = calc(request.security(asset6, timeframe.period, src), len)
[asset7_srp, asset7_srt, asset7_omg] = calc(request.security(asset7, timeframe.period, src), len)
[asset8_srp, asset8_srt, asset8_omg] = calc(request.security(asset8, timeframe.period, src), len)
[asset9_srp, asset9_srt, asset9_omg] = calc(request.security(asset9, timeframe.period, src), len)
[asset10_srp, asset10_srt, asset10_omg] = calc(request.security(asset10, timeframe.period, src), len)
[asset11_srp, asset11_srt, asset11_omg] = calc(request.security(asset11, timeframe.period, src), len)
[asset12_srp, asset12_srt, asset12_omg] = calc(request.security(asset12, timeframe.period, src), len)
[asset13_srp, asset13_srt, asset13_omg] = calc(request.security(asset13, timeframe.period, src), len)
[asset14_srp, asset14_srt, asset14_omg] = calc(request.security(asset14, timeframe.period, src), len)
[asset15_srp, asset15_srt, asset15_omg] = calc(request.security(asset15, timeframe.period, src), len)

getAssetName(asset) =>
    array.get(str.split(asset, ":"), 1)

for i = 1 to 15
    var float srp = na
    var float srt = na
    var float omg = na
    asset = ""

    if i == 1
        srp := asset1_srp
        srt := asset1_srt
        omg := asset1_omg
        asset := getAssetName(asset1)
    else if i == 2
        srp := asset2_srp
        srt := asset2_srt
        omg := asset2_omg
        asset := getAssetName(asset2)
    else if i == 3
        srp := asset3_srp
        srt := asset3_srt
        omg := asset3_omg
        asset := getAssetName(asset3)
    else if i == 4
        srp := asset4_srp
        srt := asset4_srt
        omg := asset4_omg
        asset := getAssetName(asset4)
    else if i == 5
        srp := asset5_srp
        srt := asset5_srt
        omg := asset5_omg
        asset := getAssetName(asset5)
    else if i == 6
        srp := asset6_srp
        srt := asset6_srt
        omg := asset6_omg
        asset := getAssetName(asset6)
    else if i == 7
        srp := asset7_srp
        srt := asset7_srt
        omg := asset7_omg
        asset := getAssetName(asset7)
    else if i == 8
        srp := asset8_srp
        srt := asset8_srt
        omg := asset8_omg
        asset := getAssetName(asset8)
    else if i == 9
        srp := asset9_srp
        srt := asset9_srt
        omg := asset9_omg
        asset := getAssetName(asset9)
    else if i == 10
        srp := asset10_srp
        srt := asset10_srt
        omg := asset10_omg
        asset := getAssetName(asset10)
    else if i == 11
        srp := asset11_srp
        srt := asset11_srt
        omg := asset11_omg
        asset := getAssetName(asset11)
    else if i == 12
        srp := asset12_srp
        srt := asset12_srt
        omg := asset12_omg
        asset := getAssetName(asset12)
    else if i == 13
        srp := asset13_srp
        srt := asset13_srt
        omg := asset13_omg
        asset := getAssetName(asset13)
    else if i == 14
        srp := asset14_srp
        srt := asset14_srt
        omg := asset14_omg
        asset := getAssetName(asset14)
    else if i == 15
        srp := asset15_srp
        srt := asset15_srt
        omg := asset15_omg
        asset := getAssetName(asset15)

    table.cell(ratiosTable, 0, i, asset, text_color=color.white, bgcolor=color.new(color.blue, 80), text_formatting=text.format_italic)
    table.cell(ratiosTable, 1, i, str.tostring(srp), text_color=#228833)
    table.cell(ratiosTable, 2, i, str.tostring(srt), text_color=#cf5151)
    table.cell(ratiosTable, 3, i, str.tostring(omg), text_color=#c09b20)

[srp, srt, omg] = src.calc(len)
hline(blmid ? 0 : na, "Zero Line", color=color.new(color.gray, 0))
plot(blsrp ? math.round(srp, 2) : na, "Sharpe Ratio", color=#228833, precision = 2)
plot(blstn ? math.round(srt, 2) : na, "Sortino Ratio", color=#cf5151, precision = 2)
plot(blomg ? math.round(omg, 2) : na, "Omega Ratio", color=#c09b20, precision = 2)
Paylaş

1 Cevap

Cevabınız

Cevap yazmak için giriş yapın.Giriş yapKayıt ol