Kalman hull supertend

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #232543 quote
    StenozarStenozar
    Participant
    Master

    Buongiorno, è possibile tradurre questo indicatore? metto il link perchè non mi fa pubblicare il post se copio il codice: https://www.tradingview.com/script/PPHncdRt-Kalman-Hull-Supertrend-BackQuant/
    Grazie

    #232546 quote
    supertitisupertiti
    Participant
    Master
    #232547 quote
    StenozarStenozar
    Participant
    Master

    Grazie ma non mi pare lo stesso indicatore; quello che indicavo io incorpora anche il supertrend, non solo media mobile di hull e kalman.

    #232549 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Il codice al link iniziale è quello nel file allegato (il codice non riesco ad inserirlo).

    Nicolas and Iván González thanked this post
    Codice.txt
    #233145 quote
    Iván GonzálezIván González
    Moderator
    Legend

    Hola Aquí ha un'approssimazione dell'indicatore. Non è esattamente uguale, ma cambiare i parametri può renderlo più o meno sensato.

    //--------------------------------------------------------------//
    //PRC_Kalman Hull Supertrend
    //version = 0
    //28.05.24
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    //--------------------------------------------------------------//
    //-----Inputs---------------------------------------------------//
    pricesource=customclose
    measurementNoise=3
    processNoise=0.01
    
    atrPeriod=12
    factor=1.7
    
    //showkalman=1
    //paintCandles=1
    //showlongshort=1
    //--------------------------------------------------------------//
    //-----Kalman Price Filter Function-----------------------------//
    N=5
    
    if not isset($stateEstimate1[0]) then
    for j=0 to N-1 do
    $stateEstimate1[j]=pricesource
    $errorCovariance1[j]=1
    next
    endif
    
    for i=0 to N-1 do
    $predictedStateEstimate1[i]=$stateEstimate1[i]
    $predictedErrorCovariance1[i]=$errorCovariance1[i]+processNoise
    next
    
    for k=0 to N-1 do
    kg1=$predictedErrorCovariance1[k]/($predictedErrorCovariance1[k]+measurementNoise)
    $kalmanGain1[k]=kg1
    $stateEstimate1[k]=$predictedStateEstimate1[k]+kg1*(pricesource-$predictedStateEstimate1[k])
    $errorCovariance1[k]=(1-kg1)*$predictedErrorCovariance1[k]
    next
    Kalman1=$stateEstimate1[0]
    //--------------------------------------------------------------//
    //-----Hull Moving Average with Kalman--------------------------//
    //Kalman2
    if not isset($stateEstimate2[0]) then
    for j=0 to N-1 do
    $stateEstimate2[j]=pricesource
    $errorCovariance2[j]=1
    next
    endif
    
    for i=0 to N-1 do
    $predictedStateEstimate2[i]=$stateEstimate2[i]
    $predictedErrorCovariance2[i]=$errorCovariance2[i]+processNoise
    next
    
    for k=0 to N-1 do
    kg2=$predictedErrorCovariance2[k]/($predictedErrorCovariance2[k]+measurementNoise/2)
    $kalmanGain2[k]=kg2
    $stateEstimate2[k]=$predictedStateEstimate2[k]+kg2*(pricesource-$predictedStateEstimate2[k])
    $errorCovariance2[k]=(1-kg2)*$predictedErrorCovariance2[k]
    next
    Kalman2=$stateEstimate2[0]
    //Kalman Hull MA
    src=2*Kalman2-Kalman1
    length=round(sqrt(measurementNoise))
    
    if not isset($stateEstimate3[0]) then
    for j=0 to N-1 do
    $stateEstimate3[j]=src
    $errorCovariance3[j]=1
    next
    endif
    
    for i=0 to N-1 do
    $predictedStateEstimate3[i]=$stateEstimate3[i]
    $predictedErrorCovariance3[i]=$errorCovariance3[i]+processNoise
    next
    
    for k=0 to N-1 do
    kg3=$predictedErrorCovariance3[k]/($predictedErrorCovariance3[k]+length)
    $kalmanGain3[k]=kg3
    $stateEstimate3[k]=$predictedStateEstimate3[k]+kg3*(src-$predictedStateEstimate3[k])
    $errorCovariance3[k]=(1-kg3)*$predictedErrorCovariance3[k]
    next
    KalmanHMA=$stateEstimate3[0]
    //--------------------------------------------------------------//
    //-----SuperTrend Function--------------------------------------//
    if barindex <= atrperiod then
    upperband=kalmanHMA
    lowerband=kalmanHMA
    direction=1
    else
    atr=averagetruerange[atrPeriod](close)
    upperband=kalmanHMA+factor*atr
    lowerband=kalmanHMA-factor*atr
    prevlowerband=lowerband[1]
    prevupperband=upperband[1]
    
    if lowerband>prevlowerband or close[1]<prevlowerband then
    lowerband=lowerband
    else
    lowerband=prevlowerband
    endif
    
    if upperband<prevupperband or close[1]>prevupperband then
    upperband=upperband
    else
    upperband=prevupperband
    endif
    
    prevST=ST[1]
    if prevST=prevupperband then
    if close > upperband then
    direction=-1
    else
    direction=1
    endif
    else
    if close < lowerband then
    direction=1
    else
    direction=-1
    endif
    endif
    if direction=-1 then
    ST=lowerband
    else
    ST=upperband
    endif
    endif
    //--------------------------------------------------------------//
    //-----Conditional Trend----------------------------------------//
    once trend=0
    SuperTrendLong=direction crosses under 0
    SuperTrendShort=direction crosses over 0
    if SupertrendLong and not SuperTrendShort then
    trend=1
    r=0
    g=188
    b=212
    drawtext("▲",barindex,low)coloured(r,g,b)
    elsif SuperTrendShort then
    trend=-1
    r=255
    g=82
    b=82
    drawtext("▼",barindex,high)coloured(r,g,b)
    endif
    //--------------------------------------------------------------//
    //--------------------------------------------------------------//
    return ST as "Kalman Hull SuperTrend" coloured(r,g,b)style(line,3)
    
    #233235 quote
    StenozarStenozar
    Participant
    Master

    Grazie infinite Ivan!

Viewing 6 posts - 1 through 6 (of 6 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

Kalman hull supertend


ProBuilder: Indicatori & Strumenti Personalizzati

New Reply
Author
author-avatar
Stenozar @stenozar Participant
Summary

This topic contains 5 replies,
has 4 voices, and was last updated by StenozarStenozar
2 years, 6 months ago.

Topic Details
Forum: ProBuilder: Indicatori & Strumenti Personalizzati
Language: Italian
Started: 05/11/2024
Status: Active
Attachments: 1 files
ProRealCode ProRealCode
Loading...