Last active
February 25, 2023 03:48
-
-
Save juanmirocks/c914bd78dd43e910c5e76f12ceb875f4 to your computer and use it in GitHub Desktop.
Pine Script for a TradingView indicator: Pivot Points
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // @version=3 | |
| // | |
| // Pivot Points indicator, calculated in the "traditional" way, also called "floor-trader pivots". | |
| // | |
| // Additionally, and optional to the user, the halves between the key levels are also shown. | |
| // | |
| // The Default chosen Time Frame to calculate the pivot points is: | |
| // Daily (D) if within intraday | |
| // Weekly (W) if within daily chart | |
| // Monthly (M) if within weekly chart | |
| // 3 Months (3M) if within monthly chart | |
| // | |
| // | |
| // # Advantages over TV's indicator "Pivot Points Standard" | |
| // 1. Show pivot lines for all history, which lets you gauge trading strategies throughout time | |
| // 2. More sensible Default/Auto time frame; e.g. on intradays only and always the market values of yesterday's Day are used | |
| // 3. The halves between the key levels are also shown, which it's useful for some trading strategies | |
| // 4. Arguably out-of-the-box nicer interface | |
| // | |
| // | |
| // | |
| // Author: Juan Miguel Cejuela (@juanmirocks) | |
| // Source: https://gist.github.com/juanmirocks/c914bd78dd43e910c5e76f12ceb875f4 | |
| // Updated: 2019-05-16 | |
| // | |
| study(title="Pivot Points, by @juanmirocks", shorttitle="PP", overlay=true) | |
| defaultTimeFrame = ((isintraday) ? "D" : ((isdaily) ? "W" : ((isweekly) ? "M" : "3M"))) | |
| inputTimeFrame = input(title="Time Frame", type=string, defval="Default") | |
| chosenTimeFrame = (inputTimeFrame == "Default") ? defaultTimeFrame : inputTimeFrame | |
| getSeries(e) => security(tickerid, chosenTimeFrame, e, lookahead=barmerge.lookahead_on) | |
| H = getSeries(high[1]) | |
| L = getSeries(low[1]) | |
| C = getSeries(close[1]) | |
| // Main Pivot | |
| P = (H + L + C) / 3 | |
| // Resistence Levels | |
| R3 = H + 2*(P - L) | |
| R2 = P + (H - L) | |
| R1 = (P * 2) - L | |
| // Support Levels | |
| S1 = (P * 2) - H | |
| S2 = P - (H - L) | |
| S3 = L - 2*(H - P) | |
| // Optional Halves between levels | |
| R2_5 = (R2 + R3) / 2 //aka R2.5 | |
| R1_5 = (R1 + R2) / 2 //aka R1.5 | |
| R0_5 = (P + R1) / 2 //aka R0.5 | |
| // | |
| S0_5 = (P + S1) / 2 //aka S0.5 | |
| S1_5 = (S1 + S2) / 2 //aka S1.5 | |
| S2_5 = (S2 + S3) / 2 //aka S2.5 | |
| //UX Input Arguments | |
| pColor = #ffa100 | |
| rColor = green | |
| sColor = red | |
| myWidthMainLevels = input(title="Line width for Main levels", type=integer, defval=3, minval=1) | |
| myWidthHalfLevels = input(title="Line width for Half levels", type=integer, defval=1, minval=1) | |
| myStyle = linebr | |
| plot(R3, title="R3", color=rColor, linewidth=myWidthMainLevels, style=myStyle) | |
| plot(R2_5, title="R2.5", color=rColor, linewidth=myWidthHalfLevels, style=myStyle) | |
| plot(R2, title="R2", color=rColor, linewidth=myWidthMainLevels, style=myStyle) | |
| plot(R1_5, title="R1.5", color=rColor, linewidth=myWidthHalfLevels, style=myStyle) | |
| plot(R1, title="R1", color=rColor, linewidth=myWidthMainLevels, style=myStyle) | |
| plot(R0_5, title="R0.5", color=rColor, linewidth=myWidthHalfLevels, style=myStyle) | |
| plot(P, title="P", color=pColor, linewidth=myWidthMainLevels, style=myStyle) | |
| plot(S0_5, title="S0.5", color=sColor, linewidth=myWidthHalfLevels, style=myStyle) | |
| plot(S1, title="S1", color=sColor, linewidth=myWidthMainLevels, style=myStyle) | |
| plot(S1_5, title="S1.5", color=sColor, linewidth=myWidthHalfLevels, style=myStyle) | |
| plot(S2, title="S2", color=sColor, linewidth=myWidthMainLevels, style=myStyle) | |
| plot(S2_5, title="S2.5", color=sColor, linewidth=myWidthHalfLevels, style=myStyle) | |
| plot(S3, title="S3", color=sColor, linewidth=myWidthMainLevels, style=myStyle) |
Error: Undeclared identifier barmerge.lookahead_on
how can i solve this error!
I'm not getting this error...
Can you tell me how this plotting for previous days, what is doing that to plot history? (I thought it will only plot for the current day) Thanks..
Hi,
I wanted to add 5 levels to Pivot Point Standard - Fibonacci but currently there are only 3 levels.
Can you please help me out with pine script as I am not an IT person?
I found some code on Trading view about Fibonacci pivots but I don't know how to add two more levels which are 0.236 and 0.786
PP = (HIGHprev + LOWprev + CLOSEprev) / 3
R1 = PP + 0.382 * (HIGHprev - LOWprev)
S1 = PP - 0.382 * (HIGHprev - LOWprev)
R2 = PP + 0.618 * (HIGHprev - LOWprev)
S2 = PP - 0.618 * (HIGHprev - LOWprev)
R3 = PP + (HIGHprev - LOWprev)
S3 = PP - (HIGHprev - LOWprev)
Thanks
Hi,
I'm not an IT person too ππ
Just see what for example R1 and S1 is, what the difference is, and where
R1 and S1 is used further in the script.
When you figure this out, you can create a separate 0.236 & 0.786 level
(for example R4 , S4 & R5, S5)
Good luck!
Op vr 1 jan. 2021 om 17:54 schreef dockapil <notifications@github.com>:
β¦ ***@***.**** commented on this gist.
------------------------------
Hi,
I wanted to add 5 levels to Pivot Point Standard - Fibonacci but currently
there are only 3 levels.
Can you please help me out with pine script as I am not an IT person?
I found some code on Trading view about Fibonacci pivots but I don't know
how to add two more levels which are 0.236 and 0.786
PP = (HIGHprev + LOWprev + CLOSEprev) / 3
R1 = PP + 0.382 * (HIGHprev - LOWprev)
S1 = PP - 0.382 * (HIGHprev - LOWprev)
R2 = PP + 0.618 * (HIGHprev - LOWprev)
S2 = PP - 0.618 * (HIGHprev - LOWprev)
R3 = PP + (HIGHprev - LOWprev)
S3 = PP - (HIGHprev - LOWprev)
Thanks
β
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<https://gist.github.com/c914bd78dd43e910c5e76f12ceb875f4#gistcomment-3579254>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AN7P6USTRF6MRMDE4U3SMXLSXX44XANCNFSM4I6P5HUQ>
.
hello do you have the code to remove pivot history cordially
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello!
Is it available for MT4 platform? That would be very useful to me.