Price Displacement - Candlestick (OHLC) CalculationsA Magical little helper friend for Candle Math.
When composing scripts, it is often necessary to manipulate the math around the OHLC. At times, you want a scalar (absolute) value others you want a vector (+/-). Sometimes you want the open - close and sometimes you want just the positive number of the body size. You might want it in ticks or you might want it in points or you might want in percentages. And every time you try to put it together you waste precious time and brain power trying to think about how to properly structure what you're looking for. Not to mention it's normally not that aesthetically pleasing to look at in the code.
So, this fixes all of that.
Using this library. A function like 'pd.pt(_exp)' can call any kind of candlestick math you need. The function returns the candlestick math you define using particular expressions.
Candle Math Functions Include:
Points:
pt(_exp) Absolute Point Displacement. Point quantity of given size parameters according to _exp.
vpt(_exp) Vector Point Displacement. Point quantity of given size parameters according to _exp.
Ticks:
tick(_exp) Absolute Tick Displacement. Tick quantity of given size parameters according to _exp.
vtick(_exp) Vector Tick Displacement. Tick quantity of given size parameters according to _exp.
Percentages:
pct(_exp, _prec) Absolute Percent Displacement. (w/rounding overload). Percent quantity of bar range of given size parameters according to _exp.
vpct(_exp, _prec) Vector Percent Displacement (w/rounding overload). Percent quantity of bar range of given size parameters according to _exp.
Expressions You Can Use with Formulas:
The expressions are simple (simple strings that is) and I did my best to make them sensible, generally using just the ohlc abreviations. I also included uw, lw, bd, and rg for when you're just trying to pull a candle component out. That way you don't have to think about which of the ohlc you're trying to get just use pd.tick("uw") and now the variable is assigned the length of the upper wick, absolute value, in ticks. If you wanted the vector in pts its pd.vpt("uw"). It also makes changing things easy too as I write it out.
Expression List:
Combinations
"oh" = open - high
"ol" = open - low
"oc" = open - close
"ho" = high - open
"hl" = high - low
"hc" = high - close
"lo" = low - open
"lh" = low - high
"lc" = low - close
"co" = close - open
"ch" = close - high
"cl" = close - low
Candle Components
"uw" = Upper Wick
"bd" = Body
"lw" = Lower Wick
"rg" = Range
Pct() Only
"scp" = Scalar Close Position
"sop" = Scalar Open Position
"vcp" = Vector Close Position
"vop" = Vector Open Position
The attributes are going to be available in the pop up dialogue when you mouse over the function, so you don't really have to remember them. I tried to make that look as efficient as possible. You'll notice it follows the OHLC pattern. Thus, "oh" precedes "ho" (heyo) because "O" would be first in the OHLC. Its a way to help find the expression you're looking for quickly. Like looking through an alphabetized list for traders.
There is a copy/paste console friendly helper list in the script itself.
Additional Notes on the Pct() Only functions:
This is the original reason I started writing this. These concepts place a rating/value on the bar based on candle attributes in one number. These formulas put a open or close value in a percentile of the bar relative to another aspect of the bar.
Scalar - Non-directional. Absolute Value.
Scalar Position: The position of the price attribute relative to the scale of the bar range (high - low)
Example: high = 100. low = 0. close = 25.
(A) Measure price distance C-L. How high above the low did the candle close (e.g. close - low = 25)
(B) Divide by bar range (high - low). 25 / (100 - 0) = .25
Explaination: The candle closed at the 25th percentile of the bar range given the bar range low = 0 and bar range high = 100.
Formula: scp = (close - low) / (high - low)
Vector = Directional.
Vector Position: The position of the price attribute relative to the scale of the bar midpoint (Vector Position at hl2 = 0)
Example: high = 100. low = 0. close = 25.
(A) Measure Price distance C-L: How high above the low did the candle close (e.g. close - low = 25)
(B) Measure Price distance H-C: How far below the high did the candle close (e.g. high - close = 75)
(C) Take Difference: A - B = C = -50
(D) Divide by bar range (high - low). -50 / (100 - 0) = -0.50
Explaination: Candle close at the midpoint between hl2 and the low.
Formula: vcp = { / (high - low) }
Thank you for checking this out. I hope no one else has already done this (because it took half the day) and I hope you find value in it. Be well. Trade well.
Library "PD"
Price Displacement
pt(_exp) Absolute Point Displacement. Point quantity of given size parameters according to _exp.
Parameters:
_exp : (string) Price Parameter
Returns: Point size of given expression as an absolute value.
vpt(_exp) Vector Point Displacement. Point quantity of given size parameters according to _exp.
Parameters:
_exp : (string) Price Parameter
Returns: Point size of given expression as a vector.
tick(_exp) Absolute Tick Displacement. Tick quantity of given size parameters according to _exp.
Parameters:
_exp : (string) Price Parameter
Returns: Tick size of given expression as an absolute value.
vtick(_exp) Vector Tick Displacement. Tick quantity of given size parameters according to _exp.
Parameters:
_exp : (string) Price Parameter
Returns: Tick size of given expression as a vector.
pct(_exp, _prec) Absolute Percent Displacement (w/rounding overload). Percent quantity of bar range of given size parameters according to _exp.
Parameters:
_exp : (string) Expression
_prec : (int) Overload - Place value precision definition
Returns: Percent size of given expression as decimal.
vpct(_exp, _prec) Vector Percent Displacement (w/rounding overload). Percent quantity of bar range of given size parameters according to _exp.
Parameters:
_exp : (string) Expression
_prec : (int) Overload - Place value precision definition
Returns: Percent size of given expression as decimal.
Ohlc
4C Daily Levels Suite + Premarket High/LowThis '4C Daily Levels Suite + Premarket High/Low' indicator is a clean way to automatically plot important daily levels including:
Prior Day High
Prior Day Low
Prior Day Close
50% level between Prior High/Low
Today's Open
Today's Premarket Low+High
This Daily Levels indicator is unique in its ability to:
-Plot all of the daily level PLUS premarket high/low levels (extended hours must be turned ON)
-Can hide past days levels, only plotting levels on the current day, to keep chart cleaner
-Can extend line levels right or fullscreen
-Plots the level price at each level on the chart
-Can show/hide price levels labels
-Can add supplemental premarket levels plot to show levels being formed during the premarket time period
-Coded with line.new vs plot so dashed lines are available as a style
-Automatically hides the indicator if the timeframe selected is Daily or greater
SEE SCREENSHOT EXAMPLES BELOW
Default mode, with extended hours showing:
With supplemental premarket plot showing:
Default mode without extended hours showing:
Showing past day’s levels
Extend lines to fullscreen
Some parts of this code were adapted from 'pd Levels' by CryptoCurl
Rolling OHLC Candles█ OVERVIEW
This indicator displays a Rolling OHLC Bars for a given timeframe Multiplier. Contrary to OHLC Charts, if the timeframe Multiplier is "5", this indicator plot OHLC of the last 5 Candles.
█ WHAT IS THE NEED FOR IT
Let's see if we want to use a Higher timeframe OHLC Data using security function or resolution options. The indicator repaints until the higher timeframe OHLC Candle closes, leading to a repainting strategy or indicator using higher-timeframe data. So we can use Rolling OHLC Candles in these cases.
█ USES
To Pull out higher timeframe OHLC Data to build a non-repainting strategy or indicator.
Prominently, traders use Heikin Ashi Candles to locate trends or trading opportunities easier than traditional candlesticks. But the OHLC in those Heikin Ashi candles doesn't match with conventional candlesticks. We can use these Rolling OHLC Candles as an alternative for Heikin Ashi Candles because Here we can locate trends or trading opportunities easier than traditional candlesticks, and also close of these candles matches the close of the standard candlesticks, which can help us to take trades based on the close of the candles.
█ WHY I AM BUILDING THIS SIMPLE INDICATOR
There is no doubt higher timeframe analysis is a critical study to mastering the markets.
I found a necessity for an indicator that analyses multiple higher timeframes and gives us a cumulative or average trend direction. I already built the indicator; I will release it soon. The Indicator I am building is wholly based on my understanding and perspective of Market Structure. Please use this indicator idea to remove the repainting issue when you make an indicator that utilises higher timeframe data.
I am using this in my upcoming indicators. Felt to share before head.
Stay Tuned...
If you have any recommendations or alternative ideas, then please drop a comment under the script ;)
Lepelle's Key LevelsCredit to original code goes to paaax and NSDT. Modified to include premarket H/L levels and to show only daily levels. Indicator includes Close levels.
-US Premarket High and Low Levels
-Daily OHL Levels (No close included)
-Yesterday and Previous day OHLC level
-Labels and ability to modify user preferences (color, line)
Previous OHLC (Nephew_Sam_)This indicator plots the OHLC of a previous HTF candle with an option to show the HTF candle too on the lower timeframe.
(uses latest pine script version 5)
Options:
1. Custom timeframe (requires a higher timeframe from current chart period)
2. Show or hide OC and/or LH lines of previous candle
3. Show or hide the candle at the beginning of the new period
Styles
1. You can style all lines and candle colors from this tab.
MILK (My Intraday Lazy Kit)I made this script to group information considered useful in forex day trading, of course it can be used on crypto or other markets.
First of all, feel free to suggest any improvement/new feature you would consider interesting for such an use. This is not especially a final version and I'm sure other relevant information can be added in this tool.
Current features are the following
An international clock showing time and session status (open/closed) for 5 different cities. You can modify it in parameters.
Drawings of previous days/weeks open/high/low/close prices, which will be often used as supports and resistances zones.
The Clock shows
City
Time (with a bgcolor corresponding to the "period" of the day (Morning, Afternoon, Evening, Night)
Session status (Cyan when the corresponding session is open, blue when it's closed)
Price levels names are
YTD-H : Yesterday's high
YTD-L : Yesterday's low
YTD-C : Yesterday's close
YTD-O : Yesterday's open
PWH : Previous week high
PWL : Previous week low
PWO : Previous week open
PWC : Previous week close
Levels width and colors can be modified.
You can also enable/disable the clock, and daily or weekly levels in the options panel.
Nothing more to say for now, I mainly integrated information I like to have, but I'll probably add new features in it if I get some.
Dynamic Fibonacci Pivot Points & EMA CrossoversI have created this script for those who face difficulties drawing Fibonacci levels as this script is Dynamic so it automatically calculates the ranges based on current High and Lows. I have also added Standard Fibonacci Pivot Points so that we can easily see the confluences between Dynamic and Standard pivot points. Apart from this I have also added EMA Crossovers so that we can easily identify trend changes. You can modify this script as per your own.
OHLC - H.D.W.MThis indicatos plots Open and Close of the Curernt and Previous Day, Week or Month. It also shows the Highs and Lows of the Hourly, Daily, Weekly and Monthly Timeframes.
OHLC-Tables New FeatureHello All,
The command shows the opening-high-low-closing-change values of that day based on the previous value in each period.
You can set the clock in any time zone you want.
You can use the indicator by adapting it wherever you want on your screen. You can adjust its position. Top-Left-Middle Left- Bottom Left/ Top Right-Middle Right- Bottom Right.
Although it is not a command with a Buy-Sell indicator, its user-friendliness and convenience were taken into account while developing it.
The purpose of the indicator is to allow you to consider the values while focusing not only on the chart you are watching.
Line Chart Enhancer by makuchakuTradingview has a good line chart, but I wanted to make it even more awesome.
Some shortcomings which this line chart enhancer script fixes
Colors up move as green, down move as red (you can change them as you like)
Plots high and low - so that one can be aware about what the price is doing
To achieve the look with markers as shown above
Goto Symbol settings > Type > Select "With Markers"
Feedback welcome!
Example - HTF Step InterpolationAbout this script:
This example aims to highlight an alternative way to view HTF data by providing basic interpolation functionality.
This script does not aim to provide use in itself as an indicator or strategy.
Reason for study:
Educational Purposes Only
mOCP - volatility metricGauge price action (volatility) of current movements against sma of historical OHCP (open/close) percent_difference.
NSDT Daily Key LevelsSimple script to show key levels of current day and previous day. Labels can be turned on and off as needed. Line colors, thickness and style can be changed. Modified the "M/W/D Level" script from paaax. Credit for original code goes to him. Link to script and profile posted in code of this script.
Yesterday's RTH&ON sessions OHLCsThe indicator plots the OHLC levels of both trading sessions of the day before: the overnight session and the Regular Trading Hours.
Previous OHLCThe scripts places horizontal levels on your charts indicating the previous Daily, Weekly or Monthly OHLC values over the current timeframe.
Slightly modified version of Nanda86's "Previous OHLC" script. I corrected a couple of bugs and added more control over colors and labels in general. I also removed the hourly OHLCs.
MrBS:EMA/SMA/HMA (Heikin Ashi Calc)This indicator allows you to base the MA calculation from Heikin Ashi values on normal charts and/or the real OHLC values while looking at Heikin Ashi.
There are 3 MA types you can select - EMA / SMA / HMA
The colour is based on the slope.
I made this to help me visualize my DMI+ strategy, when I was looking at taking signals from Heikin Ashi but looking at candlesticks. Turns out, I was going down the wrong road. Now I'm looking into using the real OHLC values for generating signals but watching the Heikin Ashi chart as I find it easier to see trends on it.
Hopefully its useful to some people, and if you have any suggestions for improvements I'd love to know.
Yesterday's open, high, low and closeA very simple script to plot the yesterday's OHLC, to be used in an intraday graph.
There were other scripts like this, but their code was ugly, filthy, smelly, and WET, so I did this.
L1 Buy after Dump DetectorLevel: 1
Background
The so-called "Buy after Dump" refers to the phenomenon in which the stock price sometimes rebounds temporarily due to the rapid decline in the falling market. The rebound was smaller than the decline, and the downtrend resumed after the rebound.
Function
L1 Buy after Dump Detector is one of my research to see win rate of a "Buy after Dump" chance. The principle is that I use ema() and OHLC to model a whale dump behavior. After the dump wave, I use KDJ to indicate several long entry points.
Key Signal
dump --> whale dump signal
fundready --> it indicate the end of a dump and make fund ready to long entry
longentry --> long entry signal generated from KDJ resonating with dump and fundready signal
Pros and Cons
Pros:
1. it can detect obvious dump and depict the decay of dump wave
2. use resonance to generate long entry
Cons:
1. it may be risky to "buy after dump" which may require take profit method here because the opportunity may be very short
2. KDJ is too sensitive in large time frame and have many long entry signals (the closer to dump wave, the better based on experience)
Remarks
Very interesing stuff, but rare of people trade with such crazy method. I suggest this is ONLY for backtest study of market behavior.
Readme
In real life, I am a prolific inventor. I have successfully applied for more than 60 international and regional patents in the past 12 years. But in the past two years or so, I have tried to transfer my creativity to the development of trading strategies. Tradingview is the ideal platform for me. I am selecting and contributing some of the hundreds of scripts to publish in Tradingview community. Welcome everyone to interact with me to discuss these interesting pine scripts.
The scripts posted are categorized into 5 levels according to my efforts or manhours put into these works.
Level 1 : interesting script snippets or distinctive improvement from classic indicators or strategy. Level 1 scripts can usually appear in more complex indicators as a function module or element.
Level 2 : composite indicator/strategy. By selecting or combining several independent or dependent functions or sub indicators in proper way, the composite script exhibits a resonance phenomenon which can filter out noise or fake trading signal to enhance trading confidence level.
Level 3 : comprehensive indicator/strategy. They are simple trading systems based on my strategies. They are commonly containing several or all of entry signal, close signal, stop loss, take profit, re-entry, risk management, and position sizing techniques. Even some interesting fundamental and mass psychological aspects are incorporated.
Level 4 : script snippets or functions that do not disclose source code. Interesting element that can reveal market laws and work as raw material for indicators and strategies. If you find Level 1~2 scripts are helpful, Level 4 is a private version that took me far more efforts to develop.
Level 5 : indicator/strategy that do not disclose source code. private version of Level 3 script with my accumulated script processing skills or a large number of custom functions. I had a private function library built in past two years. Level 5 scripts use many of them to achieve private trading strategy.
Relative CandleThis script visualizes the relative movement of a single OHLC candle compared to an index (or another symbol). The vertical location of the candle indicates the general positive/negative comparison of the bar vs the index. The color of the candle indicates how the candle moved relative to the index. The wick indicates the closing range compared to the index (did the symbol close at lows of the bar while the index closed at highs).
The area graph in the background shows the average relative close over a 10-day simple moving average.
I use this to pop any behavior that is out of line with the market, whether positive or negative. For example, is a red bar day due to the market pullback or something specific to the stock. Or did the market pull back and the stock did the opposite, strong day!
Structures OHLCThis will mark the:
Previous month OHLC
Last week OHLC
Current week open
Yesterday OHLC
2 days ago OHLC
Yearly OHLplots Yearly Open, High, Low levels
Interesting interactions to note at previous yearly opens
PivotBoss Pivots & Camarilla - H,D,W, M timeframe & OHLC LabelsThis is the new pivotboss pivots calculations and also has Camarilla Pivots . User can define which time frame pivots they want to see starting from Hourly, Daily, weekly and monthly. Added labels for each levels. So that user can calculate potential profit targets. This script also includes Hourly and Daily OHLC with labels. Added Developing mid point of the current day. The script can calculate midpoint as and when new highs and lows are made through out the day
Abbrevations used in this script
yHI - Yesterday's session High
dOP - Days open
yCL - yesterday's session Close
yLO - yesterday's session Low
MP -- Developing midpoint of the day
TC - Top channel
P - Pivot Point
BC - Bottom Channel
R1 - R4 -- Resistance levels
S1 - S4 -- Support Levels