John Ehler's – Indicator: Correlation Cycle

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #133379 quote
    Actaru5
    Participant
    Veteran

    Buonasera a tutti,

    in seguito alla pubblicazione dell’ edizione 06/2020 di Stock & Commodities dove troviamo l’articolo con il codice di John Ehlers “Correlation As A Cycle Indicator”, mi sono divertito a tradurlo in codice PRT

    Lo pubblico qui, in quanto vorrei che @nicolas lo controlli prima di inserirlo in libreria per gli altri utenti.

    Fonte S&C http://traders.com/Documentation/FEEDbk_docs/2020/06/TradersTips.html

    Autor John F. Ehlers

    // http://traders.com/Documentation/FEEDbk_docs/2020/06/TradersTips.html
    
    // Indicator: Correlation Cycle
    // Correlation Angle Indicator
    // (C) 2013-2020   John F. Ehlers
    // TASC Jun 2020
    
    // Inputs Setting
    Period = 14 
    InputPeriod = 0           // Uses price data if 0
    ShowCycleIndicator = True // Booleano  Indicator Mode
    ShowCycleIndex = False    // Booleano  Index Mode    
    ShowPhasorAngle = False   // Booleano  Show Angle Phasor Mode
    ShowMarketState = False   // Booleano  Show Market State Mode
    
    
    //Correlate over one full cycle period
    Length = Period
    Price = customClose
    
    //Creates a theoretical sinusoid having an period equal to the input period as the data input
    if InputPeriod <> 0 then
    Price = Sin( 360 * Barindex / InputPeriod)
    endif
    //Correlate price with cosine wave having a fixed period
    Sx = 0
    Sy = 0
    Sxx = 0
    Sxy = 0
    Syy = 0
    for Count = 1 to Length do
    X = Price[count - 1]
    Y = Cos( 360 * ( Count - 1 ) / Period )
    Sx = Sx + X
    Sy = Sy + Y
    Sxx = Sxx + X * X
    Sxy = Sxy + X * Y
    Syy = Syy + Y*Y
    next
    
    if ( Length*Sxx - Sx*Sx > 0) and ( Length*Syy - Sy*Sy > 0 ) then
    Real = ( Length*Sxy - Sx*Sy ) / SQRT( ( Length*Sxx - Sx*Sx ) * ( Length*Syy - Sy*Sy ) )
    endif
    //Correlate with a negative sine wave having a fixed period
    Sx = 0
    Sy = 0
    Sxx = 0
    Sxy = 0
    Syy = 0
    for Count = 1 to Length do
    X = Price[count - 1]
    Y = -Sin( 360 * ( count - 1 ) / Period )
    Sx = Sx + X
    Sy = Sy + Y
    Sxx = Sxx + X * X
    Sxy = Sxy + X * Y
    Syy = Syy + Y * Y
    next
    
    if ( Length*Sxx - Sx*Sx > 0 ) and ( Length*Syy - Sy*Sy > 0 ) then
    Imag = ( Length*Sxy - Sx*Sy ) / SqRt( ( Length*Sxx - Sx*Sx ) *( Length*Syy - Sy*Sy ) )
    endif
    
    //Compute the angle as an arctangent function and resolve ambiguity
    if Imag <> 0 then
    Angle = 90 + Atan( Real / Imag )
    Endif
    if Imag > 0 then
    Angle = Angle - 180
    Endif
    //Do not allow the rate change of angle to go negative
    if Angle[1] - Angle < 270 and Angle < Angle[1] then
    Angle = Angle[1]
    Endif
    
    //Compute and plot market state
    State = 0
    if Abs( Angle - Angle[1] ) < 9 and Angle <= 0 then
    State = -1
    Endif
    if Abs( Angle - Angle[1] ) < 9 and Angle >= 0 then
    State = 1
    Endif
    
    If ShowCycleIndicator Then
    Realshow = (((real+1)/2)*200)-100
    Imagshow = (((Imag+1)/2)*200)-100
    r=169
    g=169
    b=169
    if Realshow>Imagshow then
    r=34
    g=139
    b=34
    elsif Realshow<Imagshow then
    r=220
    g=20
    b=60
    endif
    ZeroLine = 0
    Endif
    
    If ShowCycleIndex Then
    Realshow = (((real+1)/2)*100)
    Imagshow = (((Imag+1)/2)*100)
    r=169
    g=169
    b=169
    if Realshow>Imagshow then
    r=34
    g=139
    b=34
    elsif Realshow<Imagshow then
    r=220
    g=20
    b=60
    endif
    ZeroLine = 50
    Endif
    
    If ShowPhasorAngle Then
    AngleShow = Angle
    if AngleShow>0 then
    r=34
    g=139
    b=34
    elsif AngleShow<0 then
    r=220
    g=20
    b=60
    endif
    ZeroLine = 0
    Endif
    
    If ShowMarketState Then
    StateShow = State*100
    if StateShow>0 then
    r=34
    g=139
    b=34
    elsif StateShow<0 then
    r=220
    g=20
    b=60
    Endif
    ZeroLine = 0
    Endif
    
    Return Realshow coloured(r,g,b) as "Real", Imagshow coloured(153,153,153) as "Imag" ,AngleShow coloured(r,g,b) as "Phasor", StateShow coloured(r,g,b) Style(Histogram,1) as "Correlation Cycle Ind", ZeroLine coloured(153,153,153) as "Zero Line"
    

    Saluti Actaru5

    #133397 quote
    Nicolas
    Keymaster
    Master

    Molte grazie! Molto gentile da parte tua per condividere il codice che hai tradotto! L'ho provato e non ho visto alcun errore. Potrei chiederti più aiuto? Pubblicandolo con il tuo nome nella libreria usando questa pagina: condividi il tuo codice nella libreria 😉

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

John Ehler's – Indicator: Correlation Cycle


ProBuilder: Indicatori & Strumenti Personalizzati

New Reply
Author
author-avatar
Actaru5 @actaru5 Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by Nicolas
5 years, 10 months ago.

Topic Details
Forum: ProBuilder: Indicatori & Strumenti Personalizzati
Language: Italian
Started: 05/26/2020
Status: Active
Attachments: No files
Logo Logo
Loading...