traduzione codice TW Machine Learning Momentum

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #233669 quote
    Msport71
    Participant
    Junior

    Buongiorno,

    vorrei proporre traduzione di questo codice che sembra interessante, in quanto evidenzia molto chiaramente le fasi di stallo del mercato, potenzialmente

    propedeutiche a successivi movimenti.

    Grazie come sempre

    https://www.tradingview.com/script/OCl780V6-Machine-Learning-Momentum-Oscillator-ChartPrime/

    // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
    // © ChartPrime

    //@version=5
    indicator(“Machine Learning Momentum Oscillator [ChartPrime]”,shorttitle = “Machine Learning Momentum Oscillator [ChartPrime]” , overlay=false)

    string Core = “➞ ML Core Settings 🔸”
    int ShortPriod = input.int (26, ‘Short Period’, 1,group=Core)
    int LongPriod = input.int (14, ‘Long Period’, 2,group=Core)
    int Smooth = input.int (13, ‘Smoothing Period’, 2,group=Core)
    int Neighbours = math.floor(input.int (50,’Neighbours Count’, 5,group=Core))
    bool showLines = input.bool(false,”Show prediction lines”)
    float prediction = 0.0
    float small = 0.0
    float BIG = 0.0
    int Class = 0

    //——– {

    type MachineLearning
    array<float> D1
    array<float> D2
    array<float> D3
    array<int> dir
    array<int> Preds
    array<float> PerD

    type MLData
    float Prime1
    float Prime2
    float Prime3
    float prediction
    float Smoothed
    float Band

     

    var ML = MachineLearning.new(
    array.new_float(0),
    array.new_float(0),
    array.new_float(),
    array.new_int(0),
    array.new_int(0),
    array.new_float()
    )

    MData = MLData.new()

    method _Band(int len)=>
    math.min (ta.atr (len) * 0.3, close * (0.3/100)) [20] /2

     

    method RawData(int x,z) =>
    WS = ta.ema(hlc3 – hlc3[1], x)
    WQ = ta.ema(math.abs(hlc3 – hlc3[1]), x)
    Out = ta.ema(WS, z)
    Outs = ta.ema(WQ, z)
    Z = 100 * (Out / Outs)
    Z

    MData.Prime1 := RawData(LongPriod,Smooth)
    MData.Prime2 := RawData(ShortPriod,Smooth)
    MData.Band := _Band(30) * 2.5
    max = MData.Prime2 + MData.Band
    min = MData.Prime2 – MData.Band

     

    for i = 0 to math.max(LongPriod,ShortPriod,Neighbours)
    Class := MData.Prime1[2] < MData.Prime1[0] ? -1 : MData.Prime1[2] > MData.Prime1[0] ? 1 : 0

    ML.D1.push(MData.Prime1)
    ML.D2.push(MData.Prime2)
    ML.dir.push(Class)

    // if Algo.dir.size() > 10000
    // Algo.dir.shift()

    // method MLCalculation(float x ,float y) =>
    method MLCalculation(float x ,float y , float q , float z) =>
    math.abs(x – y) + math.abs(q – z)
    // math.sqrt(math.abs(x – y) * math.abs(q – z))
    // math.abs(x – y))

    // Nearest Neighbor Calculations
    method Knn(MachineLearning MS) =>
    float Minz = -1e-6
    for i = 0 to MS.dir.size() – 1
    MData.Prime3 := MLCalculation(MData.Prime1,MS.D1.get(i),MData.Prime2 ,MS.D2.get(i))
    // MData.Prime3 := MLCalculation(MData.Prime1,ML.data.get(i))
    if MData.Prime3 > Minz
    Minz := MData.Prime3
    if MS.Preds.size() >= Neighbours
    MS.Preds.shift()
    MS.Preds.push(MS.dir.get(i))
    float(MS.Preds.sum() * 5 )

    // break

    MData.prediction := Knn(ML)
    MData.Smoothed := ta.sma(MData.prediction,Smooth)
    ML.PerD.push(MData.Smoothed)

    // if ML.PerD.size() > 1000
    // ML.PerD.shift()
    small := ML.PerD.min()
    BIG := ML.PerD.max()
    Which = MData.prediction > 0 ? small:BIG

    Greeny = color.from_gradient(MData.prediction,small,BIG,color.rgb(7, 187, 37), color.rgb(0, 107, 43))
    Reddy = color.from_gradient(MData.prediction,small,BIG,color.rgb(153, 0, 0),color.rgb(255, 82, 82))
    con = MData.prediction == MData.Smoothed ?
    color.from_gradient(MData.prediction,small,BIG,color.rgb(164, 175, 10, 70), color.rgb(87, 61, 0, 70)): na

    pred = plot(MData.prediction,color =color.new(color.black,100),style = plot.style_line,title = “ML”,editable = false)
    SmoothP = plot(MData.Smoothed,color =color.new(color.black,100),style = plot.style_linebr,title = “Smoothed ML”,editable = false)
    _Which = plot(Which,color = color.new(color.black,100),editable = false)
    CONA = MData.prediction > MData.Smoothed ? Greeny:Reddy
    topLine = plot(BIG,color = color.new(color.white, 78),title = “T-TOP”)
    botLine = plot(small,color = color.new(color.white, 78),title = “T-BOT”)
    Top = plot(BIG + 15 ,color = color.new(color.white, 78),title = “B-TOP”)
    Bot = plot(small – 15,color = color.new(color.white, 78),title = “B-BOT”)
    _Center = plot(showLines ? MData.Prime1: na,color = color.new(#efb906, 70),linewidth = 2,editable = false)
    Center = plot(showLines ? MData.Prime2: na,color = color.new(#08d3ed, 70),linewidth = 2,editable = false)
    alpha = color.new(color.black, 100)
    TOP = plot(showLines ? max : na ,color = alpha,linewidth = 2,editable = false)
    BOT = plot(showLines ? min: na ,color = alpha,linewidth = 2,editable = false)

    plot(showLines ? MData.Prime1: na , “”, color.new(#efb906, 70), 2, editable = false)
    plot(showLines ? MData.Prime1: na , “”, color.new(#efb906, 90), 4, editable = false)
    plot(showLines ? MData.Prime2: na , “”, color.new(#08d3ed, 70), 2, editable = false)
    plot(showLines ? MData.Prime2: na , “”, color.new(#08d3ed, 90), 4, editable = false)

    fill(pred,_Which,color = con)
    fill(topLine,Top,color = color.rgb(255, 255, 255, 91))
    fill(botLine,Bot,color = color.rgb(255, 255, 255, 91))
    fill(topLine, botLine, BIG, small, color.rgb(255, 82, 82, 75), color.rgb(33, 149, 243, 82))

    plotcandle(MData.prediction,MData.prediction,MData.Smoothed,MData.Smoothed,color=color.new(CONA,20),bordercolor = color.new(CONA,10))
    fill(TOP, Center, top_value = max, bottom_value = MData.Prime2, bottom_color = color.new(#08edda, 75), top_color = alpha, editable = true)
    fill(Center, BOT, top_value = MData.Prime2, bottom_value = min, bottom_color = alpha, top_color = color.new(#08edda, 75), editable = true)
    fill(TOP, _Center, top_value = max, bottom_value = MData.Prime1, bottom_color = color.new(#efb906, 75), top_color = alpha, editable = true)
    fill(_Center, BOT, top_value = MData.Prime1, bottom_value = min, bottom_color = alpha, top_color = color.new(#efb906, 75), editable = true)

    #233855 quote
    Ciccarelli Franco
    Participant
    Junior

    Sembra molto interessante, strano che ancora non sia tradotto.

    #233977 quote
    Msport71
    Participant
    Junior

    Speriamo che Ivan lo abbia messo in coda alle varie traduzioni.

    #233981 quote
    Iván González
    Moderator
    Master

    Ciao! Sì, è in linea. Il problema è che un indicatore è difficile da tradurre, almeno per me 🙁

    #233991 quote
    Ciccarelli Franco
    Participant
    Junior

    Ciao Roberto, vuoi provare tu alla traduzione?

    #233992 quote
    Msport71
    Participant
    Junior

    Ciao! Sì, è in linea. Il problema è che un indicatore è difficile da tradurre, almeno per me 🙁

    Capisco, grazie .

    #233996 quote
    robertogozzi
    Moderator
    Master

    Non conosco i linguaggi divrsi da ProRealTime, solo a volte ho tradotto qualcosa da Easylanguage (Tradingiew) molto semplice e di 10-15 righe al massimo.

    #234003 quote
    Iván González
    Moderator
    Master

    Chiedo solo tempo perché ne avrò bisogno 🙂 Traducetelo, ne sono sicuro, ma non sarà come il resto dei codici che vengono tradotti in un paio di giorni.

    #234008 quote
    Msport71
    Participant
    Junior

    Benissimo, grazie per l’aiuto e buon lavoro.

    #234515 quote
    Ciccarelli Franco
    Participant
    Junior

    La traduzione è ancora il elaborazione?

    #234654 quote
    Iván González
    Moderator
    Master

    Sì, è in linea. Ho bisogno di trovare 2 ore di fila per poterci lavorare. Non è un codice di traduzione immediato

    #235460 quote
    Ciccarelli Franco
    Participant
    Junior

    Continuo ad aspettare

    #235468 quote
    Iván González
    Moderator
    Master

    Ciao, dovresti aspettare la prossima versione di PRT perché sono necessarie funzioni extra… In tutte le forme ha programmato bene la parte dell'indicatore e i risultati non hanno mala pinta.

    //---------------------------------------------------------//
    //PRC_Predictive Momentum Oscillator
    //version = 0
    //11.07.2024
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    //---------------------------------------------------------//
    shortPeriod=26
    LongPeriod=14
    Smooth=13
    Neighbours=50
    prediction=0
    small=0
    big=0
    class=0
    
    //---------------------------------------------------------//
    hlc3=(high+low+close)/3
    src=hlc3-hlc3[1]
    
    ws1=average[longperiod,1](src)
    wq1=average[longperiod,1](abs(src))
    out1=average[smooth,1](ws1)
    outs1=average[smooth,1](wq1)
    MDataPrime1 = 100*(out1/outs1)
    
    ws2=average[shortPeriod,1](src)
    wq2=average[shortPeriod,1](abs(src))
    out2=average[smooth,1](ws2)
    outs2=average[smooth,1](wq2)
    MDataPrime2 = 100*(out2/outs2)
    
    auxBand=min(averagetruerange[30]*0.3,close*0.3/100)
    MDataBand=auxBand[20]/2*2.5
    
    lmax=MDataPrime2+MDataBand
    lmin=MDataPrime2-MDataBand
    //---------------------------------------------------------//
    if MDataPrime1[2]<MDataPrime1 then
    class=-1
    elsif MDataPrime1[2]>MDataPrime1 then
    class=1
    else
    class=0
    endif
    
    size=max(longperiod,max(shortperiod,neighbours))
    Minz=0
    preds=0
    
    for i=size-1 downto 0  do
    MDataPrime3=abs(MdataPrime1-MdataPrime1[i])+abs(MdataPrime2-MdataPrime2[i])
    if MdataPrime3>Minz then
    Minz=MdataPrime3
    Preds=class[i]+Preds
    endif
    next
    
    MdataPrediction=Preds*5
    MdataSmoothed=average[smooth](MdataPrediction)
    
    small=lowest[size](MdataSmoothed)
    big=highest[size](MdataSmoothed)
    
    if MdataPrediction>0 then
    which=small
    backgroundcolor("green",50)
    else
    which=big
    backgroundcolor("red",50)
    endif
    //---------------------------------------------------------//
    if MdataPrediction > MdataSmoothed then
    drawcandle(MdataPrediction,MdataPrediction,MdataSmoothed,MdataSmoothed)coloured("lightgreen")
    else
    drawcandle(MdataPrediction,MdataPrediction,MdataSmoothed,MdataSmoothed)coloured("red")
    endif
    //---------------------------------------------------------//
    return MDataPrime2 coloured("lightblue"),MDataPrime1 coloured("red"), 0 as "Zero" style(dottedline2)
    
    #235473 quote
    supertiti
    Participant
    Master

    un problema en el codigo con short and long period 14 y 26 …

    un saludo

    #235480 quote
    Iván González
    Moderator
    Master

    Non capisco… copia/incolla e basta…

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

traduzione codice TW Machine Learning Momentum


ProBuilder: Indicatori & Strumenti Personalizzati

New Reply
Author
author-avatar
Msport71 @carlo-pasca Participant
Summary

This topic contains 15 replies,
has 5 voices, and was last updated by supertiti
1 year, 6 months ago.

Topic Details
Forum: ProBuilder: Indicatori & Strumenti Personalizzati
Language: Italian
Started: 06/10/2024
Status: Active
Attachments: 1 files
Logo Logo
Loading...