MA Sabres TW

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

    Ciao, chiedo la traduzione di questo indicatore:( https://www.tradingview.com/script/viwa6CR8-MA-Sabres-LuxAlgo/):

    // This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
    // © LuxAlgo

    //@version=5
    indicator(‘MA Sabres [LuxAlgo]’, shorttitle=’LuxAlgo – MA Sabres’, max_polylines_count=100, overlay=true)

    //——————————————————————————
    //Settings
    //—————————————————————————–{
    type = input.string( “TEMA” , ‘MA Type’ , group= ‘MA’
    , options = [“SMA”, “EMA”, “SMMA (RMA)”, “HullMA”, “WMA”, “VWMA”, “DEMA”, “TEMA”, “NONE”])
    len = input.int ( 50 , ‘Length’ , group= ‘MA’ )
    count = input.int ( 20 , ‘Previous Trend Duration’ , group= ‘MA’
    , tooltip = ‘Reversal after x bars in the same direction’ )
    colUp = input.color (#2962ff, ‘Bullish’ , group=’Colours’)
    colDn = input.color (#f23645, ‘Bearish’ , group=’Colours’)
    colMa = input.color (#787b86, ‘MA’ , group=’Colours’)

    //—————————————————————————–}
    //Method MA
    //—————————————————————————–{
    method ma(string type, int length) =>
    //
    ema1 = ta.ema(close, length)
    ema2 = ta.ema(ema1 , length)
    ema3 = ta.ema(ema2 , length)
    //
    switch type
    “SMA” => ta.sma (close, length)
    “EMA” => ema1
    “SMMA (RMA)” => ta.rma (close, length)
    “HullMA” => ta.hma (close, length)
    “WMA” => ta.wma (close, length)
    “VWMA” => ta.vwma(close, length)
    “DEMA” => 2 * ema1 – ema2
    “TEMA” => (3 * ema1) – (3 * ema2) + ema3
    => na

    //—————————————————————————–}
    //Calculations
    //—————————————————————————–{
    ma = type.ma(len)
    fl = ta.falling(ma , count)
    rs = ta.rising (ma , count)
    up = fl[1] and ma > ma[1]
    dn = rs[1] and ma < ma[1]
    atr = ta.atr(14)
    n = bar_index

    //—————————————————————————–}
    //Execution
    //—————————————————————————–{
    if up
    p = array.new<chart.point>()
    p.push(chart.point.from_index(n – 1 , low [1] – atr / 15 ))
    p.push(chart.point.from_index(n + (len / 2 -1) , low [1] + atr / 2.5))
    p.push(chart.point.from_index(n + len , low [1] + atr * 2 ))
    p.push(chart.point.from_index(n + (len / 2 -1) , low [1] + atr / 2.5))
    p.push(chart.point.from_index(n – 1 , low [1] + atr / 15 ))
    polyline.new(p
    , curved = true
    , closed = false
    , line_color = colUp
    , fill_color = color.new(colUp, 50))

    if dn
    p = array.new<chart.point>()
    p.push(chart.point.from_index(n – 1 , high[1] + atr / 15 ))
    p.push(chart.point.from_index(n + (len / 2 -1) , high[1] – atr / 2.5))
    p.push(chart.point.from_index(n + len , high[1] – atr * 2 ))
    p.push(chart.point.from_index(n + (len / 2 -1) , high[1] – atr / 2.5))
    p.push(chart.point.from_index(n – 1 , high[1] – atr / 15 ))
    polyline.new(p
    , curved = true
    , closed = false
    , line_color = colDn
    , fill_color = color.new(colDn, 50))

    //—————————————————————————–}
    //Plots
    //—————————————————————————–{
    plot (ma , ‘MA’ , color= colMa )

    plotshape(up ? low [1] : na, ”, color= colUp , location=location.absolute, style=shape.circle, size=size.tiny , offset=-1)
    plotshape(up ? low [1] : na, ”, color=color.new(colUp, 50), location=location.absolute, style=shape.circle, size=size.small , offset=-1)
    plotshape(up ? low [1] : na, ”, color=color.new(colUp, 65), location=location.absolute, style=shape.circle, size=size.normal, offset=-1)

    plotshape(dn ? high[1] : na, ”, color= colDn , location=location.absolute, style=shape.circle, size=size.tiny , offset=-1)
    plotshape(dn ? high[1] : na, ”, color=color.new(colDn, 50), location=location.absolute, style=shape.circle, size=size.small , offset=-1)
    plotshape(dn ? high[1] : na, ”, color=color.new(colDn, 65), location=location.absolute, style=shape.circle, size=size.normal, offset=-1)

    //—————————————————————————–}

    #241267 quote
    Ciccarelli FrancoCiccarelli Franco
    Participant
    Senior

    Si può avere anche uno scrinner?

    Grazie

    #241271 quote
    Iván GonzálezIván González
    Moderator
    Legend

    Eccolo qui:

    //-------------------------------------//
    //PRC_MA Sabres
    //version = 0
    //09.12.2024
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    //-------------------------------------//
    // Inputs
    //-------------------------------------//
    len=50
    count=20
    UseTEMA=1
    MaType=2
    //-------------------------------------//
    //Method MA
    //-------------------------------------//
    if UseTEMA then
    ma=tema[len](close)
    else
    ma=average[len,MaType](close)
    endif
    //-------------------------------------//
    //Calculations
    //-------------------------------------//
    // MA falling
    if ma<=lowest[count](ma) then
    fl=1
    else
    fl=0
    endif
    up=fl[1] and ma>ma[1]
    // MA rising
    if ma>=highest[count](ma) then
    rs=1
    else
    rs=0
    endif
    dn=rs[1] and ma<ma[1]
    //ATR calculation
    atr=averagetruerange[14](close)
    n=barindex
    //-------------------------------------//
    //Calculations
    //-------------------------------------//
    if up and summation[len](up)=1 then
    // Puntos fijos
    xx1 = n-1
    xx9 = n+len
    yy1 = low[1] - atr / 15
    yy9 = low[1] + atr * 2
    
    // Calcular los puntos intermedios en X (división uniforme)
    xx2 = xx1 + (xx9 - xx1) * 1 / 8
    xx3 = xx1 + (xx9 - xx1) * 2 / 8
    xx4 = xx1 + (xx9 - xx1) * 3 / 8
    xx5 = xx1 + (xx9 - xx1) * 4 / 8
    xx6 = xx1 + (xx9 - xx1) * 5 / 8
    xx7 = xx1 + (xx9 - xx1) * 6 / 8
    xx8 = xx1 + (xx9 - xx1) * 7 / 8
    
    // Ecuación cuadrática para Y (emular parábola)
    aa = (yy9 - yy1) / pow((xx9 - xx1), 2) // Calcular el coeficiente de la parábola
    yy2 = yy1 + aa * pow((xx2 - xx1), 2)
    yy3 = yy1 + aa * pow((xx3 - xx1), 2)
    yy4 = yy1 + aa * pow((xx4 - xx1), 2)
    yy5 = yy1 + aa * pow((xx5 - xx1), 2)
    yy6 = yy1 + aa * pow((xx6 - xx1), 2)
    yy7 = yy1 + aa * pow((xx7 - xx1), 2)
    yy8 = yy1 + aa * pow((xx8 - xx1), 2)
    
    // Dibujar segmentos
    drawsegment(xx1,yy1,xx2,yy2)coloured("blue")
    drawsegment(xx3,yy3,xx2,yy2)coloured("blue")
    drawsegment(xx3,yy3,xx4,yy4)coloured("blue")
    drawsegment(xx5,yy5,xx4,yy4)coloured("blue")
    drawsegment(xx5,yy5,xx6,yy6)coloured("blue")
    drawsegment(xx7,yy7,xx6,yy6)coloured("blue")
    drawsegment(xx7,yy7,xx8,yy8)coloured("blue")
    drawsegment(xx9,yy9,xx8,yy8)coloured("blue")
    
    //DrawPoints
    drawpoint(xx1,yy1,1)coloured("blue")
    drawpoint(xx1,yy1,3)coloured("blue",70)
    drawpoint(xx1,yy1,5)coloured("blue",30)
    endif
    
    if dn and summation[len](dn) = 1 then
    // Puntos fijos
    x1 = n-1
    x9 = n+len
    y1 = high[1] + atr / 15
    y9 = high[1] - atr * 2
        
    // Calcular los puntos intermedios en X (división uniforme)
    x2 = x1 + (x9 - x1) * 1 / 8
    x3 = x1 + (x9 - x1) * 2 / 8
    x4 = x1 + (x9 - x1) * 3 / 8
    x5 = x1 + (x9 - x1) * 4 / 8
    x6 = x1 + (x9 - x1) * 5 / 8
    x7 = x1 + (x9 - x1) * 6 / 8
    x8 = x1 + (x9 - x1) * 7 / 8
        
    // Ecuación cuadrática para Y (emular parábola)
    a = (y9 - y1) / pow((x9 - x1), 2) // Calcular el coeficiente de la parábola
    y2 = y1 + a * pow((x2 - x1), 2)
    y3 = y1 + a * pow((x3 - x1), 2)
    y4 = y1 + a * pow((x4 - x1), 2)
    y5 = y1 + a * pow((x5 - x1), 2)
    y6 = y1 + a * pow((x6 - x1), 2)
    y7 = y1 + a * pow((x7 - x1), 2)
    y8 = y1 + a * pow((x8 - x1), 2)
      
    // Dibujar segmentos
    drawsegment(x1,y1,x2,y2)coloured("red")
    drawsegment(x3,y3,x2,y2)coloured("red")
    drawsegment(x3,y3,x4,y4)coloured("red")
    drawsegment(x5,y5,x4,y4)coloured("red")
    drawsegment(x5,y5,x6,y6)coloured("red")
    drawsegment(x7,y7,x6,y6)coloured("red")
    drawsegment(x7,y7,x8,y8)coloured("red")
    drawsegment(x9,y9,x8,y8)coloured("red")
    
    //DrawPoints
    drawpoint(x1,y1,1)coloured("red")
    drawpoint(x1,y1,3)coloured("red",70)
    drawpoint(x1,y1,5)coloured("red",30)
    endif
    return ma as "Moving Average" coloured("Grey")style(line,2)
Viewing 3 posts - 1 through 3 (of 3 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

MA Sabres TW


ProBuilder: Indicatori & Strumenti Personalizzati

New Reply
Author
author-avatar
Stenozar @stenozar Participant
Summary

This topic contains 2 replies,
has 3 voices, and was last updated by Iván GonzálezIván González
1 year, 9 months ago.

Topic Details
Forum: ProBuilder: Indicatori & Strumenti Personalizzati
Language: Italian
Started: 12/08/2024
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...