Nadaraya Watson Indicator not working well on some charts

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #203178 quote
    Mary
    Participant
    Average

    Hello, I have this indicator (please see code below) Nadaraya Watson Indicator and on most daily charts it plots just fine, but some charts on Daily time frame, box pops up with Error Message:

    ” Error in the indicator: Nadaraya Watson
    A positive integer field is expected with $a”

    Daily Units I have set to 1k.  For example ticker METHUSDXXXX , this indicator is refusing to draw, but other futures and stocks it draws just fine .

    As well this indicator Does Not Draw at all on ALL Weekly charts, even if units amount is set to 100 units.

    Any idea how to fix this? I am using the stable version of Prorealtime end of day data v11.1

    This is the code:

    //Nadaraya-Watson Envelope
    defparam drawonlastbaronly = true
    length = 500//Window Size
    hh = 8 //Bandwidth
    mult = .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)
    //if close[barindex-i] > ($a[barindex-i]+mae) then // and src[1]<y2[1]+mae then
    //drawarrowdown(barindex-i,high) coloured(“red”)
    //endif
    //if close[barindex-i] < ($a[barindex-i]-mae) then //and src[1]>y2[1]-mae then
    //drawarrowup(barindex-i,low) coloured(“green”)
    //endif
    next
    /*drawpoint(barindex,y2,1)
    drawpoint(barindex,y2+mae,1)
    drawpoint(barindex,y2-mae,1)*/
    Y2High=$a[barindex]+mae
    Y2Low=$a[barindex]-mae

    endif
    return y2,y2+mae,y2-mae

    #203180 quote
    JS
    Participant
    Senior

    Hi @Mary

    Replace the second line in the code with:

    length = Min(500,BarIndex)

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

Nadaraya Watson Indicator not working well on some charts


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Mary @mila Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by JS
3 years, 3 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 10/29/2022
Status: Active
Attachments: 1 files
Logo Logo
Loading...