CPR and Pivot points conversion from Tradingview

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #143245 quote
    edrajs
    Participant
    New

    Salut Nicolas,

    I tried with my limited programming knowledge to create new indicators for CPR and Pivot points with formulas. It didn’t work out.

    Appreciate your help in converting this code for CPR and Pivot points from TradingView.

    For the pivot points only daily, weekly and monthly are enough. Please ignore other pivots in the code, as I was not sure which one to delete.

    study(title="Pivot Range", shorttitle="CD_PivotR", overlay=true) 
    sd = input(true, title="Show Daily Pivots?")
    
    //Pivot Range Calculations - Mark Fisher
    pivot = (high + low + close ) / 3.0 
    bc = (high + low ) / 2.0 
    tc = (pivot - bc) + pivot
    
    //Daily Pivot Range 
    dtime_pivot = security(tickerid, 'D', pivot[1]) 
    dtime_bc = security(tickerid, 'D', bc[1]) 
    dtime_tc = security(tickerid, 'D', tc[1]) 
    
    offs_daily = 0 
    plot(sd and dtime_pivot ? dtime_pivot : na, title="Daily Pivot",style=circles, color=fuchsia,linewidth=3) 
    plot(sd and dtime_bc ? dtime_bc : na, title="Daily BC",style=circles, color=blue,linewidth=3)
    plot(sd and dtime_tc ? dtime_tc : na, title="Daily TC",style=circles, color=blue,linewidth=3)
    
    study(title="CM_Pivot Points_M-W-D_4H_1H_Filtered", shorttitle="CM_Pivots_Filtered", overlay=true)
    pf = input(true,title="Show Filtered Pivots")
    sa = input(true,title="Show Pivot Average")
    sh = input(false, title="Show 1 Hour Pivots?")
    sf = input(false, title="Show 4 Hour Pivots?")
    sd = input(false, title="Show Daily Pivots?")
    sw = input(false, title="Show Weekly Pivots?")
    sm = input(true, title="Show Monthly Pivots?")
    sy = input(false, title="Show Yearly Pivots?")
    sh3 = input(false, title="Show R3 & S3 Only On 1 Hour & 4 Hour?")
    
    // Classic Pivot
    pivot = (high + low + close ) / 3.0
    // Filter Cr
    bull= pivot > (pivot + pivot[1]) / 2 + .0025
    bear= pivot < (pivot + pivot[1]) / 2 - .0025
    // Classic Pivots
    r1 = pf and bear ? pivot + (pivot - low) : pf and bull ? pivot + (high - low) : pivot + (pivot - low)
    s1 = pf and bull ? pivot - (high - pivot) : pf and bear ? pivot - (high - low) : pivot - (high - pivot)
    r2 = pf ? na : pivot + (high - low)
    s2 = pf ? na : pivot - (high - low)
    r3 = sh3 and r1 + (high - low) ? r1 + (high - low) : na
    s3 = sh3 and s1 - (high - low) ? s1 - (high - low) : na
    //Pivot Average Calculation
    smaP = sma(pivot, 3)
    
    //1 Hour Pivots
    htime_pivot = security(tickerid, '60', pivot[1])
    htime_pivotAvg = security(tickerid, '60', smaP[1])
    htime_R1 = security(tickerid, '60', r1[1])
    htime_S1 = security(tickerid, '60', s1[1])
    htime_R2 = security(tickerid, '60', r2[1])
    htime_S2 = security(tickerid, '60', s2[1])
    htime_R3 = security(tickerid, '60', r3[1])
    htime_S3 = security(tickerid, '60', s3[1])
    
    plot(sa and sh and htime_pivotAvg ? htime_pivotAvg : na, title="Hourly Pivot Average",style=cross, color=orange,linewidth=2)
    plot(sh and htime_pivot ? htime_pivot : na, title="Hourly Pivot",style=circles, color=fuchsia,linewidth=2) 
    plot(sh and htime_R1 ? htime_R1 : na, title="Hourly R1",style=circles, color=#DC143C,linewidth=2)
    plot(sh and htime_S1 ? htime_S1 : na, title="Hourly S1",style=circles, color=lime,linewidth=2)
    plot(sh and htime_R2 ? htime_R2 : na, title="Hourly R2",style=circles, color=maroon,linewidth=2)
    plot(sh and htime_S2 ? htime_S2 : na, title="Hourly S2",style=circles, color=#228B22,linewidth=2)
    plot(sh and htime_R3 ? htime_R3 : na, title="Hourly R3",style=circles, color=#FA8072,linewidth=2)
    plot(sh and htime_S3 ? htime_S3 : na, title="Hourly S3",style=circles, color=#CD5C5C,linewidth=2)
    
    //4 Hour Pivots
    ftime_pivot = security(tickerid, '240', pivot[1])
    ftime_pivotAvg = security(tickerid, '240', smaP[1])
    ftime_R1 = security(tickerid, '240', r1[1]) 
    ftime_S1 = security(tickerid, '240', s1[1])
    ftime_R2 = security(tickerid, '240', r2[1]) 
    ftime_S2 = security(tickerid, '240', s2[1])
    ftime_R3 = security(tickerid, '240', r3[1]) 
    ftime_S3 = security(tickerid, '240', s3[1])
    
    plot(sa and sf and ftime_pivotAvg ? ftime_pivotAvg : na, title="4 Hour Pivot Average",style=cross, color=orange,linewidth=2)
    plot(sf and ftime_pivot ? ftime_pivot : na, title="4 Hour Pivot",style=circles, color=fuchsia,linewidth=3) 
    plot(sf and ftime_R1 ? ftime_R1 : na, title="4 Hour R1",style=circles, color=#DC143C,linewidth=3) 
    plot(sf and ftime_S1 ? ftime_S1 : na, title="4 Hour S1",style=circles, color=lime,linewidth=3) 
    plot(sf and ftime_R2 ? ftime_R2 : na, title="4 Hour R2",style=circles, color=maroon,linewidth=3) 
    plot(sf and ftime_S2 ? ftime_S2 : na, title="4 Hour S2",style=circles, color=#228B22,linewidth=3) 
    plot(sf and ftime_R3 ? ftime_R3 : na, title="4 Hour R3",style=circles, color=#FA8072,linewidth=3) 
    plot(sw and ftime_S3 ? ftime_S3 : na, title="4 Hour S3",style=circles, color=#CD5C5C,linewidth=3)
    
    //Daily Pivots 
    dtime_pivot = security(tickerid, 'D', pivot[1])
    dtime_pivotAvg = security(tickerid, 'D', smaP[1])
    dtime_r1 = security(tickerid, 'D', r1[1]) 
    dtime_s1 = security(tickerid, 'D', s1[1]) 
    dtime_r2 = security(tickerid, 'D', r2[1]) 
    dtime_s2 = security(tickerid, 'D', s2[1])
    
    offs_daily = 0
    plot(sa and sd and dtime_pivotAvg ? dtime_pivotAvg : na, title="Daily Pivot Average",style=cross, color=orange,linewidth=2)
    plot(sd and dtime_pivot ? dtime_pivot : na, title="Daily Pivot",style=circles, color=fuchsia,linewidth=3) 
    plot(sd and dtime_r1 ? dtime_r1 : na, title="Daily R1",style=circles, color=#DC143C,linewidth=3) 
    plot(sd and dtime_s1 ? dtime_s1 : na, title="Daily S1",style=circles, color=lime,linewidth=3) 
    plot(sd and dtime_r2 ? dtime_r2 : na, title="Daily R2",style=circles, color=maroon,linewidth=3) 
    plot(sd and dtime_s2 ? dtime_s2 : na, title="Daily S2",style=circles, color=#228B22,linewidth=3) 
    
    //Weekly Pivots 
    wtime_pivot = security(tickerid, 'W', pivot[1])
    wtime_pivotAvg = security(tickerid, 'W', smaP[1])
    wtime_R1 = security(tickerid, 'W', r1[1]) 
    wtime_S1 = security(tickerid, 'W', s1[1])
    wtime_R2 = security(tickerid, 'W', r2[1]) 
    wtime_S2 = security(tickerid, 'W', s2[1])
    
    plot(sa and sw and wtime_pivotAvg ? wtime_pivotAvg : na, title="Weekly Pivot Average",style=cross, color=orange,linewidth=3)
    plot(sw and wtime_pivot ? wtime_pivot : na, title="Weekly Pivot",style=circles, color=fuchsia,linewidth=4) 
    plot(sw and wtime_R1 ? wtime_R1 : na, title="Weekly R1",style=circles, color=#DC143C,linewidth=4) 
    plot(sw and wtime_S1 ? wtime_S1 : na, title="Weekly S1",style=circles, color=lime,linewidth=4) 
    plot(sw and wtime_R2 ? wtime_R2 : na, title="Weekly R2",style=circles, color=maroon,linewidth=4) 
    plot(sw and wtime_S2 ? wtime_S2 : na, title="Weekly S2",style=circles, color=#228B22,linewidth=4) 
    
    //Monthly Pivots
    mtime_pivot = security(tickerid, 'M', pivot[1])
    mtime_pivotAvg = security(tickerid, 'M', smaP[1])
    mtime_R1 = security(tickerid, 'M', r1[1])
    mtime_S1 = security(tickerid, 'M', s1[1])
    mtime_R2 = security(tickerid, 'M', r2[1])
    mtime_S2 = security(tickerid, 'M', s2[1])
    
    plot(sa and sm and mtime_pivotAvg ? mtime_pivotAvg : na, title="Monthly Pivot Average",style=cross, color=orange,linewidth=4)
    plot(sm and mtime_pivot ? mtime_pivot : na, title="Monthly Pivot",style=circles, color=fuchsia,linewidth=5)
    plot(sm and mtime_R1 ? mtime_R1 : na, title="Monthly R1",style=circles, color=#DC145C,linewidth=5)
    plot(sm and mtime_S1 ? mtime_S1 : na, title="Monthly S1",style=circles, color=lime,linewidth=5)
    plot(sm and mtime_R2 ? mtime_R2 : na, title="Monthly R2",style=circles, color=maroon,linewidth=5)
    plot(sm and mtime_S2 ? mtime_S2 : na, title="Monthly S2",style=circles, color=#228B22,linewidth=5)
    
    //Yearly Pivots
    ytime_pivot = security(tickerid, '12M', pivot[1])
    ytime_pivotAvg = security(tickerid, '12M', smaP[1])
    ytime_R1 = security(tickerid, '12M', r1[1])
    ytime_S1 = security(tickerid, '12M', s1[1])
    ytime_R2 = security(tickerid, '12M', r2[1])
    ytime_S2 = security(tickerid, '12M', s2[1])
    
    //Yearly Pivots Plots
    plot(sa and sy and ytime_pivotAvg ? ytime_pivotAvg : na, title="Yearly Pivot Average",style=cross, color=orange,linewidth=4)
    plot(sy and ytime_pivot ? ytime_pivot : na, title="Yearly Pivot",style=cross, color=fuchsia,linewidth=6) 
    plot(sy and ytime_R1 ? ytime_R1 : na, title="Yearly R1",style=cross, color=#DC143C,linewidth=6) 
    plot(sy and ytime_S1 ? ytime_S1 : na, title="Yearly S1",style=cross, color=lime,linewidth=6) 
    plot(sy and ytime_R2 ? ytime_R2 : na, title="Yearly R2",style=cross, color=maroon,linewidth=6) 
    plot(sy and ytime_S2 ? ytime_S2 : na, title="Yearly S2",style=cross, color=#228B22,linewidth=6)
    #143285 quote
    Nicolas
    Keymaster
    Master

    Please provide pictures of these indicators. Please next time follow the easy rules to ask for code conversion: Ask for a free code conversion

    #143320 quote
    edrajs
    Participant
    New

    Salut Nicolas,

    Thanks for notifying me about the conversion process.

    As required, please find attached the screenshots of the indicators.

    Kind regards

    Edwin

    daily-weekly-monthly-pivot_Tradingview.png daily-weekly-monthly-pivot_Tradingview.png CPR_Tradingview.png CPR_Tradingview.png
    #143323 quote
    edrajs
    Participant
    New

    Nicolas,

    in case you need, here is the formula for CPR and pivot points.

    Formula for CPR (central pivot range)
    Pivot= (High + Low+ Close)/3
    BCPR = (High + Low)/2
    TCPR = (Pivot – BCPR) + Pivot
    (some times BCPR (Bottom CPR) can be above TCPR (Top CPR) and vice versa)

    PP (Pivot points/Central pivot) = (previous High + previous Low + previous Close) / 3
    (R1) = (2 x PP) – Low
    (S1) = (2 x PP) – High
    (R2) = PP + (High – Low)
    (S2) = PP – (High – Low)
    (R3) = High + 2(PP – Low)
    (S3) = Low – 2(High – PP)
    Same formula for daily/ weekly/monthly/yearly pivots.

    #143343 quote
    Nicolas
    Keymaster
    Master

    Ok for CPR, but what are the differences with the classic pivot points for the second code? They are all available in the platform (daily,weekly,monthy,yearly,..).

    #143412 quote
    edrajs
    Participant
    New

    ok, CPR Will do for now. I find difference between Tradingview and PRT pivot points, thats why I asked. I understand the price levels could be different for each platform. Please forget the pivot points for now.

    #144472 quote
    edrajs
    Participant
    New

    Hi Nicolas,

    Hope you had sometime to convert the CPR indicator for PRT. Currently I am using Tradingview in addition to PRT, which is not convenient having to switch between applications frequently.

    Thanks for your help

    #144503 quote
    Nicolas
    Keymaster
    Master

    Thought it was ok, since you posted the code in your previous post?

    CPR pivot formula:

    Pivot= (High + Low+ Close)/3
    BCPR = (High + Low)/2
    TCPR = (Pivot – BCPR) + Pivot
    
    return bcpr,tcpr
    #144592 quote
    edrajs
    Participant
    New

    Nicolas,

    Thanks for the code. I am happy to know that I was not different initially. But As you see from the screenshot, it is very much different to the Tradingview CPR.

    How to bring it to the price chart, and shown horizontal lines that draws continuously as the price changes. This is the piece I am missing.

    DAX-2-minutes.png DAX-2-minutes.png
    #144624 quote
    Nicolas
    Keymaster
    Master

    So to be the same as the code from TV, the code should be this one: (apply it on the price chart by using the wrench on the left upper side of the price chart).

    Pivot= (dHigh(1) + dLow(1)+ dClose(1))/3
    BCPR = (dHigh(1) + dLow(1))/2
    TCPR = (Pivot - BCPR) + Pivot
    
    return pivot coloured(255,0,255), bcpr coloured(0,0,255),tcpr coloured(0,0,255)
    #144911 quote
    edrajs
    Participant
    New

    Thank you Nicolas for the great support. There is still a difference of about 10 points between PRT and TV where the CPR and pivot points are plotted on the chart. I will have to manage this.

    #144942 quote
    Nicolas
    Keymaster
    Master

    Because of different market hours, different OHLC data, ..

    #171966 quote
    bharathr15
    Participant
    Average

    Hi Nicolas,

    Thank you very much for your support, Shall I get ITF file because, during copy paste I am getting error.

    #174759 quote
    oyinloyea
    Participant
    Veteran

    Good Day. This formula is not stable on Intraday Timeframes.

    Capture-1.jpg Capture-1.jpg
    #176928 quote
    Sakhalin
    Participant
    New

    Salut Nicolas

    Je suis néophyte dans la programmation. J’ai le CPR en journée mais coment faire pour en créer un en 4H? J’ai essayé de remplacer le “d” par 4H etc.. sans succés. Tes lumières sont les bienvenues

    merci

    Hi Nicolas I am new to programming. I have the CPR during the day, but how can I create one in 4 hours? I tried to replace the “d” with 4H etc. without success. Your lights are welcome thank you

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

CPR and Pivot points conversion from Tradingview


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
edrajs @edrajs Participant
Summary

This topic contains 15 replies,
has 6 voices, and was last updated by robertogozzi
4 years, 5 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 09/02/2020
Status: Active
Attachments: 4 files
Logo Logo
Loading...