Codificare questo indicatore

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #181535 quote
    m3rc76m3rc76
    Participant
    New

    Secondo voi è possibile codificare questo indicatore da trading view?

    //@version=4
    study(title=”Rolling Moving Average”, shorttitle=”MA_rolling”, overlay=true)
    len = input(9, minval=1, title=”Length”)
    src = input(close, title=”Source”)
    ma_type = input(options=[“SMA”,”EMA”], defval=”SMA”, title=”type”)

    roll_sma(x, y) =>
    sum = 0.0
    for i = 0 to y – 1
    sum := sum + x[i] / y
    sum

    roll_ema(x, y) =>
    alpha = 2 / (y + 1)
    sum = 0.0
    sum := alpha * x + (1 – alpha) * nz(sum[1])

    var roll_sma_len = 0

    roll_sma_len := roll_sma_len + 1

    out1 = ma_type==”SMA” ? sma(src,len) : ema(src,len)
    out2 = ma_type==”SMA” ? roll_sma(src,roll_sma_len) : roll_ema(src,roll_sma_len)

    out = bar_index+1 <= len ? out2 : out1

    plot(out, color=#00FF00, title="MA")

    #181661 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    E’ identico ad una SMA o EMA, cambia qualcosa solo per i primi periodi iniziali:

    ONCE Periods = 9                //9  periods
    ONCE MaType  = 0                //0=SMA,  1=EMA
    ONCE N       = Periods
    src          = CustomClose
    N            = N + 1
    IF MaType = 0 THEN
       Out1 = average[Periods,0](src)
       Out2 = 0
       FOR i = 0 TO N- 1
          Out2 = (Out2 + src[i]) / N
       NEXT
    ELSIF MaType = 1 THEN
       Out1  = average[Periods,1](src)
       Out2  = 0
       alpha = 2 / (N + 1)
       Out2  = (alpha * src) + ((1 - alpha) * Out2[1])
    ENDIF
    IF BarIndex <= Periods THEN
       OutX = Out2
    ELSE
       OutX = Out1
    ENDIF
    RETURN OutX AS "Rolling Moving Average"
    m3rc76 thanked this post
Viewing 2 posts - 1 through 2 (of 2 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

Codificare questo indicatore


ProBuilder: Indicatori & Strumenti Personalizzati

New Reply
Author
author-avatar
m3rc76 @m3rc76 Participant
Summary

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

Topic Details
Forum: ProBuilder: Indicatori & Strumenti Personalizzati
Language: Italian
Started: 11/13/2021
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...