Trading System basato su Indicatore Nadaraya – Watson

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #224081 quote
    luca_mass
    Participant
    New

    Ciao a tutti,

    vi chiedo aiuto perchè non riesco a trovare una soluzione al mio problema qui sul forum.

    Vorrei provare a studiare alcuni trading system basati sull’indicatore Nadaraya Watson che ho trovato qui sul forum e che vi allego.

    Vorrei Riuscire a trasformare i punti dell’indicatore in una linea da sfruttare come trigger di ingresso per dei TS (un po come se fossero bande di Bollinger), prevalentemente come trigger counter trend, ma perchè no, anche come segnale di rottura forte.

    Siccome i TS non saranno troppo complessi preferirei avere il calcolo dell’indicatore Nadaraya Watson all’interno del codice, visto che dovrebbe essere anche più veloce in fase di backtest (è corretto?).

    Grazie mille

     

    //Nadaraya-Watson Envelope
    length = 21 //Window Size
    hh = 8 //Bandwidth
    mult = 2
    
    once init = 1
    
    src = customclose
    
    n = barindex
    
    If init = 1 then
    den = 0
    For i = 0 to length-1 do
    $coefs[i]=exp(-(i*i)/(hh*hh*2))
    den = den + $coefs[i]
    Next
    init = 0
    Endif
    
    out = 0
    
    For i = 0 to length-1 do
    out = out + src[i]*$coefs[i]
    Next
    
    out = out/den
    mae = exponentialAverage[length](abs(src-out)) * mult
    
    upper = out + mae
    lower = out - mae
    
    DRAWPOINT(barindex, lower, 2) coloured(0,255,0,200)
    DRAWPOINT(barindex, upper, 2) coloured(255,0,0,255)
    
    Return
    #224238 quote
    robertogozzi
    Moderator
    Master

    Basta cambuare le ultime 3 righe così per ottenere le righe:

    //DRAWPOINT(barindex, lower, 2) coloured(0,255,0,200)
    //DRAWPOINT(barindex, upper, 2) coloured(255,0,0,255)
    
    Return upper AS "Linea Superiore",lower as "Linea Inferiore"

    e nel TS fai riferimento ad UPPER and LOWER come se fossero Bande di Bolluinger ecc…

    #224247 quote
    luca_mass
    Participant
    New

    Grazie mille,

    quindi poi dovrei richimare con la funzione Call il mio indicatore nel TS, giusto? non posso tenerlo nel codice del TS?

    Intanto ho provato a fare come mi hai consigliato ma trovo discrepanza tra i punti e la linea, ti allego screen. Come posso avere una linea che replichi correttamente i punti?

    Grazie

    #224249 quote
    luca_mass
    Participant
    New

    mi scuso ma ho copiato un codice errato.

    ti metto quello corretto, magari riesci così ad aiutarmi, grazie

     

    //Nadaraya-Watson Envelope
    defparam drawonlastbaronly = true
     
    length = Min(1000,BarIndex)//Window Size
    hh = 8 //Bandwidth
    mult = 0.3
    src = Close
    n = barindex
    k = 2
    if IsLastBarUpdate then
    y2 = 0
    sume = 0
    for i = 0 to length-1
    sum = 0
    sumw = 0
    for j = 0 to length-1
    w = EXP(-pow(i-j,2)/(hh*hh*2))
    sum = sum+src[j]*w
    sumw = sumw+w
    next
    y2 = sum/sumw
    sume = sume+abs(src[i] - y2)
    $a[barindex-i]=y2
    //DRAWPOINT(barindex-i, y2, 1)
    next
    mae = sume/(length*mult)
    for i=0 to length-1
    DRAWpoint(barindex-i, $a[barindex-i]-mae, 2) coloured(0,255,0,100)
    DRAWPOINT(barindex-i, $a[barindex-i]+mae, 2) coloured(255,0,0,100)
    next
    endif
    return
    
    #224263 quote
    robertogozzi
    Moderator
    Master

    Commenta le due righe DRAWPOINT e metti come ultime 3 righe:

    Upper = y2+mae
    Lower = y2-mae
    return Upper,Lower

    e fai sempre riferimento ad UPPER and LOWER.

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

Trading System basato su Indicatore Nadaraya – Watson


ProOrder: Trading Automatico & Backtesting

New Reply
Author
author-avatar
luca_mass @luca_mass Participant
Summary

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

Topic Details
Forum: ProOrder: Trading Automatico & Backtesting
Language: Italian
Started: 11/21/2023
Status: Active
Attachments: 1 files
Logo Logo
Loading...