Chiedo di tradurre Autocorrelation Price Forecasting Indicatore

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #245414 quote
    Gianfri
    Participant
    New

    Buonasera, posso chiedere la cortesia di tradurre questo indicatore dal linguaggio pine script al linguaggio proreal time?

    Ecco il codice :

    // @version= 6
    indicator ( “Autocorrelation Price Forecasting [The Quant Scie nce]” , overlay = true , max_labels_count = 500 )   tooltip1 = “Imposta la lunghezza dei dati utilizzati nel modello di previsione dei prezzi con autocorrelazione.” _length = input.int ( defval = 20 , title = “Lunghezza:” , step = 1 , minval =

      
                   1 , maxval = 200 , tooltip = tooltip1 , group = “IMPOSTAZIONE” )          
    signal_threshold = 0.50   color1 = input.color ( defval = color.rgb ( 105 , 247 , 62 ) , title = “Stima in su” , group = “STIMA COLORI” , inline = ‘footer’ ) color2 = input.color ( defval = color.rgb ( 255 , 0 , 0 ) , title = “Stima in giù” , group = “STIMA COLORI” , inline = ‘footer’ ) prices = close autocorr_values ​​= ta.correlation ( prezzi , prezzi [ _length ] , 200 ) cycle_detected = autocorr_values ​​> signal_threshold restituisce = ( prezzi prezzi [ 1 ]) / prezzi [ 1 ] * 100 linreg_values ​​= ta.linreg ( restituisce , _length , 0 ) var float store_cycle_value = 0 se cycle_detected store_cycle_value := linreg_values

                     
                      

      
        
        
            
        

        

     
          

    future_price_estimate = close * ( 1 + store_cycle_value / 100 )         hipotetical_gain = future_price_estimate close color_estimate = future_price_estimate > close ? color1 : future_price_estimate < close ? color2 : na color_estimate2 = hipotetical_gain > 0 ? color1 : na color_estimate3 = hipotetical_gain < 0 ? color2 : na label.new ( bar_index , future_price_estimate , xloc = xloc . bar_index , yloc = yloc . abovebar , text = str. tostring ( math. round_to_mintick ( hipotetical_gain )) , style = label. style_none , textcolor = color_estimate2 , size = size. tiny ) label.new ( bar_index , future_price_estimate , xloc = xloc . bar_index , yloc = yloc . belowbar , text = str. tostring ( math. round_to_mintick ( hipotetical_gain )) , style = label. style_none , textcolor = color_estimate3 , size = size. tiny ) plot ( future_price_estimate , color = color_estimate , style = plot. style_stepline_diamond , larghezza della riga = 2 )

        

    #245423 quote
    robertogozzi
    Moderator
    Master

    Per favore non aggiungere nuovi argomenti ad altri già esistenti.

    Per ciascun nuovo argomento, anche se molto simile, occorre aprirne uno nuovo con un titolo appropriato. Grazie 🙂

    Adesso l’ho creato io.

    Se riesci a postare il codice formattato sarebbe meglio. Anche un link alla pagina web dove l’hai trovato sarebbe molto utile.

    #245471 quote
    Gianfri
    Participant
    New

    Ok Grazie e chiedo scusa.

    Questo è il link del sito dove ho reperito il form dell’indicatore.

    https://it.tradingview.com/scripts/page-13/

     

    Grazie

    #245482 quote
    Iván González
    Moderator
    Master

    Ecco qui:

    //-------------------------------------------//
    //PRC_Autocorr Price Forecasting
    //version = 0
    //01.04.2025
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    //-------------------------------------------//
    // Inputs
    //-------------------------------------------//
    length = 20         // Lag period used for autocorrelation
    window = 200        // Number of bars used in the correlation window
    threshold = 0.5     // Threshold value to detect the presence of a cycle
    src = close         // Source data for returns calculation
    
    //-------------------------------------------//
    // Manual Pearson Correlation Calculation
    //-------------------------------------------//
    
    // Initialize sum variables for correlation formula
    sumX = 0
    sumY = 0
    sumXY = 0
    sumX2 = 0
    sumY2 = 0
    
    // Loop through the window and compute necessary sums
    FOR i = 0 TO window - 1 DO
       x = close[i]               // Current value
       y = close[i + length]      // Lagged value
       
       sumX  = sumX  + x          // ∑x
       sumY  = sumY  + y          // ∑y
       sumXY = sumXY + x * y      // ∑xy
       sumX2 = sumX2 + x * x      // ∑x²
       sumY2 = sumY2 + y * y      // ∑y²
    NEXT
    
    // Apply the Pearson correlation formula
    numerador   = window * sumXY - (sumX * sumY)
    denominador = SQRT((window * sumX2 - sumX * sumX) * (window * sumY2 - sumY * sumY))
    
    // Handle division by zero
    IF denominador <> 0 THEN
       autocorr = numerador / denominador
    ELSE
       autocorr = 0
    ENDIF
    
    //-------------------------------------------//
    // Cycle Detection & Linear Regression
    //-------------------------------------------//
    cycleDetected = autocorr > threshold   // Detect if autocorrelation is strong enough
    
    // Compute percentage returns
    returns = (src - src[1]) / src[1] * 100
    
    // Apply linear regression on returns
    linreg = LinearRegression[length](returns)
    
    // Store regression value only if a cycle is detected
    IF cycleDetected THEN
       storeCyclevalue = linreg
    ENDIF
    
    //-------------------------------------------//
    // Future Price Forecast
    //-------------------------------------------//
    futurePriceEstimate = close * (1 + storeCyclevalue / 100)     // Forecast future price
    hipoteticalGain = futurePriceEstimate - close                 // Calculate expected gain/loss
    
    //-------------------------------------------//
    // Color Assignment Based on Forecast Direction
    //-------------------------------------------//
    IF futurePriceEstimate > close THEN
       r = 105
       g = 247
       b = 62     // Green color for bullish forecast
    ELSE
       r = 255
       g = 0
       b = 0      // Red color for bearish forecast
    ENDIF
    
    //-------------------------------------------//
    // Display Forecast Info on Last Bar Only
    //-------------------------------------------//
    IF islastbarupdate THEN
       prediction = ROUND(hipoteticalGain, 3)         // Rounded gain value
       futurePrice = ROUND(futurePriceEstimate, 3)    // Rounded estimated price
       
       // Draw background box (positioned top right)
       drawrectangle(-10, -60, -200, -140) ANCHOR(topright, xshift, yshift)
       
       // Text labels showing the forecasted values
       drawtext("Last Bar Prediction", -100, -80) ANCHOR(topright, xshift, yshift)
       drawtext("Hipotetical Gain: #prediction#", -100, -100) ANCHOR(topright, xshift, yshift)
       drawtext("Future Price: #futurePrice#", -100, -120) ANCHOR(topright, xshift, yshift)
    ENDIF
    
    //-------------------------------------------//
    // Output Forecast Line on Chart
    //-------------------------------------------//
    RETURN futurePriceEstimate COLOURED(r, g, b) STYLE(line, 2)
    
    robertogozzi thanked this post
    #245497 quote
    Gianfri
    Participant
    New

    Grazie mille,

     

    ma purtroppo vedo che non funziona come dovrebbe. Ma cmq grazie mille ugualmente

    #245513 quote
    Iván González
    Moderator
    Master

    I valori restituiti sono simili a quelli restituiti dall'indicatore Tradingview…

    #245615 quote
    Gianfri
    Participant
    New

    Si è vero, Grazie mille

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

Chiedo di tradurre Autocorrelation Price Forecasting Indicatore


ProBuilder: Indicatori & Strumenti Personalizzati

New Reply
Author
author-avatar
Gianfri @gianfri Participant
Summary

This topic contains 6 replies,
has 3 voices, and was last updated by Gianfri
10 months ago.

Topic Details
Forum: ProBuilder: Indicatori & Strumenti Personalizzati
Language: Italian
Started: 03/29/2025
Status: Active
Attachments: No files
Logo Logo
Loading...