Convention script tradingview

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #239486 quote
    Armand2020Armand2020
    Participant
    Senior

    Bonjour, serait il possible de convertir un script trading view? Merci

    // © Julien_Eche

    indicator(“Smart Trend Envelope”, overlay=true, max_bars_back=1000, max_lines_count=500)

    group1 = “Channel Settings”
    h = input.float(8.0, title=’Bandwidth’, group=group1)
    multnw = input.float(3.0, title=’Multiplier’)
    log(x) => math.log(x) / math.log(math.e)
    exp(x) => math.pow(math.e, x)
    src = log(input(close, title=’Source’))

    up_col = input(color.teal, title=’Upper Line Color’)
    dn_col = input(color.red, title=’Lower Line Color’)
    line_widthnw = input.int(2, title=’Line Width’)

    group2 = “Table Settings”
    tablePositionInput = input.string(“Top Center”, “Table Position”, options=[“Bottom Right”, “Bottom Left”, “Middle Right”, “Middle Left”, “Top Right”, “Top Left”, “Top Center”, “Bottom Center”], group=group2)
    getTablePosition(pos) =>
    // Function to convert table position input string to the corresponding position value
    if pos == “Bottom Right”
    position.bottom_right
    else if pos == “Bottom Left”
    position.bottom_left
    else if pos == “Middle Right”
    position.middle_right
    else if pos == “Middle Left”
    position.middle_left
    else if pos == “Top Right”
    position.top_right
    else if pos == “Top Left”
    position.top_left
    else if pos == “Top Center”
    position.top_center
    else if pos == “Bottom Center”
    position.bottom_center
    else
    position.bottom_right

    tablePos = getTablePosition(tablePositionInput)

    rightTableTextColorInput = input.color(color.silver, “Projection Confidence Text Color”)

    showPearsonInput = input.bool(false, “Show Pearson’s R instead of Projection Confidence Level”)

    lengthInput1 = 50
    lengthInput2 = 100
    lengthInput3 = 150
    lengthInput4 = 200
    lengthInput5 = 250
    lengthInput6 = 300
    lengthInput7 = 350
    lengthInput8 = 400
    lengthInput9 = 450
    lengthInput10 = 500

    calcSlope(src, length) =>
    // Function to calculate slope, average, and intercept
    max_bars_back(src, 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 = math.log(src[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]

    calcDev(src, length, slope, average, intercept) =>
    // Function to calculate standard deviation, Pearson’s R, up deviation, and down deviation
    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 = math.log(high[j]) – val
    if price > upDev
    upDev := price
    price := val – math.log(low[j])
    if price > dnDev
    dnDev := price
    price := math.log(src[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]

    // Calculate slope, average, and intercept for each length
    [s1, a1, i1] = calcSlope(src, lengthInput1)
    [s2, a2, i2] = calcSlope(src, lengthInput2)
    [s3, a3, i3] = calcSlope(src, lengthInput3)
    [s4, a4, i4] = calcSlope(src, lengthInput4)
    [s5, a5, i5] = calcSlope(src, lengthInput5)
    [s6, a6, i6] = calcSlope(src, lengthInput6)
    [s7, a7, i7] = calcSlope(src, lengthInput7)
    [s8, a8, i8] = calcSlope(src, lengthInput8)
    [s9, a9, i9] = calcSlope(src, lengthInput9)
    [s10, a10, i10] = calcSlope(src, lengthInput10)

    // Calculate standard deviation, Pearson’s R, up deviation, and down deviation for each length
    [stdDev1, pearsonR1, upDev1, dnDev1] = calcDev(src, lengthInput1, s1, a1, i1)
    [stdDev2, pearsonR2, upDev2, dnDev2] = calcDev(src, lengthInput2, s2, a2, i2)
    [stdDev3, pearsonR3, upDev3, dnDev3] = calcDev(src, lengthInput3, s3, a3, i3)
    [stdDev4, pearsonR4, upDev4, dnDev4] = calcDev(src, lengthInput4, s4, a4, i4)
    [stdDev5, pearsonR5, upDev5, dnDev5] = calcDev(src, lengthInput5, s5, a5, i5)
    [stdDev6, pearsonR6, upDev6, dnDev6] = calcDev(src, lengthInput6, s6, a6, i6)
    [stdDev7, pearsonR7, upDev7, dnDev7] = calcDev(src, lengthInput7, s7, a7, i7)
    [stdDev8, pearsonR8, upDev8, dnDev8] = calcDev(src, lengthInput8, s8, a8, i8)
    [stdDev9, pearsonR9, upDev9, dnDev9] = calcDev(src, lengthInput9, s9, a9, i9)
    [stdDev10, pearsonR10, upDev10, dnDev10] = calcDev(src, lengthInput10, s10, a10, i10)

    // Find the highest Pearson’s R among all lengths
    highestPearsonR = math.max(pearsonR1, pearsonR2, pearsonR3, pearsonR4, pearsonR5, pearsonR6, pearsonR7, pearsonR8, pearsonR9, pearsonR10)

    // Select the length, slope, intercept, and standard deviation based on the highest Pearson’s R
    selectedLength = highestPearsonR == pearsonR1 ? lengthInput1 : (highestPearsonR == pearsonR2 ? lengthInput2 : (highestPearsonR == pearsonR3 ? lengthInput3 : (highestPearsonR == pearsonR4 ? lengthInput4 : (highestPearsonR == pearsonR5 ? lengthInput5 : (highestPearsonR == pearsonR6 ? lengthInput6 : (highestPearsonR == pearsonR7 ? lengthInput7 : (highestPearsonR == pearsonR8 ? lengthInput8 : (highestPearsonR == pearsonR9 ? lengthInput9 : lengthInput10))))))))
    selectedS = highestPearsonR == pearsonR1 ? s1 : (highestPearsonR == pearsonR2 ? s2 : (highestPearsonR == pearsonR3 ? s3 : (highestPearsonR == pearsonR4 ? s4 : (highestPearsonR == pearsonR5 ? s5 : (highestPearsonR == pearsonR6 ? s6 : (highestPearsonR == pearsonR7 ? s7 : (highestPearsonR == pearsonR8 ? s8 : (highestPearsonR == pearsonR9 ? s9 : s10))))))))
    selectedI = highestPearsonR == pearsonR1 ? i1 : (highestPearsonR == pearsonR2 ? i2 : (highestPearsonR == pearsonR3 ? i3 : (highestPearsonR == pearsonR4 ? i4 : (highestPearsonR == pearsonR5 ? i5 : (highestPearsonR == pearsonR6 ? i6 : (highestPearsonR == pearsonR7 ? i7 : (highestPearsonR == pearsonR8 ? i8 : (highestPearsonR == pearsonR9 ? i9 : i10))))))))
    selectedStdDev = highestPearsonR == pearsonR1 ? stdDev1 : (highestPearsonR == pearsonR2 ? stdDev2 : (highestPearsonR == pearsonR3 ? stdDev3 : (highestPearsonR == pearsonR4 ? stdDev4 : (highestPearsonR == pearsonR5 ? stdDev5 : (highestPearsonR == pearsonR6 ? stdDev6 : (highestPearsonR == pearsonR7 ? stdDev7 : (highestPearsonR == pearsonR8 ? stdDev8 : (highestPearsonR == pearsonR9 ? stdDev9 : stdDev10))))))))

    startPrice = math.exp(selectedI + selectedS * (selectedLength – 1))
    endPrice = math.exp(selectedI)

    StartPrice = startPrice
    EndPrice = endPrice

    var string confidenceLevel = “”

    var color lineColor = na

    trendDirection = startPrice > endPrice ? -1 : 1

    if trendDirection == 1
    lineColor := color.teal
    else
    lineColor := color.red

    if barstate.islast
    var table t = table.new(position = tablePos, columns = 2, rows = 2)

    text1 = “”
    if selectedLength == lengthInput1
    text1 := “Auto-Selected Length: 50”
    if selectedLength == lengthInput2
    text1 := “Auto-Selected Length: 100”
    if selectedLength == lengthInput3
    text1 := “Auto-Selected Length: 150”
    if selectedLength == lengthInput4
    text1 := “Auto-Selected Length: 200”
    if selectedLength == lengthInput5
    text1 := “Auto-Selected Length: 250”
    if selectedLength == lengthInput6
    text1 := “Auto-Selected Length: 300”
    if selectedLength == lengthInput7
    text1 := “Auto-Selected Length: 350”
    if selectedLength == lengthInput8
    text1 := “Auto-Selected Length: 400”
    if selectedLength == lengthInput9
    text1 := “Auto-Selected Length: 450”
    if selectedLength == lengthInput10
    text1 := “Auto-Selected Length: 500”

    confidenceLevel := “”
    if highestPearsonR < 0.3
    confidenceLevel := “Ultra Weak”
    else if highestPearsonR < 0.5
    confidenceLevel := “Very Weak”
    else if highestPearsonR < 0.6
    confidenceLevel := “Weak”
    else if highestPearsonR < 0.7
    confidenceLevel := “Moderately Weak”
    else if highestPearsonR < 0.8
    confidenceLevel := “Slightly Weak”
    else if highestPearsonR < 0.9
    confidenceLevel := “Moderate”
    else if highestPearsonR < 0.92
    confidenceLevel := “Slightly Strong”
    else if highestPearsonR < 0.94
    confidenceLevel := “Moderately Strong”
    else if highestPearsonR < 0.96
    confidenceLevel := “Strong”
    else if highestPearsonR < 0.98
    confidenceLevel := “Very Strong”
    else
    confidenceLevel := “Ultra Strong”

    table.cell(t, 0, 0, text1, text_color=lineColor)
    if showPearsonInput
    table.cell(t, 1, 0, “Pearson’s R: ” + str.tostring(highestPearsonR, “#.##”), text_color=rightTableTextColorInput)
    else
    table.cell(t, 1, 0, “Projection Confidence: ” + confidenceLevel, text_color=rightTableTextColorInput)

    lengthnw = selectedLength

    n = bar_index
    var k = 2
    var uppernw = array.new_line(0)
    var lowernw = array.new_line(0)

    lset(l, x1, y1, x2, y2, col) =>
    line.set_xy1(l, x1, exp(y1))
    line.set_xy2(l, x2, exp(y2))
    line.set_color(l, col)
    line.set_width(l, line_widthnw)
    line.set_style(l, line.style_solid)

    if barstate.isfirst
    for i = 0 to lengthnw/k-1
    array.push(uppernw, line.new(na, na, na, na, color=up_col, width=line_widthnw, style=line.style_solid))
    array.push(lowernw, line.new(na, na, na, na, color=dn_col, width=line_widthnw, style=line.style_solid))

    line up = na
    line dn = na

    cross_up = 0.0
    cross_dn = 0.0
    if barstate.islast
    y = array.new_float(0)

    sum_e = 0.0
    for i = 0 to lengthnw-1
    sum = 0.0
    sumw = 0.0

    for j = 0 to lengthnw-1
    w = math.exp(-(math.pow(i-j, 2)/(h*h*2)))
    sum += src[j] * w
    sumw += w

    y2 = sum / sumw
    sum_e += math.abs(src[i] – y2)
    array.push(y, y2)

    mae = sum_e / lengthnw * multnw

    for i = 1 to lengthnw-1
    y2 = array.get(y, i)
    y1 = array.get(y, i-1)

    up := array.get(uppernw, i/k)
    dn := array.get(lowernw, i/k)

    lset(up, n-i+1, y1 + mae, n-i, y2 + mae, up_col)
    lset(dn, n-i+1, y1 – mae, n-i, y2 – mae, dn_col)

    #239731 quote
    Iván GonzálezIván González
    Moderator
    Legend

    Bonjour! Je viens de traduire cet indicateur qui est le même que celui que vous demandez : https://www.prorealcode.com/topic/nadaraya-watson-envelope/

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Convention script tradingview


ProBuilder : Indicateurs & Outils Personnalisés

New Reply
Author
author-avatar
Armand2020 @armand2020 Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by Iván GonzálezIván González
1 year, 10 months ago.

Topic Details
Forum: ProBuilder : Indicateurs & Outils Personnalisés
Language: French
Started: 10/26/2024
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...