permanent regression line and spread

Forums ProRealTime English forum ProBuilder support permanent regression line and spread

Viewing 7 posts - 1 through 7 (of 7 total)
  • #247567

    Hi,

    This is the DJI index since 1928 with a regression line (red) till today.

    I would like to make this line “permanent” and chart the spread between the index price and the regression line.

    thank you

    #247598

    Hi. You can calculate de linear regression and the spread like this:

    If you want print the regression line in the last bar you could use this code:

    1 user thanked author for this post.
    #247635

    thanks but I need to have a fixed starting date. Ex 19281031

    The regression line shown in the chart (illustration) basically is like a “money market” with an average compounded return..

    since I can know the coordinates of two points  ex:  date and  value,  because I can measure them in the chart,  it can become a “permanent line” and once in a while…   I can change change the second point.

    Then I can calculate the spread between the closing price and such line..

    makes sense to you?

    I tried like this to start with but…    it says  x1,y1  is undefined..

    DRAWLINE(x1,y1,x2,y2)
    xl=date=19283110
    yl=252
    x2=date=1980831
    y2=2781.78
    DRAWLINE(x1,y1,x2,y2)
    return

     

     

    #247643

    For example, if you have 5k sails loaded, there will actually be 5499 sails. You can put a lookback=5499

    Your code doesn’t work because x can’t be a date, it’s a barindex.

    for example you could locate the candle that meets opendate=20241208 and then store the X as a barindex.

    #247659

    thanks for your help but sorry, getting confusing to me here.

    it seems mission impossible to translate a regression line drawn in the chart (see illustration) into a script, formula   which i can use to calculate such spread

    there are many things great about prorealtime but others which seems hard to figure out.

    #247660

    Just a few comments on  earlier example with DRAWLINE

    Your example uses DRAWLINE twice, the first time appears being used before defining x1, this will triggered the ‘undefinrd’ error. (x1 doesn’t = a value, it still = UNDEFINED)

    You cannot enter a date directly for x1 and x2 in DRAW commands however, take a look at the DATETOBARINDEX( YYYYMMDDhhmmss )  command.

    This command retrieves the barindex value that relates to the date/time set in the brackets.

    The value received is not available to use as a variable, and the (date/time) doesn’t need all the date/time but all options start from the YYYY side.

    ex.

    x1 = 20241201

    y1 = 252

    x2 = 20250501

    y2 = 2781.78

    DRAWLINE(DATETOBARINDEX(x1), y1, DATETOBARINDEX(x2), y2)

    One note, the dates need to be covered by the historical bars of the chart.

    Not sure if this is helpful in you bigger problem, but just thought I’d point it out as a reference.

    1 user thanked author for this post.
    #247811

    thank you,  I’ll give a try

Viewing 7 posts - 1 through 7 (of 7 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login